Projet voilier 4IRA1 Arnaud Vergnet Marino Benassai Bastien Picco Yohan Simard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32f1xx_ll_rtc.h 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F1xx_LL_RTC_H
  21. #define __STM32F1xx_LL_RTC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx.h"
  27. /** @addtogroup STM32F1xx_LL_Driver
  28. * @{
  29. */
  30. #if defined(RTC)
  31. /** @defgroup RTC_LL RTC
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. #if defined(USE_FULL_LL_DRIVER)
  39. /** @defgroup RTC_LL_Private_Macros RTC Private Macros
  40. * @{
  41. */
  42. /**
  43. * @}
  44. */
  45. #endif /*USE_FULL_LL_DRIVER*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup RTC_LL_ES_INIT RTC Exported Init structure
  49. * @{
  50. */
  51. /**
  52. * @brief RTC Init structures definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t AsynchPrescaler; /*!< Specifies the RTC Asynchronous Predivider value.
  57. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFFF
  58. This feature can be modified afterwards using unitary function
  59. @ref LL_RTC_SetAsynchPrescaler(). */
  60. uint32_t OutPutSource; /*!< Specifies which signal will be routed to the RTC Tamper pin.
  61. This parameter can be a value of @ref LL_RTC_Output_Source
  62. This feature can be modified afterwards using unitary function
  63. @ref LL_RTC_SetOutputSource(). */
  64. } LL_RTC_InitTypeDef;
  65. /**
  66. * @brief RTC Time structure definition
  67. */
  68. typedef struct
  69. {
  70. uint8_t Hours; /*!< Specifies the RTC Time Hours.
  71. This parameter must be a number between Min_Data = 0 and Max_Data = 23 */
  72. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  73. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  74. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  75. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  76. } LL_RTC_TimeTypeDef;
  77. /**
  78. * @brief RTC Alarm structure definition
  79. */
  80. typedef struct
  81. {
  82. LL_RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members. */
  83. } LL_RTC_AlarmTypeDef;
  84. /**
  85. * @}
  86. */
  87. #endif /* USE_FULL_LL_DRIVER */
  88. /* Exported constants --------------------------------------------------------*/
  89. /** @defgroup RTC_LL_Exported_Constants RTC Exported Constants
  90. * @{
  91. */
  92. #if defined(USE_FULL_LL_DRIVER)
  93. /** @defgroup RTC_LL_EC_FORMAT FORMAT
  94. * @{
  95. */
  96. #define LL_RTC_FORMAT_BIN (0x000000000U) /*!< Binary data format */
  97. #define LL_RTC_FORMAT_BCD (0x000000001U) /*!< BCD data format */
  98. /**
  99. * @}
  100. */
  101. #endif /* USE_FULL_LL_DRIVER */
  102. /** @defgroup RTC_LL_EC_BKP BACKUP
  103. * @{
  104. */
  105. #if RTC_BKP_NUMBER > 0
  106. #define LL_RTC_BKP_DR1 (0x00000001U)
  107. #define LL_RTC_BKP_DR2 (0x00000002U)
  108. #define LL_RTC_BKP_DR3 (0x00000003U)
  109. #define LL_RTC_BKP_DR4 (0x00000004U)
  110. #define LL_RTC_BKP_DR5 (0x00000005U)
  111. #define LL_RTC_BKP_DR6 (0x00000006U)
  112. #define LL_RTC_BKP_DR7 (0x00000007U)
  113. #define LL_RTC_BKP_DR8 (0x00000008U)
  114. #define LL_RTC_BKP_DR9 (0x00000009U)
  115. #define LL_RTC_BKP_DR10 (0x0000000AU)
  116. #endif /* RTC_BKP_NUMBER > 0 */
  117. #if RTC_BKP_NUMBER > 10
  118. #define LL_RTC_BKP_DR11 (0x0000000BU)
  119. #define LL_RTC_BKP_DR12 (0x0000000CU)
  120. #define LL_RTC_BKP_DR13 (0x0000000DU)
  121. #define LL_RTC_BKP_DR14 (0x0000000EU)
  122. #define LL_RTC_BKP_DR15 (0x0000000FU)
  123. #define LL_RTC_BKP_DR16 (0x00000010U)
  124. #define LL_RTC_BKP_DR17 (0x00000011U)
  125. #define LL_RTC_BKP_DR18 (0x00000012U)
  126. #define LL_RTC_BKP_DR19 (0x00000013U)
  127. #define LL_RTC_BKP_DR20 (0x00000014U)
  128. #define LL_RTC_BKP_DR21 (0x00000015U)
  129. #define LL_RTC_BKP_DR22 (0x00000016U)
  130. #define LL_RTC_BKP_DR23 (0x00000017U)
  131. #define LL_RTC_BKP_DR24 (0x00000018U)
  132. #define LL_RTC_BKP_DR25 (0x00000019U)
  133. #define LL_RTC_BKP_DR26 (0x0000001AU)
  134. #define LL_RTC_BKP_DR27 (0x0000001BU)
  135. #define LL_RTC_BKP_DR28 (0x0000001CU)
  136. #define LL_RTC_BKP_DR29 (0x0000001DU)
  137. #define LL_RTC_BKP_DR30 (0x0000001EU)
  138. #define LL_RTC_BKP_DR31 (0x0000001FU)
  139. #define LL_RTC_BKP_DR32 (0x00000020U)
  140. #define LL_RTC_BKP_DR33 (0x00000021U)
  141. #define LL_RTC_BKP_DR34 (0x00000022U)
  142. #define LL_RTC_BKP_DR35 (0x00000023U)
  143. #define LL_RTC_BKP_DR36 (0x00000024U)
  144. #define LL_RTC_BKP_DR37 (0x00000025U)
  145. #define LL_RTC_BKP_DR38 (0x00000026U)
  146. #define LL_RTC_BKP_DR39 (0x00000027U)
  147. #define LL_RTC_BKP_DR40 (0x00000028U)
  148. #define LL_RTC_BKP_DR41 (0x00000029U)
  149. #define LL_RTC_BKP_DR42 (0x0000002AU)
  150. #endif /* RTC_BKP_NUMBER > 10 */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup RTC_LL_EC_TAMPLEVEL Tamper Active Level
  155. * @{
  156. */
  157. #define LL_RTC_TAMPER_ACTIVELEVEL_LOW BKP_CR_TPAL /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
  158. #define LL_RTC_TAMPER_ACTIVELEVEL_HIGH (0x00000000U) /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
  159. /**
  160. * @}
  161. */
  162. /** @defgroup LL_RTC_Output_Source Clock Source to output on the Tamper Pin
  163. * @{
  164. */
  165. #define LL_RTC_CALIB_OUTPUT_NONE (0x00000000U) /*!< Calibration output disabled */
  166. #define LL_RTC_CALIB_OUTPUT_RTCCLOCK BKP_RTCCR_CCO /*!< Calibration output is RTC Clock with a frequency divided by 64 on the TAMPER Pin */
  167. #define LL_RTC_CALIB_OUTPUT_ALARM BKP_RTCCR_ASOE /*!< Calibration output is Alarm pulse signal on the TAMPER pin */
  168. #define LL_RTC_CALIB_OUTPUT_SECOND (BKP_RTCCR_ASOS | BKP_RTCCR_ASOE) /*!< Calibration output is Second pulse signal on the TAMPER pin*/
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */
  175. /* Exported macro ------------------------------------------------------------*/
  176. /** @defgroup RTC_LL_Exported_Macros RTC Exported Macros
  177. * @{
  178. */
  179. /** @defgroup RTC_LL_EM_WRITE_READ Common Write and read registers Macros
  180. * @{
  181. */
  182. /**
  183. * @brief Write a value in RTC register
  184. * @param __INSTANCE__ RTC Instance
  185. * @param __REG__ Register to be written
  186. * @param __VALUE__ Value to be written in the register
  187. * @retval None
  188. */
  189. #define LL_RTC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  190. /**
  191. * @brief Read a value in RTC register
  192. * @param __INSTANCE__ RTC Instance
  193. * @param __REG__ Register to be read
  194. * @retval Register value
  195. */
  196. #define LL_RTC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  197. /**
  198. * @}
  199. */
  200. /** @defgroup RTC_LL_EM_Convert Convert helper Macros
  201. * @{
  202. */
  203. /**
  204. * @brief Helper macro to convert a value from 2 digit decimal format to BCD format
  205. * @param __VALUE__ Byte to be converted
  206. * @retval Converted byte
  207. */
  208. #define __LL_RTC_CONVERT_BIN2BCD(__VALUE__) (uint8_t)((((__VALUE__) / 10U) << 4U) | ((__VALUE__) % 10U))
  209. /**
  210. * @brief Helper macro to convert a value from BCD format to 2 digit decimal format
  211. * @param __VALUE__ BCD value to be converted
  212. * @retval Converted byte
  213. */
  214. #define __LL_RTC_CONVERT_BCD2BIN(__VALUE__) (uint8_t)(((uint8_t)((__VALUE__) & (uint8_t)0xF0U) >> (uint8_t)0x4U) * 10U + ((__VALUE__) & (uint8_t)0x0FU))
  215. /**
  216. * @}
  217. */
  218. /**
  219. * @}
  220. */
  221. /* Exported functions --------------------------------------------------------*/
  222. /** @defgroup RTC_LL_Exported_Functions RTC Exported Functions
  223. * @{
  224. */
  225. /** @defgroup RTC_LL_EF_Configuration Configuration
  226. * @{
  227. */
  228. /**
  229. * @brief Set Asynchronous prescaler factor
  230. * @rmtoll PRLH PRL LL_RTC_SetAsynchPrescaler\n
  231. * @rmtoll PRLL PRL LL_RTC_SetAsynchPrescaler\n
  232. * @param RTCx RTC Instance
  233. * @param AsynchPrescaler Value between Min_Data = 0 and Max_Data = 0xFFFFF
  234. * @retval None
  235. */
  236. __STATIC_INLINE void LL_RTC_SetAsynchPrescaler(RTC_TypeDef *RTCx, uint32_t AsynchPrescaler)
  237. {
  238. MODIFY_REG(RTCx->PRLH, RTC_PRLH_PRL, (AsynchPrescaler >> 16));
  239. MODIFY_REG(RTCx->PRLL, RTC_PRLL_PRL, (AsynchPrescaler & RTC_PRLL_PRL));
  240. }
  241. /**
  242. * @brief Get Asynchronous prescaler factor
  243. * @rmtoll DIVH DIV LL_RTC_GetDivider\n
  244. * @rmtoll DIVL DIV LL_RTC_GetDivider\n
  245. * @param RTCx RTC Instance
  246. * @retval Value between Min_Data = 0 and Max_Data = 0xFFFFF
  247. */
  248. __STATIC_INLINE uint32_t LL_RTC_GetDivider(RTC_TypeDef *RTCx)
  249. {
  250. register uint16_t Highprescaler = 0, Lowprescaler = 0;
  251. Highprescaler = READ_REG(RTCx->DIVH & RTC_DIVH_RTC_DIV);
  252. Lowprescaler = READ_REG(RTCx->DIVL & RTC_DIVL_RTC_DIV);
  253. return (((uint32_t) Highprescaler << 16U) | Lowprescaler);
  254. }
  255. /**
  256. * @brief Set Output Source
  257. * @rmtoll RTCCR CCO LL_RTC_SetOutputSource
  258. * @rmtoll RTCCR ASOE LL_RTC_SetOutputSource
  259. * @rmtoll RTCCR ASOS LL_RTC_SetOutputSource
  260. * @param BKPx BKP Instance
  261. * @param OutputSource This parameter can be one of the following values:
  262. * @arg @ref LL_RTC_CALIB_OUTPUT_NONE
  263. * @arg @ref LL_RTC_CALIB_OUTPUT_RTCCLOCK
  264. * @arg @ref LL_RTC_CALIB_OUTPUT_ALARM
  265. * @arg @ref LL_RTC_CALIB_OUTPUT_SECOND
  266. * @retval None
  267. */
  268. __STATIC_INLINE void LL_RTC_SetOutputSource(BKP_TypeDef *BKPx, uint32_t OutputSource)
  269. {
  270. MODIFY_REG(BKPx->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE | BKP_RTCCR_ASOS), OutputSource);
  271. }
  272. /**
  273. * @brief Get Output Source
  274. * @rmtoll RTCCR CCO LL_RTC_GetOutPutSource
  275. * @rmtoll RTCCR ASOE LL_RTC_GetOutPutSource
  276. * @rmtoll RTCCR ASOS LL_RTC_GetOutPutSource
  277. * @param BKPx BKP Instance
  278. * @retval Returned value can be one of the following values:
  279. * @arg @ref LL_RTC_CALIB_OUTPUT_NONE
  280. * @arg @ref LL_RTC_CALIB_OUTPUT_RTCCLOCK
  281. * @arg @ref LL_RTC_CALIB_OUTPUT_ALARM
  282. * @arg @ref LL_RTC_CALIB_OUTPUT_SECOND
  283. */
  284. __STATIC_INLINE uint32_t LL_RTC_GetOutPutSource(BKP_TypeDef *BKPx)
  285. {
  286. return (uint32_t)(READ_BIT(BKPx->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE | BKP_RTCCR_ASOS)));
  287. }
  288. /**
  289. * @brief Enable the write protection for RTC registers.
  290. * @rmtoll CRL CNF LL_RTC_EnableWriteProtection
  291. * @param RTCx RTC Instance
  292. * @retval None
  293. */
  294. __STATIC_INLINE void LL_RTC_EnableWriteProtection(RTC_TypeDef *RTCx)
  295. {
  296. CLEAR_BIT(RTCx->CRL, RTC_CRL_CNF);
  297. }
  298. /**
  299. * @brief Disable the write protection for RTC registers.
  300. * @rmtoll CRL RTC_CRL_CNF LL_RTC_DisableWriteProtection
  301. * @param RTCx RTC Instance
  302. * @retval None
  303. */
  304. __STATIC_INLINE void LL_RTC_DisableWriteProtection(RTC_TypeDef *RTCx)
  305. {
  306. SET_BIT(RTCx->CRL, RTC_CRL_CNF);
  307. }
  308. /**
  309. * @}
  310. */
  311. /** @defgroup RTC_LL_EF_Time Time
  312. * @{
  313. */
  314. /**
  315. * @brief Set time counter in BCD format
  316. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  317. * @note It can be written in initialization mode only (@ref LL_RTC_EnterInitMode function)
  318. * @rmtoll CNTH CNT LL_RTC_TIME_Set\n
  319. * CNTL CNT LL_RTC_TIME_Set\n
  320. * @param RTCx RTC Instance
  321. * @param TimeCounter Value between Min_Data=0x00 and Max_Data=0xFFFFF
  322. * @retval None
  323. */
  324. __STATIC_INLINE void LL_RTC_TIME_Set(RTC_TypeDef *RTCx, uint32_t TimeCounter)
  325. {
  326. /* Set RTC COUNTER MSB word */
  327. WRITE_REG(RTCx->CNTH, (TimeCounter >> 16U));
  328. /* Set RTC COUNTER LSB word */
  329. WRITE_REG(RTCx->CNTL, (TimeCounter & RTC_CNTL_RTC_CNT));
  330. }
  331. /**
  332. * @brief Get time counter in BCD format
  333. * @rmtoll CNTH CNT LL_RTC_TIME_Get\n
  334. * CNTL CNT LL_RTC_TIME_Get\n
  335. * @param RTCx RTC Instance
  336. * @retval Value between Min_Data = 0 and Max_Data = 0xFFFFF
  337. */
  338. __STATIC_INLINE uint32_t LL_RTC_TIME_Get(RTC_TypeDef *RTCx)
  339. {
  340. register uint16_t high = 0, low = 0;
  341. high = READ_REG(RTCx->CNTH & RTC_CNTH_RTC_CNT);
  342. low = READ_REG(RTCx->CNTL & RTC_CNTL_RTC_CNT);
  343. return ((uint32_t)(((uint32_t) high << 16U) | low));
  344. }
  345. /**
  346. * @}
  347. */
  348. /** @defgroup RTC_LL_EF_ALARM ALARM
  349. * @{
  350. */
  351. /**
  352. * @brief Set Alarm Counter
  353. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  354. * @rmtoll ALRH ALR LL_RTC_ALARM_Set\n
  355. * @rmtoll ALRL ALR LL_RTC_ALARM_Set\n
  356. * @param RTCx RTC Instance
  357. * @param AlarmCounter Value between Min_Data=0x00 and Max_Data=0xFFFFF
  358. * @retval None
  359. */
  360. __STATIC_INLINE void LL_RTC_ALARM_Set(RTC_TypeDef *RTCx, uint32_t AlarmCounter)
  361. {
  362. /* Set RTC COUNTER MSB word */
  363. WRITE_REG(RTCx->ALRH, (AlarmCounter >> 16));
  364. /* Set RTC COUNTER LSB word */
  365. WRITE_REG(RTCx->ALRL, (AlarmCounter & RTC_ALRL_RTC_ALR));
  366. }
  367. /**
  368. * @brief Get Alarm Counter
  369. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  370. * @rmtoll ALRH ALR LL_RTC_ALARM_Get\n
  371. * @rmtoll ALRL ALR LL_RTC_ALARM_Get\n
  372. * @param RTCx RTC Instance
  373. * @retval None
  374. */
  375. __STATIC_INLINE uint32_t LL_RTC_ALARM_Get(RTC_TypeDef *RTCx)
  376. {
  377. register uint16_t high = 0, low = 0;
  378. high = READ_REG(RTCx->ALRH & RTC_ALRH_RTC_ALR);
  379. low = READ_REG(RTCx->ALRL & RTC_ALRL_RTC_ALR);
  380. return (((uint32_t) high << 16U) | low);
  381. }
  382. /**
  383. * @}
  384. */
  385. /** @defgroup RTC_LL_EF_Tamper Tamper
  386. * @{
  387. */
  388. /**
  389. * @brief Enable RTC_TAMPx input detection
  390. * @rmtoll CR TPE LL_RTC_TAMPER_Enable\n
  391. * @retval None
  392. */
  393. __STATIC_INLINE void LL_RTC_TAMPER_Enable(BKP_TypeDef *BKPx)
  394. {
  395. SET_BIT(BKPx->CR, BKP_CR_TPE);
  396. }
  397. /**
  398. * @brief Disable RTC_TAMPx Tamper
  399. * @rmtoll CR TPE LL_RTC_TAMPER_Disable\n
  400. * @retval None
  401. */
  402. __STATIC_INLINE void LL_RTC_TAMPER_Disable(BKP_TypeDef *BKPx)
  403. {
  404. CLEAR_BIT(BKP->CR, BKP_CR_TPE);
  405. }
  406. /**
  407. * @brief Enable Active level for Tamper input
  408. * @rmtoll CR TPAL LL_RTC_TAMPER_SetActiveLevel\n
  409. * @param BKPx BKP Instance
  410. * @param Tamper This parameter can be a combination of the following values:
  411. * @arg @ref LL_RTC_TAMPER_ACTIVELEVEL_LOW
  412. * @arg @ref LL_RTC_TAMPER_ACTIVELEVEL_HIGH
  413. * @retval None
  414. */
  415. __STATIC_INLINE void LL_RTC_TAMPER_SetActiveLevel(BKP_TypeDef *BKPx, uint32_t Tamper)
  416. {
  417. MODIFY_REG(BKPx->CR, BKP_CR_TPAL, Tamper);
  418. }
  419. /**
  420. * @brief Disable Active level for Tamper input
  421. * @rmtoll CR TPAL LL_RTC_TAMPER_SetActiveLevel\n
  422. * @retval None
  423. */
  424. __STATIC_INLINE uint32_t LL_RTC_TAMPER_GetActiveLevel(BKP_TypeDef *BKPx)
  425. {
  426. return (uint32_t)(READ_BIT(BKPx->CR, BKP_CR_TPAL));
  427. }
  428. /**
  429. * @}
  430. */
  431. /** @defgroup RTC_LL_EF_Backup_Registers Backup_Registers
  432. * @{
  433. */
  434. /**
  435. * @brief Writes a data in a specified RTC Backup data register.
  436. * @rmtoll BKPDR DR LL_RTC_BKP_SetRegister
  437. * @param BKPx BKP Instance
  438. * @param BackupRegister This parameter can be one of the following values:
  439. * @arg @ref LL_RTC_BKP_DR1
  440. * @arg @ref LL_RTC_BKP_DR2
  441. * @arg @ref LL_RTC_BKP_DR3
  442. * @arg @ref LL_RTC_BKP_DR4
  443. * @arg @ref LL_RTC_BKP_DR5
  444. * @arg @ref LL_RTC_BKP_DR6
  445. * @arg @ref LL_RTC_BKP_DR7
  446. * @arg @ref LL_RTC_BKP_DR8
  447. * @arg @ref LL_RTC_BKP_DR9
  448. * @arg @ref LL_RTC_BKP_DR10
  449. * @arg @ref LL_RTC_BKP_DR11 (*)
  450. * @arg @ref LL_RTC_BKP_DR12 (*)
  451. * @arg @ref LL_RTC_BKP_DR13 (*)
  452. * @arg @ref LL_RTC_BKP_DR14 (*)
  453. * @arg @ref LL_RTC_BKP_DR15 (*)
  454. * @arg @ref LL_RTC_BKP_DR16 (*)
  455. * @arg @ref LL_RTC_BKP_DR17 (*)
  456. * @arg @ref LL_RTC_BKP_DR18 (*)
  457. * @arg @ref LL_RTC_BKP_DR19 (*)
  458. * @arg @ref LL_RTC_BKP_DR20 (*)
  459. * @arg @ref LL_RTC_BKP_DR21 (*)
  460. * @arg @ref LL_RTC_BKP_DR22 (*)
  461. * @arg @ref LL_RTC_BKP_DR23 (*)
  462. * @arg @ref LL_RTC_BKP_DR24 (*)
  463. * @arg @ref LL_RTC_BKP_DR25 (*)
  464. * @arg @ref LL_RTC_BKP_DR26 (*)
  465. * @arg @ref LL_RTC_BKP_DR27 (*)
  466. * @arg @ref LL_RTC_BKP_DR28 (*)
  467. * @arg @ref LL_RTC_BKP_DR29 (*)
  468. * @arg @ref LL_RTC_BKP_DR30 (*)
  469. * @arg @ref LL_RTC_BKP_DR31 (*)
  470. * @arg @ref LL_RTC_BKP_DR32 (*)
  471. * @arg @ref LL_RTC_BKP_DR33 (*)
  472. * @arg @ref LL_RTC_BKP_DR34 (*)
  473. * @arg @ref LL_RTC_BKP_DR35 (*)
  474. * @arg @ref LL_RTC_BKP_DR36 (*)
  475. * @arg @ref LL_RTC_BKP_DR37 (*)
  476. * @arg @ref LL_RTC_BKP_DR38 (*)
  477. * @arg @ref LL_RTC_BKP_DR39 (*)
  478. * @arg @ref LL_RTC_BKP_DR40 (*)
  479. * @arg @ref LL_RTC_BKP_DR41 (*)
  480. * @arg @ref LL_RTC_BKP_DR42 (*)
  481. * (*) value not defined in all devices.
  482. * @param Data Value between Min_Data=0x00 and Max_Data=0xFFFFFFFF
  483. * @retval None
  484. */
  485. __STATIC_INLINE void LL_RTC_BKP_SetRegister(BKP_TypeDef *BKPx, uint32_t BackupRegister, uint32_t Data)
  486. {
  487. register uint32_t tmp = 0U;
  488. tmp = (uint32_t)BKP_BASE;
  489. tmp += (BackupRegister * 4U);
  490. /* Write the specified register */
  491. *(__IO uint32_t *)tmp = (uint32_t)Data;
  492. }
  493. /**
  494. * @brief Reads data from the specified RTC Backup data Register.
  495. * @rmtoll BKPDR DR LL_RTC_BKP_GetRegister
  496. * @param BKPx BKP Instance
  497. * @param BackupRegister This parameter can be one of the following values:
  498. * @arg @ref LL_RTC_BKP_DR1
  499. * @arg @ref LL_RTC_BKP_DR2
  500. * @arg @ref LL_RTC_BKP_DR3
  501. * @arg @ref LL_RTC_BKP_DR4
  502. * @arg @ref LL_RTC_BKP_DR5
  503. * @arg @ref LL_RTC_BKP_DR6
  504. * @arg @ref LL_RTC_BKP_DR7
  505. * @arg @ref LL_RTC_BKP_DR8
  506. * @arg @ref LL_RTC_BKP_DR9
  507. * @arg @ref LL_RTC_BKP_DR10
  508. * @arg @ref LL_RTC_BKP_DR11 (*)
  509. * @arg @ref LL_RTC_BKP_DR12 (*)
  510. * @arg @ref LL_RTC_BKP_DR13 (*)
  511. * @arg @ref LL_RTC_BKP_DR14 (*)
  512. * @arg @ref LL_RTC_BKP_DR15 (*)
  513. * @arg @ref LL_RTC_BKP_DR16 (*)
  514. * @arg @ref LL_RTC_BKP_DR17 (*)
  515. * @arg @ref LL_RTC_BKP_DR18 (*)
  516. * @arg @ref LL_RTC_BKP_DR19 (*)
  517. * @arg @ref LL_RTC_BKP_DR20 (*)
  518. * @arg @ref LL_RTC_BKP_DR21 (*)
  519. * @arg @ref LL_RTC_BKP_DR22 (*)
  520. * @arg @ref LL_RTC_BKP_DR23 (*)
  521. * @arg @ref LL_RTC_BKP_DR24 (*)
  522. * @arg @ref LL_RTC_BKP_DR25 (*)
  523. * @arg @ref LL_RTC_BKP_DR26 (*)
  524. * @arg @ref LL_RTC_BKP_DR27 (*)
  525. * @arg @ref LL_RTC_BKP_DR28 (*)
  526. * @arg @ref LL_RTC_BKP_DR29 (*)
  527. * @arg @ref LL_RTC_BKP_DR30 (*)
  528. * @arg @ref LL_RTC_BKP_DR31 (*)
  529. * @arg @ref LL_RTC_BKP_DR32 (*)
  530. * @arg @ref LL_RTC_BKP_DR33 (*)
  531. * @arg @ref LL_RTC_BKP_DR34 (*)
  532. * @arg @ref LL_RTC_BKP_DR35 (*)
  533. * @arg @ref LL_RTC_BKP_DR36 (*)
  534. * @arg @ref LL_RTC_BKP_DR37 (*)
  535. * @arg @ref LL_RTC_BKP_DR38 (*)
  536. * @arg @ref LL_RTC_BKP_DR39 (*)
  537. * @arg @ref LL_RTC_BKP_DR40 (*)
  538. * @arg @ref LL_RTC_BKP_DR41 (*)
  539. * @arg @ref LL_RTC_BKP_DR42 (*)
  540. * @retval Value between Min_Data=0x00 and Max_Data=0xFFFFFFFF
  541. */
  542. __STATIC_INLINE uint32_t LL_RTC_BKP_GetRegister(BKP_TypeDef *BKPx, uint32_t BackupRegister)
  543. {
  544. register uint32_t tmp = 0U;
  545. tmp = (uint32_t)BKP_BASE;
  546. tmp += (BackupRegister * 4U);
  547. /* Read the specified register */
  548. return ((*(__IO uint32_t *)tmp) & BKP_DR1_D);
  549. }
  550. /**
  551. * @}
  552. */
  553. /** @defgroup RTC_LL_EF_Calibration Calibration
  554. * @{
  555. */
  556. /**
  557. * @brief Set the coarse digital calibration
  558. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  559. * @note It can be written in initialization mode only (@ref LL_RTC_EnterInitMode function)
  560. * @rmtoll RTCCR CAL LL_RTC_CAL_SetCoarseDigital\n
  561. * @param BKPx RTC Instance
  562. * @param Value value of coarse calibration expressed in ppm (coded on 5 bits)
  563. * @note This Calibration value should be between 0 and 121 when using positive sign with a 4-ppm step.
  564. * @retval None
  565. */
  566. __STATIC_INLINE void LL_RTC_CAL_SetCoarseDigital(BKP_TypeDef *BKPx, uint32_t Value)
  567. {
  568. MODIFY_REG(BKPx->RTCCR, BKP_RTCCR_CAL, Value);
  569. }
  570. /**
  571. * @brief Get the coarse digital calibration value
  572. * @rmtoll RTCCR CAL LL_RTC_CAL_SetCoarseDigital\n
  573. * @param BKPx BKP Instance
  574. * @retval value of coarse calibration expressed in ppm (coded on 5 bits)
  575. */
  576. __STATIC_INLINE uint32_t LL_RTC_CAL_GetCoarseDigital(BKP_TypeDef *BKPx)
  577. {
  578. return (uint32_t)(READ_BIT(BKPx->RTCCR, BKP_RTCCR_CAL));
  579. }
  580. /**
  581. * @}
  582. */
  583. /** @defgroup RTC_LL_EF_FLAG_Management FLAG_Management
  584. * @{
  585. */
  586. /**
  587. * @brief Get RTC_TAMPI Interruption detection flag
  588. * @rmtoll CSR TIF LL_RTC_IsActiveFlag_TAMPI
  589. * @param BKPx BKP Instance
  590. * @retval State of bit (1 or 0).
  591. */
  592. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TAMPI(BKP_TypeDef *BKPx)
  593. {
  594. return (READ_BIT(BKPx->CSR, BKP_CSR_TIF) == (BKP_CSR_TIF));
  595. }
  596. /**
  597. * @brief Clear RTC_TAMP Interruption detection flag
  598. * @rmtoll CSR CTI LL_RTC_ClearFlag_TAMPI
  599. * @param BKPx BKP Instance
  600. * @retval None
  601. */
  602. __STATIC_INLINE void LL_RTC_ClearFlag_TAMPI(BKP_TypeDef *BKPx)
  603. {
  604. SET_BIT(BKPx->CSR, BKP_CSR_CTI);
  605. }
  606. /**
  607. * @brief Get RTC_TAMPE Event detection flag
  608. * @rmtoll CSR TEF LL_RTC_IsActiveFlag_TAMPE
  609. * @param BKPx BKP Instance
  610. * @retval State of bit (1 or 0).
  611. */
  612. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TAMPE(BKP_TypeDef *BKPx)
  613. {
  614. return (READ_BIT(BKPx->CSR, BKP_CSR_TEF) == (BKP_CSR_TEF));
  615. }
  616. /**
  617. * @brief Clear RTC_TAMPE Even detection flag
  618. * @rmtoll CSR CTE LL_RTC_ClearFlag_TAMPE
  619. * @param BKPx BKP Instance
  620. * @retval None
  621. */
  622. __STATIC_INLINE void LL_RTC_ClearFlag_TAMPE(BKP_TypeDef *BKPx)
  623. {
  624. SET_BIT(BKPx->CSR, BKP_CSR_CTE);
  625. }
  626. /**
  627. * @brief Get Alarm flag
  628. * @rmtoll CRL ALRF LL_RTC_IsActiveFlag_ALR
  629. * @param RTCx RTC Instance
  630. * @retval State of bit (1 or 0).
  631. */
  632. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_ALR(RTC_TypeDef *RTCx)
  633. {
  634. return (READ_BIT(RTCx->CRL, RTC_CRL_ALRF) == (RTC_CRL_ALRF));
  635. }
  636. /**
  637. * @brief Clear Alarm flag
  638. * @rmtoll CRL ALRF LL_RTC_ClearFlag_ALR
  639. * @param RTCx RTC Instance
  640. * @retval None
  641. */
  642. __STATIC_INLINE void LL_RTC_ClearFlag_ALR(RTC_TypeDef *RTCx)
  643. {
  644. CLEAR_BIT(RTCx->CRL, RTC_CRL_ALRF);
  645. }
  646. /**
  647. * @brief Get Registers synchronization flag
  648. * @rmtoll CRL RSF LL_RTC_IsActiveFlag_RS
  649. * @param RTCx RTC Instance
  650. * @retval State of bit (1 or 0).
  651. */
  652. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RS(RTC_TypeDef *RTCx)
  653. {
  654. return (READ_BIT(RTCx->CRL, RTC_CRL_RSF) == (RTC_CRL_RSF));
  655. }
  656. /**
  657. * @brief Clear Registers synchronization flag
  658. * @rmtoll CRL RSF LL_RTC_ClearFlag_RS
  659. * @param RTCx RTC Instance
  660. * @retval None
  661. */
  662. __STATIC_INLINE void LL_RTC_ClearFlag_RS(RTC_TypeDef *RTCx)
  663. {
  664. CLEAR_BIT(RTCx->CRL, RTC_CRL_RSF);
  665. }
  666. /**
  667. * @brief Get Registers OverFlow flag
  668. * @rmtoll CRL OWF LL_RTC_IsActiveFlag_OW
  669. * @param RTCx RTC Instance
  670. * @retval State of bit (1 or 0).
  671. */
  672. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_OW(RTC_TypeDef *RTCx)
  673. {
  674. return (READ_BIT(RTCx->CRL, RTC_CRL_OWF) == (RTC_CRL_OWF));
  675. }
  676. /**
  677. * @brief Clear Registers OverFlow flag
  678. * @rmtoll CRL OWF LL_RTC_ClearFlag_OW
  679. * @param RTCx RTC Instance
  680. * @retval None
  681. */
  682. __STATIC_INLINE void LL_RTC_ClearFlag_OW(RTC_TypeDef *RTCx)
  683. {
  684. CLEAR_BIT(RTCx->CRL, RTC_CRL_OWF);
  685. }
  686. /**
  687. * @brief Get Registers synchronization flag
  688. * @rmtoll CRL SECF LL_RTC_IsActiveFlag_SEC
  689. * @param RTCx RTC Instance
  690. * @retval State of bit (1 or 0).
  691. */
  692. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_SEC(RTC_TypeDef *RTCx)
  693. {
  694. return (READ_BIT(RTCx->CRL, RTC_CRL_SECF) == (RTC_CRL_SECF));
  695. }
  696. /**
  697. * @brief Clear Registers synchronization flag
  698. * @rmtoll CRL SECF LL_RTC_ClearFlag_SEC
  699. * @param RTCx RTC Instance
  700. * @retval None
  701. */
  702. __STATIC_INLINE void LL_RTC_ClearFlag_SEC(RTC_TypeDef *RTCx)
  703. {
  704. CLEAR_BIT(RTCx->CRL, RTC_CRL_SECF);
  705. }
  706. /**
  707. * @brief Get RTC Operation OFF status flag
  708. * @rmtoll CRL RTOFF LL_RTC_IsActiveFlag_RTOF
  709. * @param RTCx RTC Instance
  710. * @retval State of bit (1 or 0).
  711. */
  712. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RTOF(RTC_TypeDef *RTCx)
  713. {
  714. return (READ_BIT(RTCx->CRL, RTC_CRL_RTOFF) == (RTC_CRL_RTOFF));
  715. }
  716. /**
  717. * @}
  718. */
  719. /** @defgroup RTC_LL_EF_IT_Management IT_Management
  720. * @{
  721. */
  722. /**
  723. * @brief Enable Alarm interrupt
  724. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  725. * @rmtoll CRH ALRIE LL_RTC_EnableIT_ALR
  726. * @param RTCx RTC Instance
  727. * @retval None
  728. */
  729. __STATIC_INLINE void LL_RTC_EnableIT_ALR(RTC_TypeDef *RTCx)
  730. {
  731. SET_BIT(RTCx->CRH, RTC_CRH_ALRIE);
  732. }
  733. /**
  734. * @brief Disable Alarm interrupt
  735. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  736. * @rmtoll CRH ALRIE LL_RTC_DisableIT_ALR
  737. * @param RTCx RTC Instance
  738. * @retval None
  739. */
  740. __STATIC_INLINE void LL_RTC_DisableIT_ALR(RTC_TypeDef *RTCx)
  741. {
  742. CLEAR_BIT(RTCx->CRH, RTC_CRH_ALRIE);
  743. }
  744. /**
  745. * @brief Check if Alarm interrupt is enabled or not
  746. * @rmtoll CRH ALRIE LL_RTC_IsEnabledIT_ALR
  747. * @param RTCx RTC Instance
  748. * @retval State of bit (1 or 0).
  749. */
  750. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_ALR(RTC_TypeDef *RTCx)
  751. {
  752. return (READ_BIT(RTCx->CRH, RTC_CRH_ALRIE) == (RTC_CRH_ALRIE));
  753. }
  754. /**
  755. * @brief Enable Second Interrupt interrupt
  756. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  757. * @rmtoll CRH SECIE LL_RTC_EnableIT_SEC
  758. * @param RTCx RTC Instance
  759. * @retval None
  760. */
  761. __STATIC_INLINE void LL_RTC_EnableIT_SEC(RTC_TypeDef *RTCx)
  762. {
  763. SET_BIT(RTCx->CRH, RTC_CRH_SECIE);
  764. }
  765. /**
  766. * @brief Disable Second interrupt
  767. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  768. * @rmtoll CRH SECIE LL_RTC_DisableIT_SEC
  769. * @param RTCx RTC Instance
  770. * @retval None
  771. */
  772. __STATIC_INLINE void LL_RTC_DisableIT_SEC(RTC_TypeDef *RTCx)
  773. {
  774. CLEAR_BIT(RTCx->CRH, RTC_CRH_SECIE);
  775. }
  776. /**
  777. * @brief Check if Second interrupt is enabled or not
  778. * @rmtoll CRH SECIE LL_RTC_IsEnabledIT_SEC
  779. * @param RTCx RTC Instance
  780. * @retval State of bit (1 or 0).
  781. */
  782. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_SEC(RTC_TypeDef *RTCx)
  783. {
  784. return (READ_BIT(RTCx->CRH, RTC_CRH_SECIE) == (RTC_CRH_SECIE));
  785. }
  786. /**
  787. * @brief Enable OverFlow interrupt
  788. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  789. * @rmtoll CRH OWIE LL_RTC_EnableIT_OW
  790. * @param RTCx RTC Instance
  791. * @retval None
  792. */
  793. __STATIC_INLINE void LL_RTC_EnableIT_OW(RTC_TypeDef *RTCx)
  794. {
  795. SET_BIT(RTCx->CRH, RTC_CRH_OWIE);
  796. }
  797. /**
  798. * @brief Disable OverFlow interrupt
  799. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  800. * @rmtoll CRH OWIE LL_RTC_DisableIT_OW
  801. * @param RTCx RTC Instance
  802. * @retval None
  803. */
  804. __STATIC_INLINE void LL_RTC_DisableIT_OW(RTC_TypeDef *RTCx)
  805. {
  806. CLEAR_BIT(RTCx->CRH, RTC_CRH_OWIE);
  807. }
  808. /**
  809. * @brief Check if OverFlow interrupt is enabled or not
  810. * @rmtoll CRH OWIE LL_RTC_IsEnabledIT_OW
  811. * @param RTCx RTC Instance
  812. * @retval State of bit (1 or 0).
  813. */
  814. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_OW(RTC_TypeDef *RTCx)
  815. {
  816. return (READ_BIT(RTCx->CRH, RTC_CRH_OWIE) == (RTC_CRH_OWIE));
  817. }
  818. /**
  819. * @brief Enable Tamper interrupt
  820. * @rmtoll CSR TPIE LL_RTC_EnableIT_TAMP
  821. * @param BKPx BKP Instance
  822. * @retval None
  823. */
  824. __STATIC_INLINE void LL_RTC_EnableIT_TAMP(BKP_TypeDef *BKPx)
  825. {
  826. SET_BIT(BKPx->CSR, BKP_CSR_TPIE);
  827. }
  828. /**
  829. * @brief Disable Tamper interrupt
  830. * @rmtoll CSR TPIE LL_RTC_EnableIT_TAMP
  831. * @param BKPx BKP Instance
  832. * @retval None
  833. */
  834. __STATIC_INLINE void LL_RTC_DisableIT_TAMP(BKP_TypeDef *BKPx)
  835. {
  836. CLEAR_BIT(BKPx->CSR, BKP_CSR_TPIE);
  837. }
  838. /**
  839. * @brief Check if all the TAMPER interrupts are enabled or not
  840. * @rmtoll CSR TPIE LL_RTC_IsEnabledIT_TAMP
  841. * @param BKPx BKP Instance
  842. * @retval State of bit (1 or 0).
  843. */
  844. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_TAMP(BKP_TypeDef *BKPx)
  845. {
  846. return (READ_BIT(BKPx->CSR, BKP_CSR_TPIE) == BKP_CSR_TPIE);
  847. }
  848. /**
  849. * @}
  850. */
  851. #if defined(USE_FULL_LL_DRIVER)
  852. /** @defgroup RTC_LL_EF_Init Initialization and de-initialization functions
  853. * @{
  854. */
  855. ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx);
  856. ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct);
  857. void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct);
  858. ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct);
  859. void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct);
  860. ErrorStatus LL_RTC_ALARM_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
  861. void LL_RTC_ALARM_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
  862. ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx);
  863. ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx);
  864. ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx);
  865. ErrorStatus LL_RTC_TIME_SetCounter(RTC_TypeDef *RTCx, uint32_t TimeCounter);
  866. ErrorStatus LL_RTC_ALARM_SetCounter(RTC_TypeDef *RTCx, uint32_t AlarmCounter);
  867. /**
  868. * @}
  869. */
  870. #endif /* USE_FULL_LL_DRIVER */
  871. /**
  872. * @}
  873. */
  874. /**
  875. * @}
  876. */
  877. /**
  878. * @}
  879. */
  880. #endif /* defined(RTC) */
  881. /**
  882. * @}
  883. */
  884. #ifdef __cplusplus
  885. }
  886. #endif
  887. #endif /* __STM32F1xx_LL_RTC_H */
  888. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/