RTC
Overview
The Real-Time Clock (RTC) is an independent binary-coded decimal (BCD) timer/counter. It provides accurate date and time information with units of year, month, day, hour, minute, and second. The RTC uses internal OSC as clock source and continues operating as long as the supply voltage remains within working range, regardless of whether the device is in run mode or low-power mode.
Features
Manages time in seconds, minutes, hours (12/24-hour format), days, and years
Supports daylight saving time compensation
Provides digital calibration to compensate for fixed-direction deviations
Programmable alarm with interrupt capability, triggerable by any combination of time fields
Maskable interrupt/event types include:
Alarm
Day threshold
Wakeup timer
Register write protection mechanism
Supports low-power wakeup
Accuracy better than 2 seconds per day
Low-Power Operation
During sleep and deepsleep modes, the system periodically wakes the XTAL module (without system wakeup) to calibrate RTC clock source, ensuring RTC accuracy in low-power states.
RTC can wake the system through alarm interrupts and wakeup timer interrupts during sleep and deepsleep modes.
Power Supply
Implement a simple RTC_IO that continues timing based on original RTC time information after RTC circuit power loss. When RTC is repowered, software must reload the RTC_IO content into the RTC circuit.
The RTC_IO can be independently powered by VDH_RTC.
The RTC_IO cannot achieve the same accuracy level as the RTC circuit due to its uncalibrated clock source.
VDH_RTC is not brought out to a pin on all chips. Refer to the specific chip’s datasheet for availability.
It is powered by the system and has no independent power supply.
It is powered by the system and has no independent power supply.
It is powered by the system and has no independent power supply.
It is powered by the system and has no independent power supply.
It is powered by the system and has no independent power supply.
RTC circuit and its clock source are powered by VDH_RTC. The RTC can continue counting when the system is powered off or reset.
VDH_RTC is not available on all chip pins. Refer to the chip datasheet for specific implementation details.
It is powered by the system and has no independent power supply.
It is powered by the system and has no independent power supply.
Year Register Handling
The RTC registers store the following time information:
Year (starting from 1900)
Day (day of year)
Hour
Minute
Second
The real-time clock has no internal leap year detection and cannot perform automatic carry-over from day to year. This requires software handling. Software can set day thresholds based on leap year information, triggering an interrupt when the day count reaches the threshold.
Application Examples
The SDK provides two types of functional examples to help developers understand and use RTC features:
mbed Examples
Path:
{SDK}\example\peripheral\mbed\RTC\{demo}Demonstrates RTC control in mbed environment
Raw Examples
Path:
{SDK}\example\peripheral\raw\RTC\{demo}Demonstrates direct RTC control without abstraction layer
Brief description of raw examples:
raw_rtc demonstrates RTC time setting and retrieval;
raw_rtc_alarm demonstrates RTC alarm interrupt usage.
Note
Check the README.md file in each example directory for supported chips.
Raw API
RTC Exported Types
-
struct RTC_AlarmTypeDef
RTC Alarm Structure Definition.
Public Members
-
RTC_TimeTypeDef RTC_AlarmTime
Specifies the RTC Alarm Time members.
-
u32 RTC_AlarmMask
Specifies the RTC Alarm1 Masks(H:M:S). This parameter can be a value of RTC Alarm Mask 1
-
u32 RTC_Alarm2Mask
Specifies the RTC Alarm2 Masks Day. This parameter can be a value of RTC Alarm Mask 2
-
RTC_TimeTypeDef RTC_AlarmTime
-
struct RTC_InitTypeDef
RTC Init Structure Definition.
Public Members
-
u32 RTC_HourFormat
Specifies the RTC Hour Format. This parameter can be a value of RTC Hour Format
-
u32 RTC_AsynchPrediv
Specifies the RTC Asynchronous Predivider value. This parameter must be a value of RTC Asynchronous Predivider
-
u32 RTC_SynchPrediv
Specifies the RTC Synchronous Predivider value. This parameter must be a value of RTC Synchronous Predivider
-
u32 RTC_DayThreshold
Specifies the RTC Day Threshold value. This parameter must be a value of RTC Day Threshold
-
u32 RTC_HourFormat
-
struct RTC_TimeTypeDef
RTC Time Structure Definition.
Public Members
-
u16 RTC_Year
Year in binary format 16bits 1900~2155
-
u16 RTC_Days
Day in binary format 9bits 0~0x1FF
-
u8 RTC_Hours
Specifies the RTC Time Hour. This parameter must be set to a value in the 1-12 range if the RTC_HourFormat_12 is selected or 0-23 range if the RTC_HourFormat_24 is selected.
-
u8 RTC_Minutes
Specifies the RTC Time Minutes. This parameter must be set to a value in the 0-59 range.
-
u8 RTC_Seconds
Specifies the RTC Time Seconds. This parameter must be set to a value in the 0-59 range.
-
u16 RTC_Year
RTC_IO Exported Types
-
struct RTCIO_TimeInfo
Backed-up RTC time and power-off elapsed counter for post-power-on time restoration.
Public Members
-
u32 Bkup_Seconds
Backed-up seconds before power down (0-59).
-
u32 Bkup_Minutes
Backed-up minutes before power down (0-59).
-
u32 Bkup_Hours
Backed-up hours before power down, 24-hour format (0-23).
-
u32 Bkup_Days
Backed-up days before power down.
-
u32 Bkup_Year
Backed-up year before power down.
-
u32 Pwd_Counter
Counter elapsed during power-off period, unit: second.
-
u32 Bkup_Seconds
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
RTC Exported Constants
Leap Year Check
/* Check if the given year is a leap year. */
#define IS_LEAP_YEAR_CHECK do {\
if(((!(YEAR % 4)) && (YEAR % 100)) || (!(YEAR % 400))) { \
RET = 1; \
} else { \
RET = 0; \
} \
} while (0)
RTC AM PM
/* AM or 24-hour format indicator. */
#define RTC_H12_AM ((u8)0x00)
/* PM hour format indicator. */
#define RTC_H12_PM ((u8)0x01)
/* Check if RTC AM/PM value is valid. */
#define IS_RTC_H12_AMPM (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM))
RTC Alarm Mask 1
/* No alarm fields are masked. */
#define RTC_AlarmMask_None ((u32)0x00000000)
/* Alarm hours field is masked. */
#define RTC_AlarmMask_Hours ((u32)0x00800000)
/* Alarm minutes field is masked. */
#define RTC_AlarmMask_Minutes ((u32)0x00008000)
/* Alarm seconds field is masked. */
#define RTC_AlarmMask_Seconds ((u32)0x00000080)
/* All alarm time fields are masked. */
#define RTC_AlarmMask_All ((u32)0x00808080)
/* Check if alarm mask value is valid. */
#define IS_ALARM_MASK (((MASK) & 0x7F7F7F) == 0)
RTC Alarm Mask 2
/* No alarm2 day field is masked. */
#define RTC_Alarm2Mask_None ((u32)0x00000000)
/* Alarm2 day field is masked. */
#define RTC_Alarm2Mask_Days ((u32)0x00000200)
/* Check if alarm2 mask value is valid. */
#define IS_ALARM2_MASK (((MASK) & ~RTC_Alarm2Mask_Days) == 0)
RTC Asynchronous Predivider
/* Check if RTC asynchronous predivider value is valid. */
#define IS_RTC_ASYNCH_PREDIV ((PREDIV) <= 0x1FF)
RTC Base Year
/* RTC base year for year calculations. */
#define RTC_BASE_YEAR ((u16)1900)
RTC DayLight Saving Control
/* Subtract one hour for winter time change. */
#define RTC_DayLightSaving_SUB1H ((u32)0x00000002)
/* Add one hour for summer time change. */
#define RTC_DayLightSaving_ADD1H ((u32)0x00000001)
/* Check if RTC daylight saving value is valid. */
#define IS_RTC_DAYLIGHT_SAVING (((SAVE) == RTC_DayLightSaving_SUB1H) || \
((SAVE) == RTC_DayLightSaving_ADD1H))
/* Reset the daylight saving backup bit. */
#define RTC_StoreOperation_Reset ((u32)0x00000000)
/* Set the daylight saving backup bit. */
#define RTC_StoreOperation_Set ((u32)0x00000004)
/* Check if RTC store operation value is valid. */
#define IS_RTC_STORE_OPERATION (((OPERATION) == RTC_StoreOperation_Reset) || \
((OPERATION) == RTC_StoreOperation_Set))
RTC Day Threshold
/* Mask for RTC day threshold field. */
#define RTC_DAYTHRES_MSK ((u32)0xFF800000)
/* Check if RTC day threshold value is valid. */
#define IS_RTC_DAY_THRES ((DAYS) <= 0x1FF)
RTC Hour Format
/* 24-hour clock format. */
#define RTC_HourFormat_24 ((u32)0x00000000)
/* 12-hour AM/PM clock format. */
#define RTC_HourFormat_12 ((u32)0x00000080)
/* Check if RTC hour format value is valid. */
#define IS_RTC_HOUR_FORMAT (((FORMAT) == RTC_HourFormat_12) || \
((FORMAT) == RTC_HourFormat_24))
/* Check if RTC time day threshold value is valid. */
#define IS_RTC_TIME_DAY_THRES ((TIME_DAYS) <= 0x1FF)
RTC Input Parameter Format
/* Binary input parameter format. */
#define RTC_Format_BIN ((u32)0x000000000)
/* BCD input parameter format. */
#define RTC_Format_BCD ((u32)0x000000001)
/* Check if RTC format value is valid. */
#define IS_RTC_FORMAT (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))
RTC Output Control
/* Disable RTC output. */
#define RTC_Output_Disable ((u32)0x00000000)
/* Output alarm wakeup signal. */
#define RTC_Output_Alarm ((u32)0x00000020)
/* Output 1 Hz synchronous clock (clk_spre). */
#define RTC_Output_clkspre ((u32)0x00000040)
/* Output 256 Hz asynchronous clock (clk_apre). */
#define RTC_Output_clkapre ((u32)0x00000060)
/* Check if RTC output value is valid. */
#define IS_RTC_OUTPUT (((OUTPUT) == RTC_Output_Disable) || \
((OUTPUT) == RTC_Output_Alarm) || \
((OUTPUT) == RTC_Output_clkspre) || \
((OUTPUT) == RTC_Output_clkapre))
RTC Shift Control
/* Bit shift for alarm hour units field. */
#define RTC_SHIFT_ALR_HU 16
/* Bit shift for alarm minute units field. */
#define RTC_SHIFT_ALR_MNU 8
/* Bit shift for alarm AM/PM field. */
#define RTC_SHIFT_ALR_PM 22
/* Bit shift for time hour units field. */
#define RTC_SHIFT_HU 16
/* Bit shift for time minute units field. */
#define RTC_SHIFT_MNU 8
/* Bit shift for time AM/PM field. */
#define RTC_SHIFT_PM 22
RTC Smooth Calibration Control
/* Calibration period of 1 minute. */
#define RTC_CalibPeriod_1MIN ((u32)0x00000000)
/* Calibration period of 2 minutes. */
#define RTC_CalibPeriod_2MIN ((u32)0x00010000)
/* Calibration period of 3 minutes. */
#define RTC_CalibPeriod_3MIN ((u32)0x00020000)
/* Calibration period of 4 minutes. */
#define RTC_CalibPeriod_4MIN ((u32)0x00030000)
/* Calibration period of 5 minutes. */
#define RTC_CalibPeriod_5MIN ((u32)0x00040000)
/* Calibration period of 6 minutes. */
#define RTC_CalibPeriod_6MIN ((u32)0x00050000)
/* Calibration period of 7 minutes. */
#define RTC_CalibPeriod_7MIN ((u32)0x00060000)
/* Calibration period of 8 minutes. */
#define RTC_CalibPeriod_8MIN ((u32)0x00070000)
/* Check if RTC calibration period value is valid. */
#define IS_RTC_CALIB_PERIOD (((DCP) == RTC_CalibPeriod_1MIN) || \
((DCP) == RTC_CalibPeriod_2MIN) || \
((DCP) == RTC_CalibPeriod_3MIN) || \
((DCP) == RTC_CalibPeriod_4MIN) || \
((DCP) == RTC_CalibPeriod_5MIN) || \
((DCP) == RTC_CalibPeriod_6MIN) || \
((DCP) == RTC_CalibPeriod_7MIN) || \
((DCP) == RTC_CalibPeriod_8MIN))
/* Disable digital calibration. */
#define RTC_Calib_Disable ((u32)0x00000000)
/* Enable digital calibration. */
#define RTC_Calib_Enable ((u32)0x00008000)
/* Check if RTC calibration enable value is valid. */
#define IS_RTC_CALIB_ENABLE (((DCE) == RTC_Calib_Disable) || \
((DCE) == RTC_Calib_Enable))
/* Positive calibration sign (increase frequency). */
#define RTC_CalibSign_Positive ((u32)0x00000000)
/* Negative calibration sign (decrease frequency). */
#define RTC_CalibSign_Negative ((u32)0x00004000)
/* Check if RTC calibration sign value is valid. */
#define IS_RTC_CALIB_SIGN (((SIGN) == RTC_CalibSign_Positive) || \
((SIGN) == RTC_CalibSign_Negative))
/* Check if RTC calibration value is valid. */
#define IS_RTC_CALIB_VALUE ((VALUE) <= 0x7F)
RTC Synchronous Predivider
/* Check if RTC synchronous predivider value is valid. */
#define IS_RTC_SYNCH_PREDIV ((PREDIV) <= 0x1FF)
RTC TR Mask
/* Reserved bits mask for RTC_TR register. */
#define RTC_TR_RESERVED_MASK ((u32)0xFFFF7F7F)
RTC Time Definitions
/* Check if RTC 12-hour value is valid. */
#define IS_RTC_HOUR12 (((HOUR) > 0) && ((HOUR) <= 12))
/* Check if RTC 24-hour value is valid. */
#define IS_RTC_HOUR24 ((HOUR) <= 23)
/* Check if RTC minutes value is valid. */
#define IS_RTC_MINUTES ((MINUTES) <= 59)
/* Check if RTC seconds value is valid. */
#define IS_RTC_SECONDS ((SECONDS) <= 59)
RTC Timeout Control
/* Timeout for RTC initialization mode. */
#define INITMODE_TIMEOUT ((u32) 0x00010000)
/* Timeout for RTC synchronization. */
#define SYNCHRO_TIMEOUT ((u32) 0x00020000)
/* Timeout for recalibration pending flag. */
#define RECALPF_TIMEOUT ((u32) 0x00020000)
/* Timeout for alarm disable operation. */
#define ALARMDIS_TIMEOUT ((u32) 0x00020000)
/* Timeout for wakeup timer disable. */
#define WUTDIS_TIMEOUT ((u32) 0x00020000)
RTC Year Threshold
/* Check if RTC year threshold value is valid. */
#define IS_RTC_YEAR_THRES ((YEAR >= RTC_BASE_YEAR) && \
((YEAR - RTC_BASE_YEAR) <= 0xFF))
RTC_IO Exported Constants
RTC IO Work Mode
/* Shift mode disabled. */
#define MODE_SHIFT_DISABLE (0)
/* Shift mode enabled. */
#define MODE_SHIFT_ENABLE (1)
/* RTC start mode. */
#define MODE_RTC_START (2)
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
RTC IO RECV RVAL
/* Receive new reset value. */
#define RTCIO_RECV_RVAL_RST TRUE
/* Receive calibrated value. */
#define RTCIO_RECV_RVAL_CAL FALSE
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
RTC IO Time Convert
/* Step time value with carry propagation. */
#define TIME_STEP do {\
TIME_POST = (TIME_PRE + TIME_STEP_CNT) % MOD_NUM; \
TIME_STEP_CNT = (TIME_PRE + TIME_STEP_CNT) / MOD_NUM; \
} while (0)
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
RTC Exported Functions
-
void RTC_AlarmClear(void)
Clear alarm pending interrupt.
-
void RTC_AlarmCmd(u32 NewState)
Enable or disable the specified RTC Alarm.
- Parameters:
NewState – New state of the specified alarm. This parameter can be: ENABLE or DISABLE.
-
void RTC_AlarmStructInit(RTC_AlarmTypeDef *RTC_AlarmStruct)
Fill each RTC_AlarmStruct member with its default value (Time = 00d:00h:00mn:20sec / Date = 1st day of the month/Mask = all fields are masked except Alarm Seconds field).
- Parameters:
RTC_AlarmStruct – Pointer to a RTC_AlarmTypeDef structure which will be initialized.
-
u32 RTC_BypassShadowCmd(u32 NewState)
Enable or Disable the Bypass Shadow feature.
- Parameters:
NewState – New state of the Bypass Shadow feature. This parameter can be: ENABLE or DISABLE.
- Returns:
Status value:
1: success
0: fail
Note
When the Bypass Shadow is enabled the calendar value are taken directly from the Calendar counter.
-
void RTC_DayIntClear(void)
Clear day over threshold pending interrupt.
-
u32 RTC_DayIntCmd(u32 NewState)
Enable or disable the RTC day over threshold interrupt.
- Parameters:
NewState – New state of the RTC day over threshold interrupt. This parameter can be: ENABLE or DISABLE.
- Returns:
Status value:
1: success
0: fail
-
u32 RTC_DayLightSavingConfig(u32 RTC_DayLightSaving, u32 RTC_StoreOperation)
Add or substract one hour from the current time.
- Parameters:
RTC_DayLightSaving –
The value of hour adjustment. This parameter can be one of the following values:
RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
RTC_DayLightSaving_ADD1H: Add one hour (summer time)
RTC_StoreOperation –
Specifies the value to be written in the BCK bit in CR register to store the operation. This parameter can be one of the following values:
RTC_StoreOperation_Reset: BCK Bit Reset
RTC_StoreOperation_Set: BCK Bit Set
- Returns:
Status value:
1: success
0: fail
-
u32 RTC_DayThresGet(void)
Get the RTC day threshold value in RTC_CR register.
- Returns:
RTC day threshold value.
-
u32 RTC_DayThresSet(u32 DayThres)
Set the RTC day threshold.
- Parameters:
DayThres – Specifies the day threshold to be configured. This parameter can be a value of RTC Day Threshold.
- Returns:
Status value:
1: RTC day threshold is configured
0: RTC day threshold is not configured
-
void RTC_GetAlarm(u32 RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)
Get the RTC Alarm value and masks.
- Parameters:
RTC_Format –
Specifies the format of the output parameters. This parameter can be one of the following values:
RTC_Format_BIN: Binary data format
RTC_Format_BCD: BCD data format
RTC_AlarmStruct – Pointer to a RTC_AlarmTypeDef structure that will contains the output alarm configuration values.
-
u32 RTC_GetStoreOperation(void)
Return the RTC Day Light Saving stored operation.
- Returns:
RTC Day Light Saving stored operation.
RTC_StoreOperation_Reset
RTC_StoreOperation_Set
-
void RTC_GetTime(u32 RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
Get the RTC current Time.
- Parameters:
RTC_Format –
Specifies the format of the returned parameters. This parameter can be one of the following values:
RTC_Format_BIN: Binary data format
RTC_Format_BCD: BCD data format
RTC_TimeStruct – Pointer to a RTC_TimeTypeDef structure that will contain the returned current time configuration.
-
u32 RTC_GetWakeup(void)
Get the RTC Wakeup Timer value and masks.
- Returns:
The wakeup time value.
-
u32 RTC_Init(RTC_InitTypeDef *RTC_InitStruct)
Initialize the RTC registers according to the specified parameters in RTC_InitStruct.
- Parameters:
RTC_InitStruct – Pointer to a RTC_InitTypeDef structure that contains the configuration information for the RTC peripheral.
- Returns:
Status value:
1: RTC registers are initialized
0: RTC registers are not initialized
Note
The RTC Prescaler register is write protected and can be written in initialization mode only.
-
u32 RTC_OutputConfig(u32 RTC_Output)
Configure the RTC output.
- Parameters:
RTC_Output –
Specifies which signal will be routed to the RTC output. This parameter can be one of the following values:
RTC_Output_Disable: No output selected
RTC_Output_Alarm: signal of Alarm mapped to output
RTC_Output_clkspre: signal of clkspre mapped to output
RTC_Output_clkapre: signal of clkapre mapped to output
- Returns:
Status value:
1: success
0: fail
-
u32 RTC_SetAlarm(u32 RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)
Set the specified RTC Alarm.
- Parameters:
RTC_Format –
Specifies the format of the returned parameters. This parameter can be one of the following values:
RTC_Format_BIN: Binary data format
RTC_Format_BCD: BCD data format
RTC_AlarmStruct – Pointer to a RTC_AlarmTypeDef structure that contains the alarm configuration parameters.
- Returns:
Status value:
1: RTC Time Alarm is configured
0: RTC Time Alarm is not configured
Note
The Alarm register can only be written when the corresponding Alarm is disabled (Use RTC_AlarmCmd (DISABLE)).
-
u32 RTC_SetTime(u32 RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
Set the RTC current time.
- Parameters:
RTC_Format –
Specifies the format of the entered parameters. This parameter can be one of the following values:
RTC_Format_BIN: Binary data format
RTC_Format_BCD: BCD data format
RTC_TimeStruct – Pointer to a RTC_TimeTypeDef structure that contains the time configuration information for the RTC.
- Returns:
Status value:
1: RTC Time register is configured
0: RTC Time register is not configured
-
u32 RTC_SetTimeDayYear(u32 RTC_TimeDay, u32 RTC_TimeYear)
Set the RTC current time for day and year.
- Parameters:
RTC_TimeDay – Specifies the day to be set. Starts from 0.
RTC_TimeYear – Specifies the year to be set. Starts from 1900.
- Returns:
Status value:
1: RTC Time day and year are configured
0: RTC Time day and year are not configured
-
u32 RTC_SetWakeup(u32 RTC_WakeupRange)
Set the specified RTC Wakeup Timer.
- Parameters:
RTC_WakeupRange – Wakeup time to be configured. This parameter can be a value from 0x1 to 0x1FF.
- Returns:
Status value:
1: RTC WakeupTimer is configured
0: RTC WakeupTimer is not configured
Note
The Wakeup Timer register can only be written when the WakeupTimer is disabled (Use RTC_WakeupCmd (DISABLE)).
-
u32 RTC_SmoothCalibConfig(u32 CalibSign, u32 Value, u32 CalibPeriod, u32 Calib_Enable)
Configure the Coarse calibration parameters.
- Parameters:
CalibSign –
CalibSign specifies the sign of the coarse calibration value. This parameter can be one of the following values:
RTC_CalibSign_Positive: The value sign is positive
RTC_CalibSign_Negative: The value sign is negative
Value – Value of coarse calibration expressed in ppm (coded on 7 bits).
CalibPeriod –
Calibration period, Compensate DC clkapre cycles every (CALP+1) minutes (coded on 3 bits). This parameter can be one of the following values:
RTC_CalibPeriod_1MIN
RTC_CalibPeriod_2MIN
RTC_CalibPeriod_3MIN
RTC_CalibPeriod_4MIN
RTC_CalibPeriod_5MIN
RTC_CalibPeriod_6MIN
RTC_CalibPeriod_7MIN
RTC_CalibPeriod_8MIN
Calib_Enable – RTC_Calib_Disable or RTC_Calib_Enable .
- Returns:
Status value:
1: RTC Coarse calibration are initialized
0: RTC Coarse calibration are not initialized
-
void RTC_StructInit(RTC_InitTypeDef *RTC_InitStruct)
Fill each RTC_InitStruct member with its default value.
- Parameters:
RTC_InitStruct – Pointer to a RTC_InitTypeDef structure which will be initialized.
-
void RTC_TimeStructInit(RTC_TimeTypeDef *RTC_TimeStruct)
Fill each RTC_TimeStruct member with its default value (Time = 00d:00h:00min:00sec).
- Parameters:
RTC_TimeStruct – Pointer to a RTC_TimeTypeDef structure which will be initialized.
-
u32 RTC_WaitForWUTSynchro(void)
Wait until the RTC Wakeup timer enable bit (WUTE bit) is synchronized with RTC APB clock.
- Returns:
Status value:
1: RTC Wakeup Timer registers are synchronised
0: RTC Wakeup Timer registers are not synchronised
Note
The software must then wait until it is set again before wakeup timer works, which means that the WUTE bit have been correctly copied into the shadow register. By the time WUTE bit is synchronized, other control bits of wakeup timer has already been synchronized, because these bits are configure before WUTE bit.
-
void RTC_WakeupClear(void)
Clear wakeup pending interrupt.
-
void RTC_WakeupCmd(u32 NewState)
Enable or disable the specified RTC Wakeup Timer.
- Parameters:
NewState – New state of the specified wakeup timer. This parameter can be: ENABLE or DISABLE.
Note
Wakeup timer starts down counting after 3 to 4 seconds
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
-
u32 Get_OSC131_STATE(void)
Get OSC131k_STATE.
- Returns:
OSC131K state value.
-
void RTC_ClearDetINT(void)
Clear rtc_det_intr.
-
void RTC_ClkSource_Select(u8 CLK_Source)
RTC clk source select.
- Parameters:
CLK_Source – SDM32K or OSC131K_DIV4
-
void RTC_Enable(u8 NewState)
Enable rtc function.
- Parameters:
NewState – New state of RTC. This parameter can be: ENABLE or DISABLE.
-
u32 RTC_GetDetintr(void)
Get rtc_det_intr state.
- Returns:
RTC detection interrupt state.
-
void Set_OSC131_STATE(u32 temp)
Set OSC131k_STATE.
- Parameters:
temp – The value you want to write into RTC_MISC_OSC131K_STATE reg.
Not supported.
RTC_IO Exported Functions
-
void RTCIO_GetTimeInfo(RTCIO_TimeInfo *pDataOut)
Output time info after setting work mode to MODE_SHIFT_ENABLE.
- Parameters:
pDataOut – Pointer to RTCIO_TimeInfo structure to store time information.
-
u32 RTCIO_GetWorkMode(void)
Get RTCIO work mode.
- Returns:
Current work mode of RTCIO:
0: MODE_SHIFT_DISABLE
1: MODE_SHIFT_ENABLE
2: MODE_RTC_START
-
u32 RTCIO_IsEnabled(void)
Check RTCIO Module enabled or not.
- Returns:
Whether RTCIO is enabled:
TRUE: enabled
FALSE: disabled
-
void RTCIO_ModeRTCStart(void)
Enable RTCIO by setting work mode to MODE_RTC_START.
-
void RTCIO_SetRValue(u32 ResetRcal)
Receive calibration value from rtc_sio.
- Parameters:
ResetRcal – Reset Rcal flag. This parameter can be: RTCIO_RECV_RVAL_RST, RTCIO_RECV_RVAL_CAL
-
void RTCIO_SetWorkMode(u32 Mode)
Configure RTCIO work mode,it works MODE_SHIFT_DISABLE by default.
- Parameters:
Mode – New work mode of RTCIO. This parameter can be: MODE_SHIFT_DISABLE, MODE_SHIFT_ENABLE, MODE_RTC_START,
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Not supported.
Mbed API
MBED_RTC Exported Types
Structure Type
MBED_RTC Exported Functions
-
void rtc_disable_alarm(void)
Disable RTC Alarm.
-
void rtc_free(void)
Deinitialize the RTC device.
-
void rtc_init(void)
Initialize the RTC device, including clock, function and RTC registers.
-
int rtc_isenabled(void)
Judge whether RTC is enabled or not.
- Returns:
RTC status:
1: RTC has been enabled.
0: RTC has not been enabled.
-
time_t rtc_read(void)
Get current timestamp in seconds from RTC.
- Returns:
Current timestamp in seconds which is calculated from 1970.1.1 00:00:00.
-
u32 rtc_set_alarm(alarm_t *alrm, alarm_irq_handler alarmHandler)
Set the specified RTC Alarm and interrupt.
- Parameters:
alrm – Alarm object defined in application software.
alarmHandler – Alarm interrupt callback function.
- Returns:
Status:
1: Success.
Others: Error.
-
void rtc_write(time_t t)
Set the specified timestamp in seconds to RTC.
- Parameters:
t – Seconds from 1970.1.1 00:00:00 to specified data and time which is to be set.