Subversion Repositories FuelGauge

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f0xx_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) 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.  
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __STM32F0xx_HAL_RTC_H
  22. #define __STM32F0xx_HAL_RTC_H
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f0xx_hal_def.h"
  30.  
  31. /** @addtogroup STM32F0xx_HAL_Driver
  32.   * @{
  33.   */
  34.  
  35. /** @defgroup RTC RTC
  36.   * @{
  37.   */
  38.  
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @defgroup RTC_Exported_Types RTC Exported Types
  41.   * @{
  42.   */
  43.  
  44. /**
  45.   * @brief  HAL State structures definition
  46.   */
  47. typedef enum
  48. {
  49.   HAL_RTC_STATE_RESET             = 0x00U,  /*!< RTC not yet initialized or disabled */
  50.   HAL_RTC_STATE_READY             = 0x01U,  /*!< RTC initialized and ready for use   */
  51.   HAL_RTC_STATE_BUSY              = 0x02U,  /*!< RTC process is ongoing              */
  52.   HAL_RTC_STATE_TIMEOUT           = 0x03U,  /*!< RTC timeout state                   */
  53.   HAL_RTC_STATE_ERROR             = 0x04U   /*!< RTC error state                     */
  54.  
  55. } HAL_RTCStateTypeDef;
  56.  
  57. /**
  58.   * @brief  RTC Configuration Structure definition
  59.   */
  60. typedef struct
  61. {
  62.   uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
  63.                                  This parameter can be a value of @ref RTC_Hour_Formats */
  64.  
  65.   uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
  66.                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
  67.  
  68.   uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
  69.                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
  70.  
  71.   uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.
  72.                                  This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
  73.  
  74.   uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.
  75.                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
  76.  
  77.   uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.
  78.                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
  79. } RTC_InitTypeDef;
  80.  
  81. /**
  82.   * @brief  RTC Time structure definition
  83.   */
  84. typedef struct
  85. {
  86.   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
  87.                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
  88.                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected  */
  89.  
  90.   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
  91.                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  92.  
  93.   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
  94.                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  95.  
  96.   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
  97.                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
  98.  
  99.   uint32_t SubSeconds;     /*!< Specifies the RTC_SSR RTC Sub Second register content.
  100.                                  This parameter corresponds to a time unit range between [0-1] Second
  101.                                  with [1 Sec / SecondFraction +1] granularity */
  102.  
  103.   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
  104.                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
  105.                                  This parameter corresponds to a time unit range between [0-1] Second
  106.                                  with [1 Sec / SecondFraction +1] granularity.
  107.                                  This field will be used only by HAL_RTC_GetTime function */
  108.  
  109.   uint32_t DayLightSaving;  /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
  110.                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
  111.  
  112.   uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
  113.                                  in CR register to store the operation.
  114.                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
  115. } RTC_TimeTypeDef;
  116.  
  117. /**
  118.   * @brief  RTC Date structure definition
  119.   */
  120. typedef struct
  121. {
  122.   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
  123.                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
  124.  
  125.   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
  126.                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
  127.  
  128.   uint8_t Date;     /*!< Specifies the RTC Date.
  129.                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
  130.  
  131.   uint8_t Year;     /*!< Specifies the RTC Date Year.
  132.                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
  133.  
  134. } RTC_DateTypeDef;
  135.  
  136. /**
  137.   * @brief  RTC Alarm structure definition
  138.   */
  139. typedef struct
  140. {
  141.   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
  142.  
  143.   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
  144.                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  145.  
  146.   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
  147.                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
  148.  
  149.   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
  150.                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  151.  
  152.   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
  153.                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
  154.                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
  155.  
  156.   uint32_t Alarm;                /*!< Specifies the alarm .
  157.                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
  158. } RTC_AlarmTypeDef;
  159.  
  160. /**
  161.   * @brief  RTC Handle Structure definition
  162.   */
  163. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  164. typedef struct __RTC_HandleTypeDef
  165. #else
  166. typedef struct
  167. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  168. {
  169.   RTC_TypeDef                 *Instance;  /*!< Register base address    */
  170.  
  171.   RTC_InitTypeDef             Init;       /*!< RTC required parameters  */
  172.  
  173.   HAL_LockTypeDef             Lock;       /*!< RTC locking object       */
  174.  
  175.   __IO HAL_RTCStateTypeDef    State;      /*!< Time communication state */
  176.  
  177. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  178.   void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc);           /*!< RTC Alarm A Event callback         */
  179.  
  180.   void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc);        /*!< RTC TimeStamp Event callback       */
  181.  
  182. #if defined(RTC_WAKEUP_SUPPORT)
  183.   void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc);      /*!< RTC WakeUpTimer Event callback     */
  184.  
  185. #endif /* RTC_WAKEUP_SUPPORT */
  186.   void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Tamper 1 Event callback        */
  187.  
  188.   void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Tamper 2 Event callback        */
  189.  
  190. #if defined(RTC_TAMPER3_SUPPORT)
  191.   void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Tamper 3 Event callback        */
  192.  
  193. #endif /* RTC_TAMPER3_SUPPORT */
  194.   void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc);               /*!< RTC Msp Init callback              */
  195.  
  196.   void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc);             /*!< RTC Msp DeInit callback            */
  197.  
  198. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  199.  
  200. } RTC_HandleTypeDef;
  201.  
  202. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  203. /**
  204.   * @brief  HAL RTC Callback ID enumeration definition
  205.   */
  206. typedef enum
  207. {
  208.   HAL_RTC_ALARM_A_EVENT_CB_ID           = 0x00u,    /*!< RTC Alarm A Event Callback ID      */
  209.   HAL_RTC_TIMESTAMP_EVENT_CB_ID         = 0x02u,    /*!< RTC TimeStamp Event Callback ID    */
  210. #if defined(RTC_WAKEUP_SUPPORT)
  211.   HAL_RTC_WAKEUPTIMER_EVENT_CB_ID       = 0x03u,    /*!< RTC WakeUp Timer Event Callback ID */
  212. #endif /* RTC_WAKEUP_SUPPORT */
  213.   HAL_RTC_TAMPER1_EVENT_CB_ID           = 0x04u,    /*!< RTC Tamper 1 Callback ID           */
  214.   HAL_RTC_TAMPER2_EVENT_CB_ID           = 0x05u,    /*!< RTC Tamper 2 Callback ID           */
  215. #if defined(RTC_TAMPER3_SUPPORT)
  216.   HAL_RTC_TAMPER3_EVENT_CB_ID           = 0x06u,    /*!< RTC Tamper 3 Callback ID           */
  217. #endif /* RTC_TAMPER3_SUPPORT */
  218.   HAL_RTC_MSPINIT_CB_ID                 = 0x0Eu,    /*!< RTC Msp Init callback ID           */
  219.   HAL_RTC_MSPDEINIT_CB_ID               = 0x0Fu     /*!< RTC Msp DeInit callback ID         */
  220. } HAL_RTC_CallbackIDTypeDef;
  221.  
  222. /**
  223.   * @brief  HAL RTC Callback pointer definition
  224.   */
  225. typedef  void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc);  /*!< pointer to an RTC callback function */
  226. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  227. /**
  228.   * @}
  229.   */
  230.  
  231. /* Exported constants --------------------------------------------------------*/
  232. /** @defgroup RTC_Exported_Constants RTC Exported Constants
  233.   * @{
  234.   */
  235.  
  236. /** @defgroup RTC_Hour_Formats RTC Hour Formats
  237.   * @{
  238.   */
  239. #define RTC_HOURFORMAT_24              0x00000000U
  240. #define RTC_HOURFORMAT_12              0x00000040U
  241.  
  242. /**
  243.   * @}
  244.   */
  245.  
  246. /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
  247.   * @{
  248.   */
  249. #define RTC_OUTPUT_POLARITY_HIGH       0x00000000U
  250. #define RTC_OUTPUT_POLARITY_LOW        0x00100000U
  251. /**
  252.   * @}
  253.   */
  254.  
  255. /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
  256.   * @{
  257.   */
  258. #define RTC_OUTPUT_TYPE_OPENDRAIN      0x00000000U
  259. #define RTC_OUTPUT_TYPE_PUSHPULL       0x00040000U
  260. /**
  261.   * @}
  262.   */
  263.  
  264. /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
  265.   * @{
  266.   */
  267. #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
  268. #define RTC_HOURFORMAT12_PM            ((uint8_t)0x40)
  269. /**
  270.   * @}
  271.   */
  272.  
  273. /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
  274.   * @{
  275.   */
  276. #define RTC_DAYLIGHTSAVING_SUB1H       0x00020000U
  277. #define RTC_DAYLIGHTSAVING_ADD1H       0x00010000U
  278. #define RTC_DAYLIGHTSAVING_NONE        0x00000000U
  279. /**
  280.   * @}
  281.   */
  282.  
  283. /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
  284.   * @{
  285.   */
  286. #define RTC_STOREOPERATION_RESET        0x00000000U
  287. #define RTC_STOREOPERATION_SET          0x00040000U
  288. /**
  289.   * @}
  290.   */
  291.  
  292. /** @defgroup RTC_Input_parameter_format_definitions RTC Input parameter format definitions
  293.   * @{
  294.   */
  295. #define RTC_FORMAT_BIN                      0x000000000U
  296. #define RTC_FORMAT_BCD                      0x000000001U
  297. /**
  298.   * @}
  299.   */
  300.  
  301. /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
  302.   * @{
  303.   */
  304. /* Coded in BCD format */
  305. #define RTC_MONTH_JANUARY              ((uint8_t)0x01)
  306. #define RTC_MONTH_FEBRUARY             ((uint8_t)0x02)
  307. #define RTC_MONTH_MARCH                ((uint8_t)0x03)
  308. #define RTC_MONTH_APRIL                ((uint8_t)0x04)
  309. #define RTC_MONTH_MAY                  ((uint8_t)0x05)
  310. #define RTC_MONTH_JUNE                 ((uint8_t)0x06)
  311. #define RTC_MONTH_JULY                 ((uint8_t)0x07)
  312. #define RTC_MONTH_AUGUST               ((uint8_t)0x08)
  313. #define RTC_MONTH_SEPTEMBER            ((uint8_t)0x09)
  314. #define RTC_MONTH_OCTOBER              ((uint8_t)0x10)
  315. #define RTC_MONTH_NOVEMBER             ((uint8_t)0x11)
  316. #define RTC_MONTH_DECEMBER             ((uint8_t)0x12)
  317. /**
  318.   * @}
  319.   */
  320.  
  321. /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
  322.   * @{
  323.   */
  324. #define RTC_WEEKDAY_MONDAY             ((uint8_t)0x01)
  325. #define RTC_WEEKDAY_TUESDAY            ((uint8_t)0x02)
  326. #define RTC_WEEKDAY_WEDNESDAY          ((uint8_t)0x03)
  327. #define RTC_WEEKDAY_THURSDAY           ((uint8_t)0x04)
  328. #define RTC_WEEKDAY_FRIDAY             ((uint8_t)0x05)
  329. #define RTC_WEEKDAY_SATURDAY           ((uint8_t)0x06)
  330. #define RTC_WEEKDAY_SUNDAY             ((uint8_t)0x07)
  331. /**
  332.   * @}
  333.   */
  334.  
  335. /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
  336.   * @{
  337.   */
  338. #define RTC_ALARMDATEWEEKDAYSEL_DATE      0x00000000U
  339. #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY   0x40000000U
  340. /**
  341.   * @}
  342.   */
  343.  
  344. /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
  345.   * @{
  346.   */
  347. #define RTC_ALARMMASK_NONE                0x00000000U
  348. #define RTC_ALARMMASK_DATEWEEKDAY         RTC_ALRMAR_MSK4
  349. #define RTC_ALARMMASK_HOURS               RTC_ALRMAR_MSK3
  350. #define RTC_ALARMMASK_MINUTES             RTC_ALRMAR_MSK2
  351. #define RTC_ALARMMASK_SECONDS             RTC_ALRMAR_MSK1
  352. #define RTC_ALARMMASK_ALL                 0x80808080U
  353. /**
  354.   * @}
  355.   */
  356.  
  357. /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
  358.   * @{
  359.   */
  360. #define RTC_ALARM_A                       RTC_CR_ALRAE
  361.  
  362. /**
  363.   * @}
  364.   */
  365.  
  366. /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
  367.   * @{
  368.   */
  369. #define RTC_ALARMSUBSECONDMASK_ALL         0x00000000U  /*!< All Alarm SS fields are masked.
  370.                                                                         There is no comparison on sub seconds
  371.                                                                         for Alarm */
  372. #define RTC_ALARMSUBSECONDMASK_SS14_1      0x01000000U  /*!< SS[14:1] are don't care in Alarm
  373.                                                                         comparison. Only SS[0] is compared.    */
  374. #define RTC_ALARMSUBSECONDMASK_SS14_2      0x02000000U  /*!< SS[14:2] are don't care in Alarm
  375.                                                                         comparison. Only SS[1:0] are compared  */
  376. #define RTC_ALARMSUBSECONDMASK_SS14_3      0x03000000U  /*!< SS[14:3] are don't care in Alarm
  377.                                                                         comparison. Only SS[2:0] are compared  */
  378. #define RTC_ALARMSUBSECONDMASK_SS14_4      0x04000000U  /*!< SS[14:4] are don't care in Alarm
  379.                                                                         comparison. Only SS[3:0] are compared  */
  380. #define RTC_ALARMSUBSECONDMASK_SS14_5      0x05000000U  /*!< SS[14:5] are don't care in Alarm
  381.                                                                         comparison. Only SS[4:0] are compared  */
  382. #define RTC_ALARMSUBSECONDMASK_SS14_6      0x06000000U  /*!< SS[14:6] are don't care in Alarm
  383.                                                                         comparison. Only SS[5:0] are compared  */
  384. #define RTC_ALARMSUBSECONDMASK_SS14_7      0x07000000U  /*!< SS[14:7] are don't care in Alarm
  385.                                                                         comparison. Only SS[6:0] are compared  */
  386. #define RTC_ALARMSUBSECONDMASK_SS14_8      0x08000000U  /*!< SS[14:8] are don't care in Alarm
  387.                                                                         comparison. Only SS[7:0] are compared  */
  388. #define RTC_ALARMSUBSECONDMASK_SS14_9      0x09000000U  /*!< SS[14:9] are don't care in Alarm
  389.                                                                         comparison. Only SS[8:0] are compared  */
  390. #define RTC_ALARMSUBSECONDMASK_SS14_10     0x0A000000U  /*!< SS[14:10] are don't care in Alarm
  391.                                                                         comparison. Only SS[9:0] are compared  */
  392. #define RTC_ALARMSUBSECONDMASK_SS14_11     0x0B000000U  /*!< SS[14:11] are don't care in Alarm
  393.                                                                         comparison. Only SS[10:0] are compared */
  394. #define RTC_ALARMSUBSECONDMASK_SS14_12     0x0C000000U  /*!< SS[14:12] are don't care in Alarm
  395.                                                                         comparison.Only SS[11:0] are compared  */
  396. #define RTC_ALARMSUBSECONDMASK_SS14_13     0x0D000000U  /*!< SS[14:13] are don't care in Alarm
  397.                                                                         comparison. Only SS[12:0] are compared */
  398. #define RTC_ALARMSUBSECONDMASK_SS14        0x0E000000U  /*!< SS[14] is don't care in Alarm
  399.                                                                         comparison.Only SS[13:0] are compared  */
  400. #define RTC_ALARMSUBSECONDMASK_NONE        0x0F000000U  /*!< SS[14:0] are compared and must match
  401.                                                                         to activate alarm. */
  402. /**
  403.   * @}
  404.   */
  405.  
  406. /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
  407.   * @{
  408.   */
  409. #define RTC_IT_TS                         0x00008000U
  410. #define RTC_IT_WUT                        0x00004000U
  411. #define RTC_IT_ALRA                       0x00001000U
  412. #define RTC_IT_TAMP                       0x00000004U /* Used only to Enable the Tamper Interrupt */
  413. #define RTC_IT_TAMP1                      0x00020000U /*only for RTC_ISR flag check*/
  414. #define RTC_IT_TAMP2                      0x00040000U /*only for RTC_ISR flag check*/
  415. #define RTC_IT_TAMP3                      0x00080000U /*only for RTC_ISR flag check*/
  416. /**
  417.   * @}
  418.   */
  419.  
  420. /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
  421.   * @{
  422.   */
  423. #define RTC_FLAG_RECALPF                  0x00010000U
  424. #define RTC_FLAG_TAMP3F                   0x00008000U
  425. #define RTC_FLAG_TAMP2F                   0x00004000U
  426. #define RTC_FLAG_TAMP1F                   0x00002000U
  427. #define RTC_FLAG_TSOVF                    0x00001000U
  428. #define RTC_FLAG_TSF                      0x00000800U
  429. #define RTC_FLAG_WUTF                     0x00000400U
  430. #define RTC_FLAG_ALRAF                    0x00000100U
  431. #define RTC_FLAG_INITF                    0x00000040U
  432. #define RTC_FLAG_RSF                      0x00000020U
  433. #define RTC_FLAG_INITS                    0x00000010U
  434. #define RTC_FLAG_SHPF                     0x00000008U
  435. #define RTC_FLAG_WUTWF                    0x00000004U
  436. #define RTC_FLAG_ALRAWF                   0x00000001U
  437. /**
  438.   * @}
  439.   */
  440.  
  441. /**
  442.   * @}
  443.   */
  444.  
  445. /* Exported macros ------------------------------------------------------------*/
  446. /** @defgroup RTC_Exported_Macros RTC Exported Macros
  447.   * @{
  448.   */
  449.  
  450. /** @brief Reset RTC handle state
  451.   * @param  __HANDLE__ RTC handle.
  452.   * @retval None
  453.   */
  454. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  455. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
  456.                                                       (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
  457.                                                       (__HANDLE__)->MspInitCallback = NULL;\
  458.                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
  459.                                                      }while(0u)
  460. #else
  461. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
  462. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  463.  
  464. /**
  465.   * @brief  Disable the write protection for RTC registers.
  466.   * @param  __HANDLE__ specifies the RTC handle.
  467.   * @retval None
  468.   */
  469. #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
  470.                         do{                                       \
  471.                             (__HANDLE__)->Instance->WPR = 0xCAU;   \
  472.                             (__HANDLE__)->Instance->WPR = 0x53U;   \
  473.                           } while(0)
  474.  
  475. /**
  476.   * @brief  Enable the write protection for RTC registers.
  477.   * @param  __HANDLE__ specifies the RTC handle.
  478.   * @retval None
  479.   */
  480. #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
  481.                         do{                                       \
  482.                             (__HANDLE__)->Instance->WPR = 0xFFU;   \
  483.                           } while(0)
  484.  
  485. /**
  486.   * @brief  Enable the RTC ALARMA peripheral.
  487.   * @param  __HANDLE__ specifies the RTC handle.
  488.   * @retval None
  489.   */
  490. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  491.  
  492. /**
  493.   * @brief  Disable the RTC ALARMA peripheral.
  494.   * @param  __HANDLE__ specifies the RTC handle.
  495.   * @retval None
  496.   */
  497. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  498.  
  499. /**
  500.   * @brief  Enable the RTC Alarm interrupt.
  501.   * @param  __HANDLE__ specifies the RTC handle.
  502.   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  503.   *          This parameter can be any combination of the following values:
  504.   *             @arg RTC_IT_ALRA: Alarm A interrupt
  505.   * @retval None
  506.   */
  507. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  508.  
  509. /**
  510.   * @brief  Disable the RTC Alarm interrupt.
  511.   * @param  __HANDLE__ specifies the RTC handle.
  512.   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  513.   *         This parameter can be any combination of the following values:
  514.   *            @arg RTC_IT_ALRA: Alarm A interrupt
  515.   * @retval None
  516.   */
  517. #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  518.  
  519. /**
  520.   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
  521.   * @param  __HANDLE__ specifies the RTC handle.
  522.   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt to check.
  523.   *         This parameter can be:
  524.   *            @arg RTC_IT_ALRA: Alarm A interrupt
  525.   * @retval None
  526.   */
  527. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__)  (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
  528.  
  529. /**
  530.   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
  531.   * @param  __HANDLE__ specifies the RTC handle.
  532.   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  533.   *         This parameter can be:
  534.   *            @arg RTC_IT_ALRA: Alarm A interrupt
  535.   * @retval None
  536.   */
  537. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
  538.  
  539. /**
  540.   * @brief  Get the selected RTC Alarm's flag status.
  541.   * @param  __HANDLE__ specifies the RTC handle.
  542.   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
  543.   *         This parameter can be:
  544.   *            @arg RTC_FLAG_ALRAF
  545.   *            @arg RTC_FLAG_ALRAWF
  546.   * @retval None
  547.   */
  548. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
  549.  
  550. /**
  551.   * @brief  Clear the RTC Alarm's pending flags.
  552.   * @param  __HANDLE__ specifies the RTC handle.
  553.   * @param  __FLAG__ specifies the RTC Alarm Flag sources to clear.
  554.   *         This parameter can be:
  555.   *            @arg RTC_FLAG_ALRAF
  556.   * @retval None
  557.   */
  558. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)   ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  559.  
  560. /**
  561.   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
  562.   * @retval None
  563.   */
  564. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
  565.  
  566. /**
  567.   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
  568.   * @retval None
  569.   */
  570. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  571.  
  572. /**
  573.   * @brief  Enable event on the RTC Alarm associated Exti line.
  574.   * @retval None.
  575.   */
  576. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
  577.  
  578. /**
  579.   * @brief  Disable event on the RTC Alarm associated Exti line.
  580.   * @retval None.
  581.   */
  582. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  583.  
  584. /**
  585.   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.
  586.   * @retval None.
  587.   */
  588. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  589.  
  590. /**
  591.   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.
  592.   * @retval None.
  593.   */
  594. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  595.  
  596. /**
  597.   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.
  598.   * @retval None.
  599.   */
  600. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  601.  
  602. /**
  603.   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.
  604.   * @retval None.
  605.   */
  606. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  607.  
  608. /**
  609.   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  610.   * @retval None.
  611.   */
  612. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();
  613.  
  614. /**
  615.   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  616.   * @retval None.
  617.   */
  618. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();
  619.  
  620. /**
  621.   * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  622.   * @retval Line Status.
  623.   */
  624. #define __HAL_RTC_ALARM_EXTI_GET_FLAG()              (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
  625.  
  626. /**
  627.   * @brief Clear the RTC Alarm associated Exti line flag.
  628.   * @retval None.
  629.   */
  630. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG()            (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
  631.  
  632. /**
  633.   * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  634.   * @retval None.
  635.   */
  636. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT()         (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
  637. /**
  638.   * @}
  639.   */
  640.  
  641. /* Include RTC HAL Extended module */
  642. #include "stm32f0xx_hal_rtc_ex.h"
  643.  
  644. /* Exported functions --------------------------------------------------------*/
  645. /** @defgroup RTC_Exported_Functions RTC Exported Functions
  646.   * @{
  647.   */
  648.  
  649. /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
  650.   * @{
  651.   */
  652.  
  653. /* Initialization and de-initialization functions  ****************************/
  654. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  655. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  656. void              HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  657. void              HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  658.  
  659. /* Callbacks Register/UnRegister functions  ***********************************/
  660. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  661. HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
  662. HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
  663. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  664. /**
  665.   * @}
  666.   */
  667.  
  668. /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
  669.   * @{
  670.   */
  671.  
  672. /* RTC Time and Date functions ************************************************/
  673. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  674. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  675. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  676. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  677. /**
  678.   * @}
  679.   */
  680.  
  681. /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
  682.   * @{
  683.   */
  684. /* RTC Alarm functions ********************************************************/
  685. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  686. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  687. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  688. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  689. void              HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  690. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  691. void              HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  692. /**
  693.   * @}
  694.   */
  695.  
  696. /** @defgroup  RTC_Exported_Functions_Group4 Peripheral Control functions
  697.   * @{
  698.   */
  699. /* Peripheral Control functions ***********************************************/
  700. HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
  701. /**
  702.   * @}
  703.   */
  704.  
  705. /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
  706.   * @{
  707.   */
  708. /* Peripheral State functions *************************************************/
  709. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  710. /**
  711.   * @}
  712.   */
  713.  
  714. /**
  715.   * @}
  716.   */
  717.  
  718. /* Private types -------------------------------------------------------------*/
  719. /* Private variables ---------------------------------------------------------*/
  720. /* Private constants ---------------------------------------------------------*/
  721. /** @defgroup RTC_Private_Constants RTC Private Constants
  722.   * @{
  723.   */
  724. /* Masks Definition */
  725. #define RTC_TR_RESERVED_MASK    0x007F7F7FU
  726. #define RTC_DR_RESERVED_MASK    0x00FFFF3FU
  727. #define RTC_INIT_MASK           0xFFFFFFFFU
  728. #define RTC_RSF_MASK            0xFFFFFF5FU
  729. #define RTC_FLAGS_MASK          ((uint32_t) (RTC_FLAG_RECALPF | RTC_FLAG_TAMP3F | RTC_FLAG_TAMP2F | \
  730.                                              RTC_FLAG_TAMP1F| RTC_FLAG_TSOVF | RTC_FLAG_TSF       | \
  731.                                              RTC_FLAG_WUTF  | RTC_FLAG_ALRAF      | \
  732.                                              RTC_FLAG_INITF | RTC_FLAG_RSF | RTC_FLAG_INITS       | \
  733.                                              RTC_FLAG_SHPF | RTC_FLAG_WUTWF | RTC_FLAG_ALRAWF))
  734.  
  735. #define RTC_TIMEOUT_VALUE       1000U
  736.  
  737. #define RTC_EXTI_LINE_ALARM_EVENT             ((uint32_t)EXTI_IMR_MR17)  /*!< External interrupt line 17 Connected to the RTC Alarm event */
  738. /**
  739.   * @}
  740.   */
  741.  
  742. /* Private macros ------------------------------------------------------------*/
  743. /** @defgroup RTC_Private_Macros RTC Private Macros
  744.   * @{
  745.   */
  746.  
  747. /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
  748.   * @{
  749.   */
  750. #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
  751.                                         ((FORMAT) == RTC_HOURFORMAT_24))
  752.  
  753. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  754.                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
  755. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  756.                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  757. #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0U) && ((HOUR) <= 12U))
  758. #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23U)
  759. #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= 0x7FU)
  760. #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= 0x7FFFU)
  761. #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59U)
  762. #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59U)
  763.  
  764. #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || \
  765.                                   ((PM) == RTC_HOURFORMAT12_PM))
  766.  
  767. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  768.                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  769.                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  770. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  771.                                            ((OPERATION) == RTC_STOREOPERATION_SET))
  772. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
  773. #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99U)
  774. #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1U) && ((MONTH) <= 12U))
  775. #define IS_RTC_DATE(DATE)              (((DATE) >= 1U) && ((DATE) <= 31U))
  776. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
  777.                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
  778.                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  779.                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
  780.                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
  781.                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
  782.                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  783. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
  784. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
  785.                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
  786.                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  787.                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
  788.                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
  789.                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
  790.                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  791. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  792.                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  793. #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
  794. #define IS_RTC_ALARM(ALARM)      ((ALARM) == RTC_ALARM_A)
  795. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
  796.  
  797. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)   (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
  798.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
  799.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
  800.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
  801.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
  802.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
  803.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
  804.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
  805.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
  806.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
  807.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
  808.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
  809.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
  810.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
  811.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
  812.                                               ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
  813. /**
  814.   * @}
  815.   */
  816.  
  817. /**
  818.   * @}
  819.   */
  820.  
  821. /* Private functions ---------------------------------------------------------*/
  822. /** @defgroup RTC_Private_Functions RTC Private Functions
  823.   * @{
  824.   */
  825. HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
  826. uint8_t            RTC_ByteToBcd2(uint8_t Value);
  827. uint8_t            RTC_Bcd2ToByte(uint8_t Value);
  828. /**
  829.   * @}
  830.   */
  831.  
  832. /**
  833.   * @}
  834.   */
  835.  
  836. /**
  837.   * @}
  838.   */
  839.  
  840. #ifdef __cplusplus
  841. }
  842. #endif
  843.  
  844. #endif /* __STM32F0xx_HAL_RTC_H */
  845.  
  846. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  847.  
  848.