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.
Set & Get Alarm
The function RTC_SetAlarm() sets the alarm time period in seconds. User passes in the details in date & time format by using the datetime data structure.
The function RTC_GetAlarm() reads the alarm time 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.
High resolution timer
Provides functions to enable high resolution timer and set and get the wake time.
Typical use case
RTC tick example
Example to set the RTC current time and trigger an alarm. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtc
|
void | RTC_Init (RTC_Type *base) |
| Ungates the RTC clock and enables the RTC oscillator. More...
|
|
static void | RTC_Deinit (RTC_Type *base) |
| Stop the timer and gate the RTC clock. 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 |
Enumerator |
---|
kRTC_AlarmInterruptEnable |
Alarm interrupt.
|
kRTC_WakeupInterruptEnable |
Wake-up interrupt.
|
Enumerator |
---|
kRTC_AlarmFlag |
Alarm flag.
|
kRTC_WakeupFlag |
1kHz wake-up timer flag
|
void RTC_Init |
( |
RTC_Type * |
base | ) |
|
- Note
- This API should be called at the beginning of the application using the RTC driver.
- Parameters
-
base | RTC peripheral base address |
static void RTC_Deinit |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
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. |
The function checks whether the specified alarm time is greater than the present time. If not, the function does not set the alarm and returns an error.
- Parameters
-
base | RTC peripheral base address |
alarmTime | Pointer to structure where the alarm time is stored. |
- Returns
- kStatus_Success: success in setting the RTC alarm kStatus_InvalidArgument: Error because the alarm datetime format is incorrect kStatus_Fail: Error because the alarm time has already passed
- Parameters
-
base | RTC peripheral base address |
datetime | Pointer to structure where the alarm date and time details are stored. |
static void RTC_SetWakeupCount |
( |
RTC_Type * |
base, |
|
|
uint16_t |
wakeupValue |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
wakeupValue | The value to be loaded into the RTC WAKE register |
static uint16_t RTC_GetWakeupCount |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
static void RTC_EnableInterrupts |
( |
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 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_GetEnabledInterrupts |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
- Returns
- The enabled interrupts. This is the 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 void RTC_ClearStatusFlags |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address |
mask | The status flags to clear. This is a logical OR of members of the enumeration rtc_status_flags_t |
static void RTC_StartTimer |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
After calling this function, the timer counter increments once a second provided SR[TOF] or SR[TIF] are not set.
- 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 |
static void RTC_Reset |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
This resets all RTC registers to their reset value. The bit is cleared by software explicitly clearing it.
- Parameters
-
base | RTC peripheral base address |