WB32L003 Standard Peripherals Firmware Library

wb32l003_rtc.h
浏览该文件的文档.
1
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __WB32L003_RTC_H
12 #define __WB32L003_RTC_H
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /* Includes ------------------------------------------------------------------*/
19 #include "wb32l003.h"
20
29 /* Exported types ------------------------------------------------------------*/
30
34 typedef struct
35 {
36 uint8_t RTC_Hours;
41 uint8_t RTC_Minutes;
44 uint8_t RTC_Seconds;
47 uint8_t RTC_H12;
49 } RTC_TimeTypeDef;
50
54 typedef struct
55 {
56 uint32_t RTC_Year;
59 uint8_t RTC_Month;
62 uint8_t RTC_Date;
65 uint8_t RTC_WeekDay;
68 uint8_t RTC_Cen;
70 } RTC_DateTypeDef;
71
75 typedef struct
76 {
77 uint32_t Year_Enable;
79 uint32_t Month_Enable;
81 uint32_t Date_Enable;
83 uint32_t WeekDay_Enable;
85 uint32_t Sen_Enable;
87 uint32_t Hours_Enable;
89 uint32_t Minutes_Enable;
91 uint32_t Seconds_Enable;
93 } RTC_AlarmEnableTypeDef;
94
98 typedef struct
99 {
100 RTC_AlarmEnableTypeDef Alarm_Enable;
101 RTC_DateTypeDef RTC_AlarmDate;
102 RTC_TimeTypeDef RTC_AlarmTime;
103 } RTC_AlarmTypeDef;
104
108 typedef struct
109 {
110 uint32_t RTC_HourFormat;
112 uint32_t RTC_CLKSEL;
113 uint32_t RTC_HSEDIV;
114 } RTC_InitTypeDef;
115
119 typedef struct
120 {
121 RTC_InitTypeDef InitStruct;
122 RTC_DateTypeDef DateToUpdate;
123 } RTC_HandleTypeDef;
124
125 /* Exported constants --------------------------------------------------------*/
126
134 #define RTC_HOURFORMAT_24 RTC_CR_FMT
135 #define RTC_HOURFORMAT_12 0x00000000U
136 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
137 ((FORMAT) == RTC_HOURFORMAT_24))
138
145 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0) && ((HOUR) <= 12))
146 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23)
147 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59)
148 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59)
149
156 #define RTC_H12_AM ((uint8_t)0x00)
157 #define RTC_H12_PM ((uint8_t)0x01)
158 #define IS_RTC_H12(PM) (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM))
159
166 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
167
174 /* Coded in BCD format */
175 #define RTC_Month_January ((uint8_t)0x01)
176 #define RTC_Month_February ((uint8_t)0x02)
177 #define RTC_Month_March ((uint8_t)0x03)
178 #define RTC_Month_April ((uint8_t)0x04)
179 #define RTC_Month_May ((uint8_t)0x05)
180 #define RTC_Month_June ((uint8_t)0x06)
181 #define RTC_Month_July ((uint8_t)0x07)
182 #define RTC_Month_August ((uint8_t)0x08)
183 #define RTC_Month_September ((uint8_t)0x09)
184 #define RTC_Month_October ((uint8_t)0x10)
185 #define RTC_Month_November ((uint8_t)0x11)
186 #define RTC_Month_December ((uint8_t)0x12)
187 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12))
188 #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31))
189 #define IS_RTC_CEN(CEN) ((CEN) <= 1)
190
197 #define RTC_Weekday_Monday ((uint8_t)0x00)
198 #define RTC_Weekday_Tuesday ((uint8_t)0x01)
199 #define RTC_Weekday_Wednesday ((uint8_t)0x02)
200 #define RTC_Weekday_Thursday ((uint8_t)0x03)
201 #define RTC_Weekday_Friday ((uint8_t)0x04)
202 #define RTC_Weekday_Saturday ((uint8_t)0x05)
203 #define RTC_Weekday_Sunday ((uint8_t)0x06)
204 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \
205 ((WEEKDAY) == RTC_Weekday_Tuesday) || \
206 ((WEEKDAY) == RTC_Weekday_Wednesday) || \
207 ((WEEKDAY) == RTC_Weekday_Thursday) || \
208 ((WEEKDAY) == RTC_Weekday_Friday) || \
209 ((WEEKDAY) == RTC_Weekday_Saturday) || \
210 ((WEEKDAY) == RTC_Weekday_Sunday))
211
218 #define RTC_Format_BIN ((uint32_t)0x000000000)
219 #define RTC_Format_BCD ((uint32_t)0x000000001)
220 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))
221
229 #define RTC_CLOCK_LSE (0x00UL << RTC_CLKCR_RTCCKSEL_Pos)
230 #define RTC_CLOCK_LSI (0x01UL << RTC_CLKCR_RTCCKSEL_Pos)
231 #define RTC_CLOCK_HSE (0x02UL << RTC_CLKCR_RTCCKSEL_Pos)
232 #define IS_RTC_CLK_SOURCE(CLK) (((CLK) == RTC_CLOCK_LSE) || \
233 ((CLK) == RTC_CLOCK_LSI) || \
234 ((CLK) == RTC_CLOCK_HSE))
235
242 #define IS_RTC_HSE_DIV(DIV) (((DIV) <= 0x7F))
243
250 #define RTC_IT_ALR2 ((uint32_t)0x00000020)
251 #define RTC_IT_ALR1 ((uint32_t)0x00000010)
252
253 #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFFFFFCF) == (uint32_t)RESET))
254 #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_ALR1) || ((IT) == RTC_IT_ALR1))
255 #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT)&0xFFFFFFCF) == (uint32_t)RESET))
256
263 #define RTC_ALARM_1 0x00U
264 #define RTC_ALARM_2 0x01U
265
272 #define RTC_CLK_SOURCE_LSE (0x00000000)
273 #define RTC_CLK_SOURCE_LSI (0x00010000)
274 #define RTC_CLK_SOURCE_HSEDIV (0x00020000)
275
282 #define RTC_ALARM2_CLOSE ((uint8_t)0x00)
283 #define RTC_ALARM2_1S ((uint8_t)0x01)
284 #define RTC_ALARM2_1P2S ((uint8_t)0x02)
285 #define RTC_ALARM2_1P4S ((uint8_t)0x03)
286 #define RTC_ALARM2_1P8S ((uint8_t)0x04)
287 #define RTC_ALARM2_1P16S ((uint8_t)0x05)
288 #define RTC_ALARM2_1P32S ((uint8_t)0x06)
289 #define RTC_ALARM2_1P64S ((uint8_t)0x07)
290 #define RTC_ALARM2_1P128S ((uint8_t)0x08)
291 #define RTC_ALARM2_10S ((uint8_t)0x09)
292 #define RTC_ALARM2_30S ((uint8_t)0x0A)
293 #define RTC_ALARM2_1M ((uint8_t)0x0B)
294 #define RTC_ALARM2_30M ((uint8_t)0x0C)
295 #define RTC_ALARM2_60M ((uint8_t)0x0D)
296 #define RTC_ALARM2_12H ((uint8_t)0x0E)
297 #define RTC_ALARM2_24H ((uint8_t)0x0F)
298 #define IS_RTC_ALARM_2_PERIOD(PERIOD) (((PERIOD) == RTC_ALARM2_CLOSE) || \
299 ((PERIOD) == RTC_ALARM2_1S) || \
300 ((PERIOD) == RTC_ALARM2_1P2S) || \
301 ((PERIOD) == RTC_ALARM2_1P4S) || \
302 ((PERIOD) == RTC_ALARM2_1P8S) || \
303 ((PERIOD) == RTC_ALARM2_1P16S) || \
304 ((PERIOD) == RTC_ALARM2_1P32S) || \
305 ((PERIOD) == RTC_ALARM2_1P64S) || \
306 ((PERIOD) == RTC_ALARM2_1P128S) || \
307 ((PERIOD) == RTC_ALARM2_10S) || \
308 ((PERIOD) == RTC_ALARM2_10S) || \
309 ((PERIOD) == RTC_ALARM2_1M) || \
310 ((PERIOD) == RTC_ALARM2_30M) || \
311 ((PERIOD) == RTC_ALARM2_60M) || \
312 ((PERIOD) == RTC_ALARM2_12H) || \
313 ((PERIOD) == RTC_ALARM2_24H))
314
321 #define RTC_FLAG_ALR2F RTC_ISR_ALM2_F /* Alarm 2 flag */
322 #define RTC_FLAG_ALR1F RTC_ISR_ALM1_F /* Alarm 1 flag */
323 #define RTC_FLAG_RSF RTC_ISR_RSF /* Registers Synchronized flag */
324 #define RTC_FLAG_WAITF RTC_ISR_WAITF /* Initialization mode flag */
325 #define RTC_FLAG_WAIT RTC_ISR_WAIT /* Shift operation pending flag */
326 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_ALR2F) || \
327 ((FLAG) == RTC_FLAG_ALR1F) || \
328 ((FLAG) == RTC_FLAG_RSF) || \
329 ((FLAG) == RTC_FLAG_WAITF) || \
330 ((FLAG) == RTC_FLAG_WAIT))
331
338 #define RTC_CalibPeriod_60sec ((uint32_t)0x00000000)
339 #define RTC_CalibPeriod_30sec ((uint32_t)0x00000100)
340 #define RTC_CalibPeriod_15sec ((uint32_t)0x00000200)
341 #define RTC_CalibPeriod_6sec ((uint32_t)0x00000300)
342 #define IS_RTC_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_CalibPeriod_60sec) || \
343 ((PERIOD) == RTC_CalibPeriod_30sec) || \
344 ((PERIOD) == RTC_CalibPeriod_15sec) || \
345 ((PERIOD) == RTC_CalibPeriod_6sec))
346
353 #define IS_RTC_CALIB_MINUS(VALUE) ((VALUE) <= 0x0000007F)
354
362 /* Exported macro ------------------------------------------------------------*/
363 /* Exported functions --------------------------------------------------------*/
364
365
366 /* Initialization and Configuration functions *********************************/
367 ErrorStatus RTC_Init(RTC_InitTypeDef *RTC_InitStruct);
368
369 void RTC_WriteProtectionCmd(FunctionalState NewState);
370 ErrorStatus RTC_EnterInitMode(void);
371 void RTC_ExitInitMode(void);
372 ErrorStatus RTC_WaitForSynchro(void);
373 void RTC_BypassShadowCmd(FunctionalState NewState);
374
375 /* Time and Date configuration functions **************************************/
376 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct);
377 void RTC_TimeStructInit(RTC_TimeTypeDef *RTC_TimeStruct);
378 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct);
379 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct);
380 void RTC_DateStructInit(RTC_DateTypeDef *RTC_DateStruct);
381 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct);
382
383 /* Alarms (Alarm 1 and Alarm 2) configuration functions **********************/
384 void RTC_SetAlarm1(uint32_t RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct);
385 void RTC_AlarmStructInit(RTC_AlarmTypeDef *RTC_AlarmStruct);
386 void RTC_Alarm1Cmd(FunctionalState NewState);
387 void RTC_GetAlarm1(uint32_t RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct);
388 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState);
389 void RTC_SetALARM2Period(uint32_t Period);
390
391 /* Output pin Configuration function ******************************************/
392 void RTC_1HZ_Config(FunctionalState NewState);
393
394 /* Digital Calibration configuration functions *********************************/
395 void RTC_CalibConfig(uint32_t RTC_CalibPeriod, uint32_t RTC_CalibMinusPulsesValue);
396
397 /* Interrupts and flags management functions **********************************/
398 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState);
399 ITStatus RTC_GetITStatus(uint32_t RTC_IT);
400 void RTC_ClearITPendingBit(uint32_t RTC_IT);
401
410 #ifdef __cplusplus
411 }
412 #endif
413
414 #endif /* __WB32L003_RTC_H */
RTC_DateTypeDef::RTC_Cen
uint8_t RTC_Cen
Definition: wb32l003_rtc.h:68
RTC_TimeTypeDef::RTC_Seconds
uint8_t RTC_Seconds
Definition: wb32l003_rtc.h:44
RTC_WaitForSynchro
ErrorStatus RTC_WaitForSynchro(void)
Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock.
Definition: wb32l003_rtc.c:204
RTC_AlarmEnableTypeDef::Seconds_Enable
uint32_t Seconds_Enable
Definition: wb32l003_rtc.h:91
RTC_AlarmEnableTypeDef::Sen_Enable
uint32_t Sen_Enable
Definition: wb32l003_rtc.h:85
RTC_InitTypeDef::RTC_HourFormat
uint32_t RTC_HourFormat
Definition: wb32l003_rtc.h:110
RTC_BypassShadowCmd
void RTC_BypassShadowCmd(FunctionalState NewState)
Enables or Disables the Bypass Shadow feature.
Definition: wb32l003_rtc.c:247
RTC_GetAlarm1
void RTC_GetAlarm1(uint32_t RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)
Get the RTC Alarm value and masks.
Definition: wb32l003_rtc.c:763
RTC_Init
ErrorStatus RTC_Init(RTC_InitTypeDef *RTC_InitStruct)
Initializes the RTC registers according to the specified parameters in RTC_InitStruct.
Definition: wb32l003_rtc.c:60
RTC_AlarmTypeDef::Alarm_Enable
RTC_AlarmEnableTypeDef Alarm_Enable
Definition: wb32l003_rtc.h:100
RTC_AlarmTypeDef::RTC_AlarmDate
RTC_DateTypeDef RTC_AlarmDate
Definition: wb32l003_rtc.h:101
RTC_ITConfig
void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
Enables or disables the specified RTC interrupts.
Definition: wb32l003_rtc.c:958
RTC_TimeTypeDef::RTC_H12
uint8_t RTC_H12
Definition: wb32l003_rtc.h:47
RTC_EnterInitMode
ErrorStatus RTC_EnterInitMode(void)
Enters the RTC Initialization mode.
Definition: wb32l003_rtc.c:143
RTC_DateTypeDef
RTC Date structure definition
Definition: wb32l003_rtc.h:54
RTC_DateTypeDef::RTC_Year
uint32_t RTC_Year
Definition: wb32l003_rtc.h:56
RTC_HandleTypeDef::InitStruct
RTC_InitTypeDef InitStruct
Definition: wb32l003_rtc.h:121
RTC_AlarmEnableTypeDef::Hours_Enable
uint32_t Hours_Enable
Definition: wb32l003_rtc.h:87
RTC_ExitInitMode
void RTC_ExitInitMode(void)
Exits the RTC Initialization mode.
Definition: wb32l003_rtc.c:188
RTC_AlarmEnableTypeDef::Date_Enable
uint32_t Date_Enable
Definition: wb32l003_rtc.h:81
RTC_DateTypeDef::RTC_Date
uint8_t RTC_Date
Definition: wb32l003_rtc.h:62
RTC_TimeTypeDef::RTC_Minutes
uint8_t RTC_Minutes
Definition: wb32l003_rtc.h:41
RTC_SetTime
ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
Set the RTC current time.
Definition: wb32l003_rtc.c:283
RTC_GetTime
void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
Get the RTC current Time.
Definition: wb32l003_rtc.c:405
RTC_DateTypeDef::RTC_WeekDay
uint8_t RTC_WeekDay
Definition: wb32l003_rtc.h:65
RTC_AlarmEnableTypeDef::Minutes_Enable
uint32_t Minutes_Enable
Definition: wb32l003_rtc.h:89
RTC_AlarmTypeDef::RTC_AlarmTime
RTC_TimeTypeDef RTC_AlarmTime
Definition: wb32l003_rtc.h:102
RTC_TimeTypeDef
RTC Time structure definition
Definition: wb32l003_rtc.h:34
RTC_AlarmEnableTypeDef::WeekDay_Enable
uint32_t WeekDay_Enable
Definition: wb32l003_rtc.h:83
RTC_AlarmEnableTypeDef::Year_Enable
uint32_t Year_Enable
Definition: wb32l003_rtc.h:77
RTC_SetAlarm1
void RTC_SetAlarm1(uint32_t RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)
Set the specified RTC Alarm1.
Definition: wb32l003_rtc.c:616
RTC_AlarmEnableTypeDef
RTC ALARM Enable structure definition
Definition: wb32l003_rtc.h:75
RTC_DateStructInit
void RTC_DateStructInit(RTC_DateTypeDef *RTC_DateStruct)
Fills each RTC_DateStruct member with its default value (Monday, January 01 xx00).
Definition: wb32l003_rtc.c:554
RTC_SetDate
ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct)
Set the RTC current date.
Definition: wb32l003_rtc.c:452
RTC_HandleTypeDef::DateToUpdate
RTC_DateTypeDef DateToUpdate
Definition: wb32l003_rtc.h:122
RTC_DateTypeDef::RTC_Month
uint8_t RTC_Month
Definition: wb32l003_rtc.h:59
RTC_1HZ_Config
void RTC_1HZ_Config(FunctionalState NewState)
Deactive the specified 1HZ out
Definition: wb32l003_rtc.c:870
RTC_Alarm1Cmd
void RTC_Alarm1Cmd(FunctionalState NewState)
Enables or disables the specified RTC Alarm.
Definition: wb32l003_rtc.c:817
RTC_CalibConfig
void RTC_CalibConfig(uint32_t RTC_CalibPeriod, uint32_t RTC_CalibMinusPulsesValue)
Configures the Calibration Settings.
Definition: wb32l003_rtc.c:898
RTC_SetALARM2Period
void RTC_SetALARM2Period(uint32_t Period)
Set the specified RTC Alarm2.
Definition: wb32l003_rtc.c:847
RTC_TimeStructInit
void RTC_TimeStructInit(RTC_TimeTypeDef *RTC_TimeStruct)
Fills each RTC_TimeStruct member with its default value (Time = 00h:00min:00sec).
Definition: wb32l003_rtc.c:386
RTC_HandleTypeDef
Time Handle Structure definition
Definition: wb32l003_rtc.h:119
RTC_GetDate
void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct)
Get the RTC current date.
Definition: wb32l003_rtc.c:574
RTC_ClearITPendingBit
void RTC_ClearITPendingBit(uint32_t RTC_IT)
Clears the RTC's interrupt pending bits.
Definition: wb32l003_rtc.c:990
RTC_WriteProtectionCmd
void RTC_WriteProtectionCmd(FunctionalState NewState)
Enables or disables the RTC registers write protection.
Definition: wb32l003_rtc.c:116
RTC_AlarmEnableTypeDef::Month_Enable
uint32_t Month_Enable
Definition: wb32l003_rtc.h:79
RTC_TimeTypeDef::RTC_Hours
uint8_t RTC_Hours
Definition: wb32l003_rtc.h:36
RTC_InitTypeDef
RTC Init structures definition
Definition: wb32l003_rtc.h:108
RTC_AlarmTypeDef
RTC Alarm structure definition
Definition: wb32l003_rtc.h:98