Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

809 lines
32 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 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 __STM32L1xx_HAL_RTC_H
  21. #define __STM32L1xx_HAL_RTC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @defgroup RTC RTC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup RTC_Exported_Types RTC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief HAL State structures definition
  39. */
  40. typedef enum
  41. {
  42. HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */
  43. HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */
  44. HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */
  45. HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */
  46. HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */
  47. } HAL_RTCStateTypeDef;
  48. /**
  49. * @brief RTC Configuration Structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t HourFormat; /*!< Specifies the RTC Hour Format.
  54. This parameter can be a value of @ref RTC_Hour_Formats */
  55. uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  56. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
  57. uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  58. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
  59. uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output.
  60. This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
  61. uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal.
  62. This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
  63. uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode.
  64. This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
  65. } RTC_InitTypeDef;
  66. /**
  67. * @brief RTC Time structure definition
  68. */
  69. typedef struct
  70. {
  71. uint8_t Hours; /*!< Specifies the RTC Time Hour.
  72. This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
  73. This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
  74. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  75. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  76. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  77. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  78. uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
  79. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  80. #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  81. uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content.
  82. This parameter corresponds to a time unit range between [0-1] Second
  83. with [1 Sec / SecondFraction +1] granularity */
  84. uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content
  85. corresponding to Synchronous pre-scaler factor value (PREDIV_S)
  86. This parameter corresponds to a time unit range between [0-1] Second
  87. with [1 Sec / SecondFraction +1] granularity.
  88. This field will be used only by HAL_RTC_GetTime function */
  89. #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  90. uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
  91. This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
  92. uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
  93. in CR register to store the operation.
  94. This parameter can be a value of @ref RTC_StoreOperation_Definitions */
  95. } RTC_TimeTypeDef;
  96. /**
  97. * @brief RTC Date structure definition
  98. */
  99. typedef struct
  100. {
  101. uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
  102. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  103. uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
  104. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  105. uint8_t Date; /*!< Specifies the RTC Date.
  106. This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
  107. uint8_t Year; /*!< Specifies the RTC Date Year.
  108. This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
  109. } RTC_DateTypeDef;
  110. /**
  111. * @brief RTC Alarm structure definition
  112. */
  113. typedef struct
  114. {
  115. RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */
  116. uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
  117. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  118. #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  119. uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks.
  120. This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
  121. #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  122. uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  123. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  124. uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
  125. If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
  126. If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
  127. uint32_t Alarm; /*!< Specifies the alarm .
  128. This parameter can be a value of @ref RTC_Alarms_Definitions */
  129. } RTC_AlarmTypeDef;
  130. /**
  131. * @brief RTC Handle Structure definition
  132. */
  133. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  134. typedef struct __RTC_HandleTypeDef
  135. #else
  136. typedef struct
  137. #endif
  138. {
  139. RTC_TypeDef *Instance; /*!< Register base address */
  140. RTC_InitTypeDef Init; /*!< RTC required parameters */
  141. HAL_LockTypeDef Lock; /*!< RTC locking object */
  142. __IO HAL_RTCStateTypeDef State; /*!< Time communication state */
  143. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  144. void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */
  145. void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */
  146. void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */
  147. void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */
  148. void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 1 Event callback */
  149. #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  150. void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 2 Event callback */
  151. void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 3 Event callback */
  152. #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  153. void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */
  154. void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */
  155. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  156. } RTC_HandleTypeDef;
  157. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  158. /**
  159. * @brief HAL LPTIM Callback ID enumeration definition
  160. */
  161. typedef enum
  162. {
  163. HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00U, /*!< RTC Alarm A Event Callback ID */
  164. HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01U, /*!< RTC Alarm B Event Callback ID */
  165. HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02U, /*!< RTC TimeStamp Event Callback ID */
  166. HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03U, /*!< RTC WakeUp Timer Event Callback ID */
  167. HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04U, /*!< RTC Tamper 1 Callback ID */
  168. #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  169. HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05U, /*!< RTC Tamper 2 Callback ID */
  170. HAL_RTC_TAMPER3_EVENT_CB_ID = 0x06U, /*!< RTC Tamper 3 Callback ID */
  171. #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  172. HAL_RTC_MSPINIT_CB_ID = 0x0EU, /*!< RTC Msp Init callback ID */
  173. HAL_RTC_MSPDEINIT_CB_ID = 0x0FU /*!< RTC Msp DeInit callback ID */
  174. } HAL_RTC_CallbackIDTypeDef;
  175. /**
  176. * @brief HAL RTC Callback pointer definition
  177. */
  178. typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */
  179. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  180. /**
  181. * @}
  182. */
  183. /* Exported constants --------------------------------------------------------*/
  184. /** @defgroup RTC_Exported_Constants RTC Exported Constants
  185. * @{
  186. */
  187. /** @defgroup RTC_Hour_Formats RTC Hour Formats
  188. * @{
  189. */
  190. #define RTC_HOURFORMAT_24 (0x00000000U)
  191. #define RTC_HOURFORMAT_12 (0x00000040U)
  192. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
  193. ((FORMAT) == RTC_HOURFORMAT_24))
  194. /**
  195. * @}
  196. */
  197. /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
  198. * @{
  199. */
  200. #define RTC_OUTPUT_POLARITY_HIGH (0x00000000U)
  201. #define RTC_OUTPUT_POLARITY_LOW (0x00100000U)
  202. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  203. ((POL) == RTC_OUTPUT_POLARITY_LOW))
  204. /**
  205. * @}
  206. */
  207. /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
  208. * @{
  209. */
  210. #define RTC_OUTPUT_TYPE_OPENDRAIN (0x00000000U)
  211. #define RTC_OUTPUT_TYPE_PUSHPULL (0x00040000U)
  212. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  213. ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  214. /**
  215. * @}
  216. */
  217. /** @defgroup RTC_Asynchronous_Predivider Asynchronous Predivider
  218. * @{
  219. */
  220. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU)
  221. /**
  222. * @}
  223. */
  224. /** @defgroup RTC_Time_Definitions Time Definitions
  225. * @{
  226. */
  227. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U))
  228. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U)
  229. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U)
  230. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U)
  231. /**
  232. * @}
  233. */
  234. /** @defgroup RTC_AM_PM_Definitions AM PM Definitions
  235. * @{
  236. */
  237. #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
  238. #define RTC_HOURFORMAT12_PM ((uint8_t)0x40)
  239. #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM))
  240. /**
  241. * @}
  242. */
  243. /** @defgroup RTC_DayLightSaving_Definitions DayLightSaving
  244. * @{
  245. */
  246. #define RTC_DAYLIGHTSAVING_SUB1H (0x00020000U)
  247. #define RTC_DAYLIGHTSAVING_ADD1H (0x00010000U)
  248. #define RTC_DAYLIGHTSAVING_NONE (0x00000000U)
  249. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  250. ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  251. ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  252. /**
  253. * @}
  254. */
  255. /** @defgroup RTC_StoreOperation_Definitions StoreOperation
  256. * @{
  257. */
  258. #define RTC_STOREOPERATION_RESET (0x00000000U)
  259. #define RTC_STOREOPERATION_SET (0x00040000U)
  260. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  261. ((OPERATION) == RTC_STOREOPERATION_SET))
  262. /**
  263. * @}
  264. */
  265. /** @defgroup RTC_Input_parameter_format_definitions Input Parameter Format
  266. * @{
  267. */
  268. #define RTC_FORMAT_BIN (0x000000000U)
  269. #define RTC_FORMAT_BCD (0x000000001U)
  270. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
  271. /**
  272. * @}
  273. */
  274. /** @defgroup RTC_Year_Date_Definitions Year Definitions
  275. * @{
  276. */
  277. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U)
  278. /**
  279. * @}
  280. */
  281. /** @defgroup RTC_Month_Date_Definitions Month Definitions
  282. * @{
  283. */
  284. /* Coded in BCD format */
  285. #define RTC_MONTH_JANUARY ((uint8_t)0x01)
  286. #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
  287. #define RTC_MONTH_MARCH ((uint8_t)0x03)
  288. #define RTC_MONTH_APRIL ((uint8_t)0x04)
  289. #define RTC_MONTH_MAY ((uint8_t)0x05)
  290. #define RTC_MONTH_JUNE ((uint8_t)0x06)
  291. #define RTC_MONTH_JULY ((uint8_t)0x07)
  292. #define RTC_MONTH_AUGUST ((uint8_t)0x08)
  293. #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
  294. #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
  295. #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
  296. #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
  297. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U))
  298. #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U))
  299. /**
  300. * @}
  301. */
  302. /** @defgroup RTC_WeekDay_Definitions WeekDay Definitions
  303. * @{
  304. */
  305. #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
  306. #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
  307. #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
  308. #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
  309. #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
  310. #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
  311. #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
  312. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  313. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  314. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  315. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  316. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  317. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  318. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  319. /**
  320. * @}
  321. */
  322. /** @defgroup RTC_Alarm_Definitions Alarm Definitions
  323. * @{
  324. */
  325. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
  326. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  327. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  328. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  329. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  330. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  331. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  332. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  333. /**
  334. * @}
  335. */
  336. /** @defgroup RTC_AlarmDateWeekDay_Definitions AlarmDateWeekDay Definitions
  337. * @{
  338. */
  339. #define RTC_ALARMDATEWEEKDAYSEL_DATE (0x00000000U)
  340. #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY (0x40000000U)
  341. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  342. ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  343. /**
  344. * @}
  345. */
  346. /** @defgroup RTC_AlarmMask_Definitions Alarm Mask Definitions
  347. * @{
  348. */
  349. #define RTC_ALARMMASK_NONE (0x00000000U)
  350. #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
  351. #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
  352. #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
  353. #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
  354. #define RTC_ALARMMASK_ALL (0x80808080U)
  355. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET)
  356. /**
  357. * @}
  358. */
  359. /** @defgroup RTC_Alarms_Definitions Alarms Definitions
  360. * @{
  361. */
  362. #define RTC_ALARM_A RTC_CR_ALRAE
  363. #define RTC_ALARM_B RTC_CR_ALRBE
  364. #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
  365. /**
  366. * @}
  367. */
  368. /**
  369. * @}
  370. */
  371. /* Exported macros -----------------------------------------------------------*/
  372. /** @defgroup RTC_Exported_macros RTC Exported Macros
  373. * @{
  374. */
  375. /** @brief Reset RTC handle state
  376. * @param __HANDLE__ RTC handle.
  377. * @retval None
  378. */
  379. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  380. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
  381. (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
  382. (__HANDLE__)->MspInitCallback = NULL;\
  383. (__HANDLE__)->MspDeInitCallback = NULL;\
  384. }while(0)
  385. #else
  386. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
  387. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  388. /**
  389. * @brief Disable the write protection for RTC registers.
  390. * @param __HANDLE__ specifies the RTC handle.
  391. * @retval None
  392. */
  393. #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
  394. do{ \
  395. (__HANDLE__)->Instance->WPR = 0xCAU; \
  396. (__HANDLE__)->Instance->WPR = 0x53U; \
  397. } while(0U)
  398. /**
  399. * @brief Enable the write protection for RTC registers.
  400. * @param __HANDLE__ specifies the RTC handle.
  401. * @retval None
  402. */
  403. #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
  404. do{ \
  405. (__HANDLE__)->Instance->WPR = 0xFFU; \
  406. } while(0U)
  407. /**
  408. * @brief Enable the RTC ALARMA peripheral.
  409. * @param __HANDLE__ specifies the RTC handle.
  410. * @retval None
  411. */
  412. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  413. /**
  414. * @brief Disable the RTC ALARMA peripheral.
  415. * @param __HANDLE__ specifies the RTC handle.
  416. * @retval None
  417. */
  418. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  419. /**
  420. * @brief Enable the RTC ALARMB peripheral.
  421. * @param __HANDLE__ specifies the RTC handle.
  422. * @retval None
  423. */
  424. #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
  425. /**
  426. * @brief Disable the RTC ALARMB peripheral.
  427. * @param __HANDLE__ specifies the RTC handle.
  428. * @retval None
  429. */
  430. #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
  431. /**
  432. * @brief Enable the RTC Alarm interrupt.
  433. * @param __HANDLE__ specifies the RTC handle.
  434. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  435. * This parameter can be any combination of the following values:
  436. * @arg RTC_IT_ALRA: Alarm A interrupt
  437. * @arg RTC_IT_ALRB: Alarm B interrupt
  438. * @retval None
  439. */
  440. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  441. /**
  442. * @brief Disable the RTC Alarm interrupt.
  443. * @param __HANDLE__ specifies the RTC handle.
  444. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  445. * This parameter can be any combination of the following values:
  446. * @arg RTC_IT_ALRA: Alarm A interrupt
  447. * @arg RTC_IT_ALRB: Alarm B interrupt
  448. * @retval None
  449. */
  450. #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  451. /**
  452. * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
  453. * @param __HANDLE__ specifies the RTC handle.
  454. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  455. * This parameter can be:
  456. * @arg RTC_IT_ALRA: Alarm A interrupt
  457. * @arg RTC_IT_ALRB: Alarm B interrupt
  458. * @retval None
  459. */
  460. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != 0U)? 1U : 0U)
  461. /**
  462. * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
  463. * @param __HANDLE__ specifies the RTC handle.
  464. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  465. * This parameter can be:
  466. * @arg RTC_IT_ALRA: Alarm A interrupt
  467. * @arg RTC_IT_ALRB: Alarm B interrupt
  468. * @retval None
  469. */
  470. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  471. /**
  472. * @brief Get the selected RTC Alarm's flag status.
  473. * @param __HANDLE__ specifies the RTC handle.
  474. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  475. * This parameter can be:
  476. * @arg RTC_FLAG_ALRAF
  477. * @arg RTC_FLAG_ALRBF
  478. * @arg RTC_FLAG_ALRAWF
  479. * @arg RTC_FLAG_ALRBWF
  480. * @retval None
  481. */
  482. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
  483. /**
  484. * @brief Clear the RTC Alarm's pending flags.
  485. * @param __HANDLE__ specifies the RTC handle.
  486. * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
  487. * This parameter can be:
  488. * @arg RTC_FLAG_ALRAF
  489. * @arg RTC_FLAG_ALRBF
  490. * @retval None
  491. */
  492. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  493. /**
  494. * @brief Enable interrupt on the RTC Alarm associated Exti line.
  495. * @retval None
  496. */
  497. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
  498. /**
  499. * @brief Disable interrupt on the RTC Alarm associated Exti line.
  500. * @retval None
  501. */
  502. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  503. /**
  504. * @brief Enable event on the RTC Alarm associated Exti line.
  505. * @retval None.
  506. */
  507. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
  508. /**
  509. * @brief Disable event on the RTC Alarm associated Exti line.
  510. * @retval None.
  511. */
  512. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  513. /**
  514. * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
  515. * @retval None.
  516. */
  517. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  518. /**
  519. * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
  520. * @retval None.
  521. */
  522. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  523. /**
  524. * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
  525. * @retval None.
  526. */
  527. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  528. /**
  529. * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
  530. * @retval None.
  531. */
  532. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  533. /**
  534. * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  535. * @retval None.
  536. */
  537. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  538. __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
  539. __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
  540. } while(0U)
  541. /**
  542. * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  543. * @retval None.
  544. */
  545. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  546. __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \
  547. __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
  548. } while(0U)
  549. /**
  550. * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  551. * @retval Line Status.
  552. */
  553. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
  554. /**
  555. * @brief Clear the RTC Alarm associated Exti line flag.
  556. * @retval None.
  557. */
  558. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
  559. /**
  560. * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  561. * @retval None.
  562. */
  563. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
  564. /**
  565. * @}
  566. */
  567. /* Include RTC HAL Extended module */
  568. #include "stm32l1xx_hal_rtc_ex.h"
  569. /* Exported functions --------------------------------------------------------*/
  570. /** @defgroup RTC_Exported_Functions RTC Exported Functions
  571. * @{
  572. */
  573. /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
  574. * @{
  575. */
  576. /* Initialization and de-initialization functions ****************************/
  577. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  578. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  579. void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  580. void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  581. /* Callbacks Register/UnRegister functions ***********************************/
  582. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  583. HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
  584. HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
  585. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  586. /**
  587. * @}
  588. */
  589. /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
  590. * @{
  591. */
  592. /* RTC Time and Date functions ************************************************/
  593. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  594. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  595. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  596. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  597. /**
  598. * @}
  599. */
  600. /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
  601. * @{
  602. */
  603. /* RTC Alarm functions ********************************************************/
  604. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  605. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  606. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  607. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  608. void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  609. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  610. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  611. /**
  612. * @}
  613. */
  614. /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
  615. * @{
  616. */
  617. /* Peripheral Control functions ***********************************************/
  618. HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
  619. /**
  620. * @}
  621. */
  622. /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
  623. * @{
  624. */
  625. /* Peripheral State functions *************************************************/
  626. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  627. /**
  628. * @}
  629. */
  630. /**
  631. * @}
  632. */
  633. /* Private types -------------------------------------------------------------*/
  634. /* Private variables ---------------------------------------------------------*/
  635. /* Private constants ---------------------------------------------------------*/
  636. /** @defgroup RTC_Private_Constants RTC Private Constants
  637. * @{
  638. */
  639. #define RTC_TIMEOUT_VALUE 1000U
  640. #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */
  641. /**
  642. * @}
  643. */
  644. /* Private macros ------------------------------------------------------------*/
  645. /** @defgroup RTC_Private_Macros RTC Private Macros
  646. * @{
  647. */
  648. /**
  649. * @}
  650. */
  651. /* Private functions -------------------------------------------------------------*/
  652. /** @defgroup RTC_Private_Functions RTC Private Functions
  653. * @{
  654. */
  655. HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
  656. uint8_t RTC_ByteToBcd2(uint8_t Value);
  657. uint8_t RTC_Bcd2ToByte(uint8_t Value);
  658. /**
  659. * @}
  660. */
  661. /**
  662. * @}
  663. */
  664. /**
  665. * @}
  666. */
  667. #ifdef __cplusplus
  668. }
  669. #endif
  670. #endif /* __STM32L1xx_HAL_RTC_H */
  671. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/