1 #ifndef __SWM341_RTC_H__ 2 #define __SWM341_RTC_H__ 3 4 5 #define RTC_CLKSRC_LRC32K 0 6 #define RTC_CLKSRC_XTAL32K 1 7 8 #define RTC_SUN 0x01 9 #define RTC_MON 0x02 10 #define RTC_TUE 0x04 11 #define RTC_WED 0x08 12 #define RTC_THU 0x10 13 #define RTC_FRI 0x20 14 #define RTC_SAT 0x40 15 16 17 typedef struct { 18 uint8_t clksrc; //RTC_CLKSRC_RC32K、RTC_CLKSRC_XTAL32K 19 uint16_t Year; 20 uint8_t Month; //取值1--12 21 uint8_t Date; //取值1--31 22 uint8_t Hour; //取值0--23 23 uint8_t Minute; //取值0--59 24 uint8_t Second; //取值0--59 25 uint8_t SecondIEn; 26 uint8_t MinuteIEn; 27 } RTC_InitStructure; 28 29 typedef struct { 30 uint8_t Days; //RTC_SUN、RTC_MON、RTC_TUE、RTC_WED、RTC_THU、RTC_FRI、RTC_SAT及其或运算组合 31 uint8_t Hour; 32 uint8_t Minute; 33 uint8_t Second; 34 uint8_t AlarmIEn; 35 } RTC_AlarmStructure; 36 37 typedef struct { 38 uint16_t Year; 39 uint8_t Month; 40 uint8_t Date; 41 uint8_t Day; //RTC_SUN、RTC_MON、RTC_TUE、RTC_WED、RTC_THU、RTC_FRI、RTC_SAT 42 uint8_t Hour; 43 uint8_t Minute; 44 uint8_t Second; 45 } RTC_DateTime; 46 47 48 /* Interrupt Type */ 49 #define RTC_IT_SECOND (1 << 0) //Second Interrupt 50 #define RTC_IT_MINUTE (1 << 1) 51 #define RTC_IT_HOUR (1 << 2) 52 #define RTC_IT_DATE (1 << 3) 53 #define RTC_IT_ALARM (1 << 4) 54 #define RTC_IT_SECOND_DIV2 (1 << 6) //1/2 Second Interrupt 55 #define RTC_IT_SECOND_DIV4 (1 << 7) //1/4 Second Interrupt 56 57 58 59 void RTC_Init(RTC_TypeDef * RTCx, RTC_InitStructure * initStruct); 60 void RTC_Start(RTC_TypeDef * RTCx); 61 void RTC_Stop(RTC_TypeDef * RTCx); 62 63 void RTC_GetDateTime(RTC_TypeDef * RTCx, RTC_DateTime * dateTime); 64 65 void RTC_AlarmSetup(RTC_TypeDef * RTCx, RTC_AlarmStructure * alarmStruct); 66 67 68 void RTC_INTEn(RTC_TypeDef * RTCx, uint32_t it); 69 void RTC_INTDis(RTC_TypeDef * RTCx, uint32_t it); 70 void RTC_INTClr(RTC_TypeDef * RTCx, uint32_t it); 71 uint32_t RTC_INTStat(RTC_TypeDef * RTCx, uint32_t it); 72 73 #endif //__SWM341_RTC_H__ 74