The MCUXpresso SDK provides a driver for the Real Time Clock (RTC).
Function groups
The RTC driver supports operating the module as a time counter.
Initialization and deinitialization
The function RTC_Init() initializes the RTC with specified configurations. The function RTC_GetDefaultConfig() gets the default configurations.
The function RTC_Deinit() disables the RTC timer and disables the module clock.
Set & Get Datetime
The function RTC_SetDatetime() sets the timer period in seconds. User passes in the details in date & time format by using the below data structure.
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtc The function RTC_GetDatetime() reads the current timer value in seconds, converts it to date & time format and stores it into a datetime structure passed in by the user.
Start & Stop timer
The function RTC_StartTimer() starts the RTC time counter.
The function RTC_StopTimer() stops the RTC time counter.
Status
Provides functions to get and clear the RTC status.
Interrupt
Provides functions to enable/disable RTC interrupts and get current enabled interrupts.
Typical use case
RTC tick example
Example to set the RTC current time and trigger an sleep interrupt. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtc
|
#define | RTC_SYNC_TIME_OUT_TICKS ((SystemCoreClock * (3 + 1)) / RTC_TFRO_FREQ) |
| Time-out ticks is (in ARM clock ticks) that a bus synchronization wait should take. More...
|
|
uint16_t rtc_datetime_t::year |
uint8_t rtc_datetime_t::month |
uint8_t rtc_datetime_t::day |
uint8_t rtc_datetime_t::hour |
uint8_t rtc_datetime_t::minute |
uint8_t rtc_datetime_t::second |
#define RTC_SYNC_TIME_OUT_TICKS ((SystemCoreClock * (3 + 1)) / RTC_TFRO_FREQ) |
Worst-case wait is 3 TFRO ticks. Worst case ARM speed is full SFRO (no divider). Since the TFRO could be somewhat slower than spec'd, and the SFRO somewhat faster, we add 33% as margin - it is just for an emergency time-out.
Enumerator |
---|
kRTC_CountDownInterruptEnable |
Count down interrupt.
|
Enumerator |
---|
kRTC_EnabledFlag |
Flag for RTC enabled or not.
|
kRTC_FreezedFlag |
Flag for RTC freezed or not.
|
kRTC_RunFlag |
Flag for RTC running status.
|
Enumerator |
---|
kRTC_CountDownRawStatus |
Raw interrupt status for count down finish.
|
Enumerator |
---|
kRTC_CountDownMaskedStatus |
Masked interrupt status for count down finish.
|
void RTC_WriteRegister |
( |
__IO uint32_t * |
reg, |
|
|
uint32_t |
value |
|
) |
| |
- Note
- This API will write data to RTC register, all bus synchornous operation will be done.
uint32_t RTC_ReadRegister |
( |
__I uint32_t * |
reg | ) |
|
- Note
- This API will read the RTC's register value.
void RTC_Init |
( |
RTC_Type * |
base, |
|
|
rtc_config_t * |
config |
|
) |
| |
- Note
- This API should be called at the beginning of the application using the RTC driver. This API will help configure the calibration value, count down auto start, enable RTC timer and the initialized date for counting.
- Parameters
-
base | RTC peripheral base address |
config | configuration for initializing RTC. |
static void RTC_Deinit |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
void RTC_GetDefaultConfig |
( |
RTC_Type * |
base, |
|
|
rtc_config_t * |
config |
|
) |
| |
This configure structure will help setup calibration value, formated date value.
And set if enable RTC timer and count down auto start function.
- Parameters
-
base | RTC peripheral base address |
config | configure structure for setting RTC module. refer to . |
The RTC counter must be stopped prior to calling this function as writes to the RTC seconds register will fail if the RTC counter is running.
- Parameters
-
base | RTC peripheral base address |
datetime | Pointer to structure where the date and time details to set are stored |
- Returns
- kStatus_Success: Success in setting the time and starting the RTC kStatus_InvalidArgument: Error because the datetime format is incorrect
- Parameters
-
base | RTC peripheral base address |
datetime | Pointer to structure where the date and time details are stored. |
static void RTC_SetSleepTime |
( |
RTC_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinestatic |
The function will set the sleep time for counting down, if the value in SLEEPT register equals to 0, an interrupt will be generated if this interrupt is enabled.
- Parameters
-
base | RTC peripheral base address |
value | sleep time, uint is seconds. |
static uint32_t RTC_GetSleepTime |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The sleep remaining in register.
static void RTC_EnableInterrupts |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
static void RTC_DisableInterrupts |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
mask | The interrupts to enable. This is a logical OR of members of the enumeration rtc_interrupt_enable_t |
static uint32_t RTC_GetStatusFlags |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The status flags. This is the logical OR of members of the enumeration rtc_status_flags_t
static uint32_t RTC_GetRawInterruptStatus |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The status flags. This is the logical OR of members of the enumeration rtc_status_flags_t
static uint32_t RTC_GetMaskedInterruptStatus |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The status flags. This is the logical OR of members of the enumeration rtc_status_flags_t
static void RTC_ClearMaskedInterruptStatus |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The status flags. This is the logical OR of members of the enumeration rtc_masked_interrupt_status_t
static void RTC_StartTimer |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
After calling this function, the timer counter increments once a second.
- Parameters
-
base | RTC peripheral base address |
static void RTC_StopTimer |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
RTC's seconds register can be written to only when the timer is stopped.
- Parameters
-
base | RTC peripheral base address |
void RTC_EnableSleepAutoStart |
( |
RTC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | RTC peripheral base address |
enable | 1 for enable, 0 for disable. |
static void RTC_StartSleep |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
static void RTC_SetCalibrationValue |
( |
RTC_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinestatic |
The calibration value decide the number of TFRO clock pulses in one tick
- Parameters
-
base | RTC peripheral base address |
value | The value to be set. |
static uint32_t RTC_GetCalibrationValue |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |