lib_rtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /**
  2. ******************************************************************************
  3. * @file lib_rtc.c
  4. * @author Application Team
  5. * @version V4.5.0
  6. * @date 2019-05-14
  7. * @brief RTC library.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. ******************************************************************************
  12. */
  13. #include "lib_rtc.h"
  14. #define RTCPWD_KEY 0x5AA55AA5
  15. #define RTCCE_SETKEY 0xA55AA55B
  16. #define RTCCE_CLRKEY 0xA55AA55A
  17. /**
  18. * @brief RTC registers write protection control.
  19. * @param NewState:
  20. * ENABLE
  21. * DISABLE
  22. * @retval None
  23. */
  24. void RTC_WriteProtection(uint32_t NewState)
  25. {
  26. /* Check parameters */
  27. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  28. /* Enable RTC Write-Protection */
  29. if (NewState != DISABLE)
  30. {
  31. RTC->PWD = RTCPWD_KEY;
  32. RTC->CE = RTCCE_CLRKEY;
  33. }
  34. /* Disable RTC Write-Protection */
  35. else
  36. {
  37. RTC->PWD = RTCPWD_KEY;
  38. RTC->CE = RTCCE_SETKEY;
  39. }
  40. }
  41. /**
  42. * @brief Wait until the RTC registers (be W/R protected) are synchronized
  43. * with RTC APB clock.
  44. *
  45. * @note The RTC Resynchronization mode is write protected, use the
  46. * RTC_WriteProtection(DISABLE) before calling this function.
  47. * Write-Operation process as follows:
  48. * 1. RTC_WriteProtection(DISABLE);
  49. * 2. RTC Registers write operation(only first write-operation be
  50. * valid on the same register).
  51. * 3. RTC_WriteProtection(ENABLE);
  52. * 4. RTC_WaitForSynchro(); Wait until the RTC registers be
  53. * synchronized by calling this function.
  54. * @retval None
  55. */
  56. void RTC_WaitForSynchro(void)
  57. {
  58. while (RTC->CE & RTC_CE_BSY)
  59. {
  60. }
  61. }
  62. /**
  63. * @brief Write RTC registers(continuous/be write-protected).
  64. * @param[in] StartAddr the start address of registers be written
  65. * @param[in] wBuffer pointer to write
  66. * @param[in] Len number of registers be written
  67. * @retval None
  68. */
  69. void RTC_WriteRegisters(uint32_t StartAddr, const uint32_t *wBuffer, uint8_t Len)
  70. {
  71. uint8_t cnt;
  72. /* Parameter check */
  73. assert_parameters(IS_RTC_REGOP_STARTADDR(StartAddr));
  74. /* Wait until the RTC registers be synchronized */
  75. RTC_WaitForSynchro();
  76. /* Disable RTC Registers write-protection */
  77. RTC_WriteProtection(DISABLE);
  78. /* Write registers */
  79. for (cnt=0; cnt<Len; cnt++)
  80. {
  81. *(volatile uint32_t *)(StartAddr) = *(wBuffer++);
  82. StartAddr += 4;
  83. }
  84. /* Enable RTC Registers write-protection */
  85. RTC_WriteProtection(ENABLE);
  86. /* Wait until the RTC registers be synchronized */
  87. RTC_WaitForSynchro();
  88. }
  89. /**
  90. * @brief Read RTC registers(continuous/be read-protected).
  91. * @param[in] StartAddr the start address of registers be read
  92. * @param[out] rBuffer pointer to read
  93. * @param[in] Len number of registers be read
  94. * @retval None
  95. */
  96. void RTC_ReadRegisters(uint32_t StartAddr, uint32_t *rBuffer, uint8_t Len)
  97. {
  98. __IO uint32_t tmp;
  99. uint8_t cnt;
  100. /* Parameter check */
  101. assert_parameters(IS_RTC_REGOP_STARTADDR(StartAddr));
  102. /* Wait until the RTC registers be synchronized */
  103. RTC_WaitForSynchro();
  104. /* Dummy read-operation to RTC->LOAD */
  105. tmp = RTC->LOAD;
  106. tmp += 1;
  107. /* Wait until the RTC registers be synchronized */
  108. RTC_WaitForSynchro();
  109. /* Read registers */
  110. for (cnt=0; cnt<Len; cnt++)
  111. {
  112. *(rBuffer++) = *(volatile uint32_t *)(StartAddr);
  113. StartAddr += 4;
  114. }
  115. }
  116. /**
  117. * @brief Set RTC current time.
  118. * @param sTime: Pointer to Time structure
  119. * @retval None
  120. */
  121. void RTC_SetTime(RTC_TimeTypeDef *sTime)
  122. {
  123. /* Parameter check */
  124. assert_parameters(IS_RTC_TIME_YEAR(sTime->Year));
  125. assert_parameters(IS_RTC_TIME_MONTH(sTime->Month));
  126. assert_parameters(IS_RTC_TIME_DATE(sTime->Date));
  127. assert_parameters(IS_RTC_TIME_WEEKDAY(sTime->WeekDay));
  128. assert_parameters(IS_RTC_TIME_HOURS(sTime->Hours));
  129. assert_parameters(IS_RTC_TIME_MINS(sTime->Minutes));
  130. assert_parameters(IS_RTC_TIME_SECS(sTime->Seconds));
  131. /* Wait until the RTC registers be synchronized */
  132. RTC_WaitForSynchro();
  133. /* Disable RTC Registers write-protection */
  134. RTC_WriteProtection(DISABLE);
  135. /* Write RTC time registers */
  136. RTC->SEC = sTime->Seconds;
  137. RTC->MIN = sTime->Minutes;
  138. RTC->HOUR = sTime->Hours;
  139. RTC->DAY = sTime->Date;
  140. RTC->WEEK = sTime->WeekDay;
  141. RTC->MON = sTime->Month;
  142. RTC->YEAR = sTime->Year;
  143. /* Enable RTC Registers write-protection */
  144. RTC_WriteProtection(ENABLE);
  145. /* Wait until the RTC registers be synchronized */
  146. RTC_WaitForSynchro();
  147. }
  148. /**
  149. * @brief Get RTC current time.
  150. * @param gTime: Pointer to Time structure
  151. * @retval None
  152. */
  153. void RTC_GetTime(RTC_TimeTypeDef *gTime)
  154. {
  155. __IO uint32_t dummy_data = 0;
  156. /* Wait until the RTC registers be synchronized */
  157. RTC_WaitForSynchro();
  158. /* Dummy read-operation to RTC->LOAD register */
  159. dummy_data = RTC->LOAD;
  160. dummy_data += 1;
  161. /* Wait until the RTC registers be synchronized */
  162. RTC_WaitForSynchro();
  163. /* Read RTC time registers */
  164. gTime->Seconds = RTC->SEC;
  165. gTime->Minutes = RTC->MIN;
  166. gTime->Hours = RTC->HOUR;
  167. gTime->Date = RTC->DAY;
  168. gTime->WeekDay = RTC->WEEK;
  169. gTime->Month = RTC->MON;
  170. gTime->Year = RTC->YEAR;
  171. }
  172. /**
  173. * @brief Interrupt configure.
  174. * @param INTMask: can use the ¡®|¡¯ operator
  175. RTC_INT_CEILLE
  176. RTC_INT_ACDONE
  177. RTC_INT_WKUCNT
  178. RTC_INT_MIDNIGHT
  179. RTC_INT_WKUHOUR
  180. RTC_INT_WKUMIN
  181. RTC_INT_WKUSEC
  182. RTC_INT_TIMEILLE
  183. NewState:
  184. ENABLE
  185. DISABLE
  186. * @retval None
  187. */
  188. void RTC_INTConfig(uint32_t INTMask, uint32_t NewState)
  189. {
  190. uint32_t tmp;
  191. /* Parameter check */
  192. assert_parameters(IS_RTC_INT(INTMask));
  193. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  194. tmp = RTC->INTEN;
  195. tmp &= ~(0x1UL);
  196. if (NewState == ENABLE)
  197. tmp |= INTMask;
  198. else
  199. tmp &= ~INTMask;
  200. RTC->INTEN = tmp;
  201. }
  202. /**
  203. * @brief Get interrupt status.
  204. * @param INTMask:
  205. RTC_INTSTS_CEILLE
  206. RTC_INTSTS_ACDONE
  207. RTC_INTSTS_WKUCNT
  208. RTC_INTSTS_MIDNIGHT
  209. RTC_INTSTS_WKUHOUR
  210. RTC_INTSTS_WKUMIN
  211. RTC_INTSTS_WKUSEC
  212. RTC_INTSTS_TIMEILLE
  213. * @retval 1: status set
  214. 0: status reset.
  215. */
  216. uint8_t RTC_GetINTStatus(uint32_t FlagMask)
  217. {
  218. /* Parameter check */
  219. assert_parameters(IS_RTC_INTFLAGR(FlagMask));
  220. if (RTC->INTSTS&FlagMask)
  221. {
  222. return 1;
  223. }
  224. else
  225. {
  226. return 0;
  227. }
  228. }
  229. /**
  230. * @brief Clear interrupt status.
  231. * @param INTMask: can use the ¡®|¡¯ operator
  232. RTC_INTSTS_CEILLE
  233. RTC_INTSTS_ACDONE
  234. RTC_INTSTS_WKUCNT
  235. RTC_INTSTS_MIDNIGHT
  236. RTC_INTSTS_WKUHOUR
  237. RTC_INTSTS_WKUMIN
  238. RTC_INTSTS_WKUSEC
  239. RTC_INTSTS_TIMEILLE
  240. * @retval None
  241. */
  242. void RTC_ClearINTStatus(uint32_t FlagMask)
  243. {
  244. /* Parameter check */
  245. assert_parameters(IS_RTC_INTFLAGC(FlagMask));
  246. RTC->INTSTS = FlagMask;
  247. }
  248. /**
  249. * @brief Fills each RTCAC_InitStruct member with its default value.
  250. * @param RTCAC_InitStruct: pointer to an RTC_AutCalType structure which will be initialized.
  251. * @retval None
  252. */
  253. void RTC_AutoCalStructInit(RTC_AutCalType *RTCAC_InitStruct)
  254. {
  255. /*------------ Reset RTC AutCal init structure parameters values -----------*/
  256. /* Initialize the ADCSource member */
  257. RTCAC_InitStruct->ADCSource = RTC_ADCS_DATA;
  258. /* Initialize the ATClockSource member */
  259. RTCAC_InitStruct->ATClockSource = RTC_ATCS_DISABLE;
  260. /* Initialize the ATDelay member */
  261. RTCAC_InitStruct->ATDelay = RTC_ATDELAY_15MS;
  262. /* Initialize the Period member */
  263. RTCAC_InitStruct->Period = 0;
  264. }
  265. /**
  266. * @brief Auto calibration initialization.
  267. * @param InitStruct: pointer to AutoCal_InitType Auto calibration configuration.
  268. * ATDelay:
  269. * RTC_ATDELAY_15MS
  270. * RTC_ATDELAY_31MS
  271. * RTC_ATDELAY_62MS
  272. * RTC_ATDELAY_125MS
  273. * ATClockSource:
  274. * RTC_ATCS_DISABLE
  275. * RTC_ATCS_SEC
  276. * RTC_ATCS_MIN
  277. * RTC_ATCS_HOUR
  278. * ADCSource:
  279. * RTC_ADCS_DATA
  280. * RTC_ADCS_PORT
  281. * Period: 0 ~ 63
  282. * @note Auto trigger period is (Period+1)*1, unit is set by ATClockSource.
  283. * Auto trigger function is not valid when ATClockSource is RTC_ATCS_DISABLE.
  284. * @retval None
  285. */
  286. void RTC_AutoCalInit(RTC_AutCalType *InitStruct)
  287. {
  288. uint32_t tmp;
  289. /* Parameter check */
  290. assert_parameters(IS_RTC_AUTOCAL_ATDLY(InitStruct->ATDelay));
  291. assert_parameters(IS_RTC_AUTOCAL_ATCS(InitStruct->ATClockSource));
  292. assert_parameters(IS_RTC_AUTOCAL_ADCSRC(InitStruct->ADCSource));
  293. assert_parameters(IS_RTC_AUTOCAL_PERIOD(InitStruct->Period));
  294. tmp = RTC->ACCTRL;
  295. tmp &= ~(RTC_ACCTRL_ACPER\
  296. |RTC_ACCTRL_ACDEL\
  297. |RTC_ACCTRL_ACCLK\
  298. |RTC_ACCTRL_ADCSEL);
  299. tmp |= (InitStruct->ADCSource\
  300. |InitStruct->ATClockSource\
  301. |InitStruct->ATDelay\
  302. |((InitStruct->Period << RTC_ACCTRL_ACPER_Pos) & RTC_ACCTRL_ACPER));
  303. /* Wait until the RTC registers be synchronized */
  304. RTC_WaitForSynchro();
  305. /* Disable RTC Registers write-protection */
  306. RTC_WriteProtection(DISABLE);
  307. RTC->ACCTRL = tmp;
  308. /* Enable RTC Registers write-protection */
  309. RTC_WriteProtection(ENABLE);
  310. /* Wait until the RTC registers be synchronized */
  311. RTC_WaitForSynchro();
  312. }
  313. /**
  314. * @brief RTC automatic calibration auto-trigger source configure.
  315. * @param TrigSource:
  316. * RTC_ATCS_DISABLE
  317. * RTC_ATCS_SEC
  318. * RTC_ATCS_MIN
  319. * RTC_ATCS_HOUR
  320. * Period: 0 ~ 63
  321. * @retval None
  322. */
  323. void RTC_TrigSourceConfig(uint32_t TrigSource, uint32_t Period)
  324. {
  325. uint32_t tmp;
  326. /* Parameter check */
  327. assert_parameters(IS_RTC_AUTOCAL_ATCS(TrigSource));
  328. assert_parameters(IS_RTC_AUTOCAL_PERIOD(Period));
  329. tmp = RTC->ACCTRL;
  330. tmp &= ~(RTC_ACCTRL_ACPER | RTC_ACCTRL_ACCLK);
  331. tmp |= (TrigSource | (Period << RTC_ACCTRL_ACPER_Pos));
  332. /* Wait until the RTC registers be synchronized */
  333. RTC_WaitForSynchro();
  334. /* Disable RTC Registers write-protection */
  335. RTC_WriteProtection(DISABLE);
  336. RTC->ACCTRL = tmp;
  337. /* Enable RTC Registers write-protection */
  338. RTC_WriteProtection(ENABLE);
  339. /* Wait until the RTC registers be synchronized */
  340. RTC_WaitForSynchro();
  341. }
  342. /**
  343. * @brief ADC Auto-calibration enable control.
  344. * @note When DISABLE is selected, the automatic triggering of the RTC-auto-calibration must be turned off by calling
  345. * RTC_TrigSourceConfig(RTC_ATCS_DISABLE, 0) before using this function.
  346. * @param NewState:
  347. * ENABLE
  348. * DISABLE
  349. * @retval 0: Function succeeded
  350. * 1: Function failded, the automatic triggering be enabled when DISABLE selected
  351. */
  352. uint32_t RTC_AutoCalCmd(uint32_t NewState)
  353. {
  354. uint32_t tmp;
  355. /* Parameter check */
  356. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  357. tmp = RTC->ACCTRL;
  358. if (NewState == DISABLE)
  359. {
  360. if (tmp & RTC_ACCTRL_ACCLK)
  361. return 1;
  362. else
  363. tmp &= ~RTC_ACCTRL_ACEN;
  364. }
  365. else
  366. {
  367. tmp |= RTC_ACCTRL_ACEN;
  368. }
  369. /* Wait until the RTC registers be synchronized */
  370. RTC_WaitForSynchro();
  371. /* Disable RTC Registers write-protection */
  372. RTC_WriteProtection(DISABLE);
  373. RTC->ACCTRL = tmp;
  374. /* Enable RTC Registers write-protection */
  375. RTC_WriteProtection(ENABLE);
  376. /* Wait until the RTC registers be synchronized */
  377. RTC_WaitForSynchro();
  378. return 0;
  379. }
  380. /**
  381. * @brief Start RTC Auto-calibration manually.
  382. * @param None
  383. * @retval None
  384. */
  385. void RTC_StartAutoCalManual(void)
  386. {
  387. /* Wait until the RTC registers be synchronized */
  388. RTC_WaitForSynchro();
  389. /* Disable RTC Registers write-protection */
  390. RTC_WriteProtection(DISABLE);
  391. /* manual trigger Auto-calibration */
  392. RTC->ACCTRL |= RTC_ACCTRL_MANU;
  393. /* Enable RTC Registers write-protection */
  394. RTC_WriteProtection(ENABLE);
  395. /* Wait until the RTC registers be synchronized */
  396. RTC_WaitForSynchro();
  397. }
  398. /**
  399. * @brief Wait until Auto-calibration manual is done.
  400. * @param None
  401. * @retval None
  402. */
  403. void RTC_WaitForAutoCalManual(void)
  404. {
  405. while (RTC->ACCTRL&RTC_ACCTRL_MANU)
  406. {
  407. }
  408. }
  409. /**
  410. * @brief Get auto-calibration busy flag.
  411. * @param None
  412. * @retval 1 flag set
  413. * 0 flag reset.
  414. */
  415. uint8_t RTC_GetACBusyFlag(void)
  416. {
  417. if (RTC->INTSTS & RTC_INTSTS_ACBSY) return (1);
  418. else return (0);
  419. }
  420. /*
  421. * @brief Multi-second wake up configure.
  422. * @param nPeriod£ºN seconds interval.
  423. * @note For the first interrupt generated by calling this function, it may
  424. * have < 1 sec error if the new WKUSEC number(parameter) is not equal
  425. * to current WKUSEC number. If the new WKUSEC is equal to current WKUSEC,
  426. * the first interrupt time may have 0~(WKUSEC +1) variation.
  427. * To avoid this problem, set an alternative parameter (like 1) by calling
  428. * this function, then set the correct parameter to it.
  429. * @retval None
  430. */
  431. void RTC_WKUSecondsConfig(uint8_t nPeriod)
  432. {
  433. /* Parameter check */
  434. assert_parameters(IS_RTC_WKUSEC_PERIOD(nPeriod));
  435. /* Wait until the RTC registers be synchronized */
  436. RTC_WaitForSynchro();
  437. /* Disable RTC Registers write-protection */
  438. RTC_WriteProtection(DISABLE);
  439. /* Write registers */
  440. RTC->WKUSEC = nPeriod - 1;
  441. /* Enable RTC Registers write-protection */
  442. RTC_WriteProtection(ENABLE);
  443. /* Wait until the RTC registers be synchronized */
  444. RTC_WaitForSynchro();
  445. }
  446. /*
  447. * @brief Multi-minute wake up configure.
  448. * @param nPeriod£ºN minute interval.
  449. * @note For the first interrupt generated by calling this function, it may
  450. * have < 1 min error if the new WKUMIN number(parameter) is not equal
  451. * to current WKUMIN number. If the new WKUMIN is equal to current WKUMIN,
  452. * the first interrupt time may have 0~(WKUMIN +1) variation.
  453. * To avoid this problem, set an alternative parameter (like 1) by calling
  454. * this function, then set the correct parameter to it.
  455. * @retval None
  456. */
  457. void RTC_WKUMinutesConfig(uint8_t nPeriod)
  458. {
  459. /* Parameter check */
  460. assert_parameters(IS_RTC_WKUMIN_PERIOD(nPeriod));
  461. /* Wait until the RTC registers be synchronized */
  462. RTC_WaitForSynchro();
  463. /* Disable RTC Registers write-protection */
  464. RTC_WriteProtection(DISABLE);
  465. /* Write registers */
  466. RTC->WKUMIN = nPeriod - 1;
  467. /* Enable RTC Registers write-protection */
  468. RTC_WriteProtection(ENABLE);
  469. /* Wait until the RTC registers be synchronized */
  470. RTC_WaitForSynchro();
  471. }
  472. /*
  473. * @brief Multi-hour wake up configure.
  474. * @param nPeriod£ºN hour interval.
  475. * @note For the first interrupt generated by calling this function, it may
  476. * have < 1 hour error if the new WKUHOUR number(parameter) is not equal
  477. * to current WKUHOUR number. If the new WKUHOUR is equal to current WKUHOUR,
  478. * the first interrupt time may have 0~(WKUHOUR +1) variation.
  479. * To avoid this problem, set an alternative parameter (like 1) by calling
  480. * this function, then set the correct parameter to it.
  481. * @retval None
  482. */
  483. void RTC_WKUHoursConfig(uint8_t nPeriod)
  484. {
  485. /* Parameter check */
  486. assert_parameters(IS_RTC_WKUHOUR_PERIOD(nPeriod));
  487. /* Wait until the RTC registers be synchronized */
  488. RTC_WaitForSynchro();
  489. /* Disable RTC Registers write-protection */
  490. RTC_WriteProtection(DISABLE);
  491. /* Write registers */
  492. RTC->WKUHOUR = nPeriod - 1;
  493. /* Enable RTC Registers write-protection */
  494. RTC_WriteProtection(ENABLE);
  495. /* Wait until the RTC registers be synchronized */
  496. RTC_WaitForSynchro();
  497. }
  498. /**
  499. * @brief RTC counter wake up configure.
  500. * @param nClock: 1 ~ 0x1000000
  501. CNTCLK:
  502. RTC_WKUCNT_RTCCLK
  503. RTC_WKUCNT_2048
  504. RTC_WKUCNT_512
  505. RTC_WKUCNT_128
  506. * @retval None
  507. */
  508. void RTC_WKUCounterConfig(uint32_t nClock,uint32_t CNTCLK)
  509. {
  510. /* Parameter check */
  511. assert_parameters(IS_RTC_WKUCNT_PERIOD(nClock));
  512. assert_parameters(IS_RTC_WKUCNT_CNTSEL(CNTCLK));
  513. /* Wait until the RTC registers be synchronized */
  514. RTC_WaitForSynchro();
  515. /* Disable RTC Registers write-protection */
  516. RTC_WriteProtection(DISABLE);
  517. /* Write registers */
  518. RTC->WKUCNT = (CNTCLK & RTC_WKUCNT_CNTSEL) | (nClock -1 );
  519. /* Enable RTC Registers write-protection */
  520. RTC_WriteProtection(ENABLE);
  521. /* Wait until the RTC registers be synchronized */
  522. RTC_WaitForSynchro();
  523. }
  524. /**
  525. * @brief Gets RTC wake-up counter value.
  526. * @retval RTC wake-up counter value
  527. */
  528. uint32_t RTC_GetWKUCounterValue(void)
  529. {
  530. return RTC->WKUCNTR;
  531. }
  532. /**
  533. * @brief RTC clock prescaler configure.
  534. * @param[in] Prescaler:
  535. * RTC_CLKDIV_1
  536. * RTC_CLKDIV_4
  537. * @retval None
  538. */
  539. void RTC_PrescalerConfig(uint32_t Prescaler)
  540. {
  541. uint32_t tmp;
  542. /* Parameter check */
  543. assert_parameters(IS_RTC_CLKDIV(Prescaler));
  544. tmp = RTC->PSCA;
  545. tmp &= ~RTC_PSCA_PSCA;
  546. tmp |= Prescaler;
  547. /* Wait until the RTC registers be synchronized */
  548. RTC_WaitForSynchro();
  549. /* Disable RTC Registers write-protection */
  550. RTC_WriteProtection(DISABLE);
  551. RTC->PSCA = tmp;
  552. /* Enable RTC Registers write-protection */
  553. RTC_WriteProtection(ENABLE);
  554. /* Wait until the RTC registers be synchronized */
  555. RTC_WaitForSynchro();
  556. }
  557. /**
  558. * @brief RTC PLLDIV frequency configure.
  559. * @param nfrequency(HZ): the frequency of RTC PLLDIV output configuration.
  560. * @note Ensure clocks be configured by calling function CLK_ClockConfig(),
  561. * get correct PCLK frequency by calling function CLK_GetPCLKFreq().
  562. * @retval None
  563. */
  564. void RTC_PLLDIVConfig(uint32_t nfrequency)
  565. {
  566. RTC->DIV = CLK_GetPCLKFreq()/2/nfrequency - 1;
  567. }
  568. /**
  569. * @brief RTC PLLDIV output enable.
  570. * @param NewState:
  571. * ENABLE
  572. * DISABLE
  573. * @retval None
  574. */
  575. void RTC_PLLDIVOutputCmd(uint8_t NewState)
  576. {
  577. /* Parameter check */
  578. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  579. if (NewState == ENABLE) RTC->CTL |= RTC_CTL_RTCPLLOE;
  580. else RTC->CTL &= ~RTC_CTL_RTCPLLOE;
  581. }
  582. /*********************************** END OF FILE ******************************/