M480 BSP V3.05.005
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
13extern "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 /* end of group RTC_EXPORTED_CONSTANTS */
107
108
115typedef 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 uint32_t u32TimeOutCount = SystemCoreClock; // 1 second timeout
290 uint32_t i = 0;
291
293 {
294 i++;
295 if(i > u32TimeOutCount) break;
296 }
297
298 if(!(SYS->CSERVER & 0x1))
299 {
300 /* To wait RWENF bit is cleared and enable RWENF bit (Access Enable bit) again */
301 RTC->RWEN = RTC_WRITE_KEY;
302 }
303
304 /* To wait RWENF bit is set and user can access the protected-register of RTC from now on */
305 while((RTC->RWEN & RTC_RWEN_RWENF_Msk) == (uint32_t)0x0)
306 {
307 i++;
308 if(i > u32TimeOutCount) break;
309 }
310}
311
312int32_t RTC_Open(S_RTC_TIME_DATA_T *sPt);
313void RTC_Close(void);
314void RTC_32KCalibration(int32_t i32FrequencyX10000);
319void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek);
320void RTC_SetTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
321void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day);
322void RTC_SetAlarmTime(uint32_t u32Hour, uint32_t u32Minute, uint32_t u32Second, uint32_t u32TimeMode, uint32_t u32AmPm);
323void RTC_SetAlarmDateMask(uint8_t u8IsTenYMsk, uint8_t u8IsYMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenDMsk, uint8_t u8IsDMsk);
324void RTC_SetAlarmTimeMask(uint8_t u8IsTenHMsk, uint8_t u8IsHMsk, uint8_t u8IsTenMMsk, uint8_t u8IsMMsk, uint8_t u8IsTenSMsk, uint8_t u8IsSMsk);
325uint32_t RTC_GetDayOfWeek(void);
326void RTC_SetTickPeriod(uint32_t u32TickSelection);
327void RTC_EnableInt(uint32_t u32IntFlagMask);
328void RTC_DisableInt(uint32_t u32IntFlagMask);
329void RTC_EnableSpareAccess(void);
330void RTC_DisableSpareRegister(void);
331void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn);
332void RTC_StaticTamperDisable(uint32_t u32TamperSelect);
333void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source);
334void RTC_DynamicTamperDisable(uint32_t u32PairSel);
335void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed);
336 /* end of group RTC_EXPORTED_FUNCTIONS */
338 /* end of group RTC_Driver */
340 /* end of group Standard_Driver */
342
343#ifdef __cplusplus
344}
345#endif
346
347#endif /* __RTC_H__ */
348
349/*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
#define RTC
Definition: M480.h:400
#define SYS
Definition: M480.h:367
#define RTC_RWEN_RTCBUSY_Msk
Definition: rtc_reg.h:1712
#define RTC_RWEN_RWENF_Msk
Definition: rtc_reg.h:1709
#define RTC_WRITE_KEY
Definition: rtc.h:33
void RTC_EnableInt(uint32_t u32IntFlagMask)
Enable RTC Interrupt.
Definition: rtc.c:775
void RTC_32KCalibration(int32_t i32FrequencyX10000)
Set Frequency Compensation Data.
Definition: rtc.c:116
void RTC_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source)
Dynamic Tamper Detect.
Definition: rtc.c:949
uint32_t RTC_GetDayOfWeek(void)
Get Day of the Week.
Definition: rtc.c:728
void RTC_SetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Update Current RTC Date and Time.
Definition: rtc.c:371
void RTC_StaticTamperDisable(uint32_t u32TamperSelect)
Static Tamper Disable.
Definition: rtc.c:902
void RTC_DynamicTamperDisable(uint32_t u32PairSel)
Dynamic Tamper Disable.
Definition: rtc.c:1014
uint32_t u32Month
Definition: rtc.h:118
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:702
uint32_t u32AmPm
Definition: rtc.h:125
void RTC_GetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Get RTC Alarm Date and Time.
Definition: rtc.c:271
void RTC_SetAlarmDateAndTime(S_RTC_TIME_DATA_T *sPt)
Update RTC Alarm Date and Time.
Definition: rtc.c:452
uint32_t u32Hour
Definition: rtc.h:121
void RTC_EnableSpareAccess(void)
Enable Spare Registers Access.
Definition: rtc.c:815
int32_t RTC_Open(S_RTC_TIME_DATA_T *sPt)
Initialize RTC module and start counting.
Definition: rtc.c:67
void RTC_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn)
Static Tamper Detect.
Definition: rtc.c:861
void RTC_SetDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day, uint32_t u32DayOfWeek)
Update RTC Current Date.
Definition: rtc.c:520
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:677
void RTC_Close(void)
Disable RTC Clock.
Definition: rtc.c:103
uint32_t u32Minute
Definition: rtc.h:122
__STATIC_INLINE void RTC_WaitAccessEnable(void)
Wait RTC Access Enable.
Definition: rtc.h:287
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:553
void RTC_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed)
Config dynamic tamper.
Definition: rtc.c:1078
uint32_t u32Day
Definition: rtc.h:119
uint32_t u32DayOfWeek
Definition: rtc.h:120
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:628
void RTC_DisableInt(uint32_t u32IntFlagMask)
Disable RTC Interrupt.
Definition: rtc.c:798
uint32_t u32Year
Definition: rtc.h:117
void RTC_DisableSpareRegister(void)
Disable Spare Register.
Definition: rtc.c:831
void RTC_SetTickPeriod(uint32_t u32TickSelection)
Set RTC Tick Period Time.
Definition: rtc.c:751
void RTC_SetAlarmDate(uint32_t u32Year, uint32_t u32Month, uint32_t u32Day)
Update RTC Alarm Date.
Definition: rtc.c:598
uint32_t u32Second
Definition: rtc.h:123
uint32_t u32TimeScale
Definition: rtc.h:124
void RTC_GetDateAndTime(S_RTC_TIME_DATA_T *sPt)
Get Current RTC Date and Time.
Definition: rtc.c:176
uint32_t SystemCoreClock
Definition: system_M480.c:21