The MCUXpresso SDK provides a peripheral driver for the Real Time Clock (RTC) module of MCUXpresso SDK devices.
Typical use case
Example use of RTC API.
int main(void)
{
BOARD_InitHardware();
PRINTF("\r\nRTC second example.\r\n");
g_RtcTime.year = 2014U;
g_RtcTime.month = 12U;
g_RtcTime.day = 25U;
g_RtcTime.hour = 19U;
g_RtcTime.minute = 0;
g_RtcTime.second = 0;
NVIC_EnableIRQ(RTC_SEC_IRQn);
g_RtcSecondFlag = 0;
while (1)
{
if (g_RtcSecondFlag)
{
g_RtcSecondFlag = 0;
PRINTF("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", g_RtcTime.year, g_RtcTime.month,
g_RtcTime.day, g_RtcTime.hour, g_RtcTime.minute, g_RtcTime.second);
}
}
}
void RTC_SEC_IRQHandler(void)
{
{
g_RtcSecondFlag = 1;
}
}
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_ForwardCalibration |
Forward calibration.
|
kRTC_BackwardCalibration |
Backward calibration.
|
static void RTC_Init |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- 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. |
- Parameters
-
base | RTC peripheral base address. |
dir | Forward or backward calibration. |
value | calibration value. |
static uint32_t RTC_GetSecond |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address. |
- Returns
- RTC's second value
static uint32_t RTC_GetCount |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address. |
- Returns
- RTC counter value
void RTC_EnableFreeRunningReset |
( |
RTC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | RTC peripheral base address. |
enable | true to enable the reset, false to disable. |
void RTC_SetFreeRunningInterruptThreshold |
( |
RTC_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
- Parameters
-
base | RTC peripheral base address. |
value | Free running interrupt threshold value. |
static uint32_t RTC_GetFreeRunningInterruptThreshold |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address. |
- Returns
- Free running interrupt threshold value.
void RTC_SetFreeRunningResetThreshold |
( |
RTC_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
- Parameters
-
base | RTC peripheral base address. |
value | Free running reset threshold value. |
static uint32_t RTC_GetFreeRunningResetThreshold |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address. |
- Returns
- Free running reset threshold value.
static uint32_t RTC_GetFreeRunningCount |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RTC peripheral base address. |
- Returns
- Free running counter value
void RTC_FreeRunningEnable |
( |
RTC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | RTC peripheral base address. |
enable | true to enable free running, false to disable. |
static uint32_t RTC_GetStatusFlags |
( |
RTC_Type * |
base | ) |
|
|
inlinestatic |
This function get all RTC status flags, the flags are returned as the logical OR value of the enumerators _rtc_status_flags.
- Parameters
-
base | RTC peripheral base address. |
- Returns
- RTC status flags which are ORed by the enumerators in the _rtc_status_flags.
void RTC_ClearStatusFlags |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function clears RTC status flags with a provided mask.
- Parameters
-
base | RTC peripheral base address. |
mask | The status flags to be cleared, it is logical OR value of _rtc_status_flags. |
void RTC_EnableInterrupts |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function enables the RTC interrupts according to the provided mask. The mask is a logical OR of enumeration members. See _rtc_interrupt_enable
- Parameters
-
void RTC_DisableInterrupts |
( |
RTC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function disables the RTC interrupts according to the provided mask. The mask is a logical OR of enumeration members. See _rtc_interrupt_enable
- Parameters
-