M480 BSP  V3.05.001
The Board Support Package for M480 Series
rtc.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __RTC_H__
10 #define __RTC_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* RTC Initial Keyword Constant Definitions */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define RTC_INIT_KEY 0xA5EB1357UL
33 #define RTC_WRITE_KEY 0x0000A965UL
35 /*---------------------------------------------------------------------------------------------------------*/
36 /* RTC Time Attribute Constant Definitions */
37 /*---------------------------------------------------------------------------------------------------------*/
38 #define RTC_CLOCK_12 0UL
39 #define RTC_CLOCK_24 1UL
40 #define RTC_AM 1UL
41 #define RTC_PM 2UL
43 /*---------------------------------------------------------------------------------------------------------*/
44 /* RTC Tick Period Constant Definitions */
45 /*---------------------------------------------------------------------------------------------------------*/
46 #define RTC_TICK_1_SEC 0x0UL
47 #define RTC_TICK_1_2_SEC 0x1UL
48 #define RTC_TICK_1_4_SEC 0x2UL
49 #define RTC_TICK_1_8_SEC 0x3UL
50 #define RTC_TICK_1_16_SEC 0x4UL
51 #define RTC_TICK_1_32_SEC 0x5UL
52 #define RTC_TICK_1_64_SEC 0x6UL
53 #define RTC_TICK_1_128_SEC 0x7UL
55 /*---------------------------------------------------------------------------------------------------------*/
56 /* RTC Day of Week Constant Definitions */
57 /*---------------------------------------------------------------------------------------------------------*/
58 #define RTC_SUNDAY 0x0UL
59 #define RTC_MONDAY 0x1UL
60 #define RTC_TUESDAY 0x2UL
61 #define RTC_WEDNESDAY 0x3UL
62 #define RTC_THURSDAY 0x4UL
63 #define RTC_FRIDAY 0x5UL
64 #define RTC_SATURDAY 0x6UL
66 /*---------------------------------------------------------------------------------------------------------*/
67 /* RTC Miscellaneous Constant Definitions */
68 /*---------------------------------------------------------------------------------------------------------*/
69 #define RTC_WAIT_COUNT 0xFFFFFFFFUL
70 #define RTC_YEAR2000 2000UL
71 #define RTC_FCR_REFERENCE 32761UL
74 #define RTC_TAMPER0_SELECT (0x1ul << 0)
75 #define RTC_TAMPER1_SELECT (0x1ul << 1)
76 #define RTC_TAMPER2_SELECT (0x1ul << 2)
77 #define RTC_TAMPER3_SELECT (0x1ul << 3)
78 #define RTC_TAMPER4_SELECT (0x1ul << 4)
79 #define RTC_TAMPER5_SELECT (0x1ul << 5)
80 #define MAX_TAMPER_PIN_NUM 6ul
82 #define RTC_TAMPER_HIGH_LEVEL_DETECT 1ul
83 #define RTC_TAMPER_LOW_LEVEL_DETECT 0ul
85 #define RTC_TAMPER_DEBOUNCE_ENABLE 1ul
86 #define RTC_TAMPER_DEBOUNCE_DISABLE 0ul
88 #define RTC_PAIR0_SELECT (0x1ul << 0)
89 #define RTC_PAIR1_SELECT (0x1ul << 1)
90 #define RTC_PAIR2_SELECT (0x1ul << 2)
91 #define MAX_PAIR_NUM 3ul
93 #define RTC_2POW10_CLK (0x0 << RTC_TAMPCTL_DYNRATE_Pos)
94 #define RTC_2POW11_CLK (0x1 << RTC_TAMPCTL_DYNRATE_Pos)
95 #define RTC_2POW12_CLK (0x2 << RTC_TAMPCTL_DYNRATE_Pos)
96 #define RTC_2POW13_CLK (0x3 << RTC_TAMPCTL_DYNRATE_Pos)
97 #define RTC_2POW14_CLK (0x4 << RTC_TAMPCTL_DYNRATE_Pos)
98 #define RTC_2POW15_CLK (0x5 << RTC_TAMPCTL_DYNRATE_Pos)
99 #define RTC_2POW16_CLK (0x6 << RTC_TAMPCTL_DYNRATE_Pos)
100 #define RTC_2POW17_CLK (0x7 << RTC_TAMPCTL_DYNRATE_Pos)
102 #define REF_RANDOM_PATTERN 0x0
103 #define REF_PREVIOUS_PATTERN 0x1
104 #define REF_SEED 0x3
106  /* end of group RTC_EXPORTED_CONSTANTS */
107 
108 
115 typedef struct
116 {
117  uint32_t u32Year;
118  uint32_t u32Month;
119  uint32_t u32Day;
120  uint32_t u32DayOfWeek;
121  uint32_t u32Hour;
122  uint32_t u32Minute;
123  uint32_t u32Second;
124  uint32_t u32TimeScale;
125  uint32_t u32AmPm;
127  /* end of group RTC_EXPORTED_STRUCTS */
129 
130 
146 #define RTC_IS_LEAP_YEAR() (RTC->LEAPYEAR & RTC_LEAPYEAR_LEAPYEAR_Msk ? 1:0)
147 
158 #define RTC_CLEAR_ALARM_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_ALMIF_Msk)
159 
170 #define RTC_CLEAR_TICK_INT_FLAG() (RTC->INTSTS = RTC_INTSTS_TICKIF_Msk)
171 
188 #define RTC_CLEAR_TAMPER_INT_FLAG(u32TamperFlag) (RTC->INTSTS = (u32TamperFlag))
189 
201 #define RTC_GET_ALARM_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_ALMIF_Msk)? 1:0)
202 
214 #define RTC_GET_TICK_INT_FLAG() ((RTC->INTSTS & RTC_INTSTS_TICKIF_Msk)? 1:0)
215 
227 #define RTC_GET_TAMPER_INT_FLAG() ((RTC->INTSTS & (0x3F00))? 1:0)
228 
244 #define RTC_GET_TAMPER_INT_STATUS() ((RTC->INTSTS & (0x3F00)))
245 
258 #define RTC_READ_SPARE_REGISTER(u32RegNum) (RTC->SPR[(u32RegNum)])
259 
273 #define RTC_WRITE_SPARE_REGISTER(u32RegNum, u32RegValue) (RTC->SPR[(u32RegNum)] = (u32RegValue))
274 
275 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
276 __STATIC_INLINE void RTC_WaitAccessEnable(void);
277 
287 __STATIC_INLINE void RTC_WaitAccessEnable(void)
288 {
289  while((RTC->RWEN & RTC_RWEN_RTCBUSY_Msk) == RTC_RWEN_RTCBUSY_Msk)
290  {
291  }
292 
293  if(!(SYS->CSERVER & 0x1))
294  {
295  /* To wait RWENF bit is cleared and enable RWENF bit (Access Enable bit) again */
296  RTC->RWEN = RTC_WRITE_KEY;
297  }
298 
299  /* To wait RWENF bit is set and user can access the protected-register of RTC from now on */
300  while((RTC->RWEN & RTC_RWEN_RWENF_Msk) == (uint32_t)0x0)
301  {
302  }
303 }
304 
305 void RTC_Open(S_RTC_TIME_DATA_T *sPt);
306 void RTC_Close(void);
307 void RTC_32KCalibration(int32_t i32FrequencyX10000);
312 void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
313 void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
314 void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day);
315 void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
316 void RTC_SetAlarmDateMask(uint8_t u8IsTenYMsk, uint8_t u8IsYMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenDMsk, uint8_t u8IsDMsk);
317 void RTC_SetAlarmTimeMask(uint8_t u8IsTenHMsk, uint8_t u8IsHMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenSMsk, uint8_t u8IsSMsk);
318 uint32_t RTC_GetDayOfWeek(void);
319 void RTC_SetTickPeriod(uint32_t u32TickSelection);
320 void RTC_EnableInt(uint32_t u32IntFlagMask);
321 void RTC_DisableInt(uint32_t u32IntFlagMask);
322 void RTC_EnableSpareAccess(void);
323 void RTC_DisableSpareRegister(void);
324 void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn);
325 void RTC_StaticTamperDisable(uint32_t u32TamperSelect);
326 void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source);
327 void RTC_DynamicTamperDisable(uint32_t u32PairSel);
328 void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed);
329  /* end of group RTC_EXPORTED_FUNCTIONS */
331  /* end of group RTC_Driver */
333  /* end of group Standard_Driver */
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 #endif /* __RTC_H__ */
341 
342 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
void RTC_Open(S_RTC_TIME_DATA_T *sPt)
Initialize RTC module and start counting.
Definition: rtc.c:66
uint32_t u32Hour
Definition: rtc.h:121
void RTC_EnableInt(uint32_t u32IntFlagMask)
Enable RTC Interrupt.
Definition: rtc.c:769
void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
Update RTC Current Time.
Definition: rtc.c:547
void RTC_DisableSpareRegister(void)
Disable Spare Register.
Definition: rtc.c:825
void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source)
Dynamic Tamper Detect.
Definition: rtc.c:943
void RTC_SetAlarmTimeMask(uint8_t u8IsTenHMsk, uint8_t u8IsHMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenSMsk, uint8_t u8IsSMsk)
Set RTC Alarm Time Mask Function.
Definition: rtc.c:696
uint32_t RTC_GetDayOfWeek(void)
Get Day of the Week.
Definition: rtc.c:722
#define SYS
Definition: M480.h:367
uint32_t u32Year
Definition: rtc.h:117
#define RTC_RWEN_RTCBUSY_Msk
Definition: rtc_reg.h:1712
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Update Current RTC Date and Time.
Definition: rtc.c:365
void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn)
Static Tamper Detect.
Definition: rtc.c:855
#define RTC_RWEN_RWENF_Msk
Definition: rtc_reg.h:1709
__STATIC_INLINE void RTC_WaitAccessEnable(void)
Wait RTC Access Enable.
Definition: rtc.h:287
void RTC_SetAlarmDateMask(uint8_t u8IsTenYMsk, uint8_t u8IsYMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenDMsk, uint8_t u8IsDMsk)
Set RTC Alarm Date Mask Function.
Definition: rtc.c:671
void RTC_Close(void)
Disable RTC Clock.
Definition: rtc.c:97
void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed)
Config dynamic tamper.
Definition: rtc.c:1072
uint32_t u32Minute
Definition: rtc.h:122
uint32_t u32AmPm
Definition: rtc.h:125
void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
Update RTC Current Date.
Definition: rtc.c:514
#define RTC_WRITE_KEY
Definition: rtc.h:33
void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Update RTC Alarm Date and Time.
Definition: rtc.c:446
void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm)
Update RTC Alarm Time.
Definition: rtc.c:622
uint32_t u32Day
Definition: rtc.h:119
void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
Update RTC Alarm Date.
Definition: rtc.c:592
void RTC_EnableSpareAccess(void)
Enable Spare Registers Access.
Definition: rtc.c:809
uint32_t u32DayOfWeek
Definition: rtc.h:120
#define RTC
Definition: M480.h:400
void RTC_SetTickPeriod(uint32_t u32TickSelection)
Set RTC Tick Period Time.
Definition: rtc.c:745
uint32_t u32Month
Definition: rtc.h:118
uint32_t u32Second
Definition: rtc.h:123
void RTC_DynamicTamperDisable(uint32_t u32PairSel)
Dynamic Tamper Disable.
Definition: rtc.c:1008
void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Get RTC Alarm Date and Time.
Definition: rtc.c:265
void RTC_32KCalibration(int32_t i32FrequencyX10000)
Set Frequency Compensation Data.
Definition: rtc.c:110
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Get Current RTC Date and Time.
Definition: rtc.c:170
uint32_t u32TimeScale
Definition: rtc.h:124
void RTC_StaticTamperDisable(uint32_t u32TamperSelect)
Static Tamper Disable.
Definition: rtc.c:896
void RTC_DisableInt(uint32_t u32IntFlagMask)
Disable RTC Interrupt.
Definition: rtc.c:792