MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
RTC: Real Time Clock

Overview

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)
{
/* Initialize board hardware. */
BOARD_InitHardware();
PRINTF("\r\nRTC second example.\r\n");
RTC_Init(RTC);
/* Set a start date time and start RT */
g_RtcTime.year = 2014U;
g_RtcTime.month = 12U;
g_RtcTime.day = 25U;
g_RtcTime.hour = 19U;
g_RtcTime.minute = 0;
g_RtcTime.second = 0;
/* Set RTC time to default */
RTC_SetDatetime(RTC, &g_RtcTime);
/* Enable RTC second interrupt */
RTC_EnableInterrupts(RTC, kRTC_SecondInterruptEnable);
/* Enable at the NVIC */
NVIC_EnableIRQ(RTC_SEC_IRQn);
g_RtcSecondFlag = 0;
while (1)
{
if (g_RtcSecondFlag)
{
g_RtcSecondFlag = 0;
/* Get data */
RTC_GetDatetime(RTC, &g_RtcTime);
/* Show data */
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)
{
if (RTC_GetStatusFlags(RTC) & kRTC_SecondInterruptFlag)
{
g_RtcSecondFlag = 1;
/* Clear second interrupt flag */
RTC_ClearStatusFlags(RTC, kRTC_SecondInterruptFlag);
}
}

Data Structures

struct  rtc_datetime_t
 Structure is used to hold the date and time. More...
 

Enumerations

enum  rtc_calibration_direction_t {
  kRTC_ForwardCalibration = 0U,
  kRTC_BackwardCalibration
}
 RTC calibration direction. More...
 
enum  _rtc_interrupt_enable
 RTC interrupt configuration structure.
 
enum  _rtc_status_flags
 RTC status flags.
 

Driver version

#define FSL_RTC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

static void RTC_Init (RTC_Type *base)
 Ungates the RTC clock. More...
 
static void RTC_Deinit (RTC_Type *base)
 Gate the RTC clock. More...
 

Current Time

status_t RTC_SetDatetime (RTC_Type *base, const rtc_datetime_t *datetime)
 Sets the RTC date and time according to the given time structure. More...
 
void RTC_GetDatetime (RTC_Type *base, rtc_datetime_t *datetime)
 Gets the RTC time and stores it in the given time structure. More...
 
void RTC_Calibration (RTC_Type *base, rtc_calibration_direction_t dir, uint16_t value)
 RTC calibration. More...
 
static uint32_t RTC_GetSecond (RTC_Type *base)
 Get RTC's second value. More...
 
static uint32_t RTC_GetCount (RTC_Type *base)
 Get RTC counter value. More...
 

RTC Free running

void RTC_EnableFreeRunningReset (RTC_Type *base, bool enable)
 Enable/Disable free running reset. More...
 
void RTC_SetFreeRunningInterruptThreshold (RTC_Type *base, uint32_t value)
 Set free running interrupt threshold. More...
 
static uint32_t RTC_GetFreeRunningInterruptThreshold (RTC_Type *base)
 Get free running interrupt threshold. More...
 
void RTC_SetFreeRunningResetThreshold (RTC_Type *base, uint32_t value)
 Set free running reset threshold. More...
 
static uint32_t RTC_GetFreeRunningResetThreshold (RTC_Type *base)
 Get free running reset threshold. More...
 
static uint32_t RTC_GetFreeRunningCount (RTC_Type *base)
 Get free running counter value. More...
 
void RTC_FreeRunningEnable (RTC_Type *base, bool enable)
 Enable/Disable RTC free running. More...
 

Status

static uint32_t RTC_GetStatusFlags (RTC_Type *base)
 Gets the RTC status flags. More...
 
void RTC_ClearStatusFlags (RTC_Type *base, uint32_t mask)
 Clears status flags with the provided mask. More...
 

Interrupts

void RTC_EnableInterrupts (RTC_Type *base, uint32_t mask)
 Enable RTC interrupts according to the provided mask. More...
 
void RTC_DisableInterrupts (RTC_Type *base, uint32_t mask)
 Disable RTC interrupts according to the provided mask. More...
 

Data Structure Documentation

struct rtc_datetime_t

Data Fields

uint16_t year
 Range from 1970 to 2099. More...
 
uint8_t month
 Range from 1 to 12. More...
 
uint8_t day
 Range from 1 to 31 (depending on month). More...
 
uint8_t hour
 Range from 0 to 23. More...
 
uint8_t minute
 Range from 0 to 59. More...
 
uint8_t second
 Range from 0 to 59. More...
 

Field Documentation

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

Enumeration Type Documentation

Enumerator
kRTC_ForwardCalibration 

Forward calibration.

kRTC_BackwardCalibration 

Backward calibration.

Function Documentation

static void RTC_Init ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address
static void RTC_Deinit ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address
status_t RTC_SetDatetime ( RTC_Type *  base,
const rtc_datetime_t datetime 
)

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
baseRTC peripheral base address
datetimePointer 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
void RTC_GetDatetime ( RTC_Type *  base,
rtc_datetime_t datetime 
)
Parameters
baseRTC peripheral base address.
datetimePointer to structure where the date and time details are stored.
void RTC_Calibration ( RTC_Type *  base,
rtc_calibration_direction_t  dir,
uint16_t  value 
)
Parameters
baseRTC peripheral base address.
dirForward or backward calibration.
valuecalibration value.
static uint32_t RTC_GetSecond ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address.
Returns
RTC's second value
static uint32_t RTC_GetCount ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address.
Returns
RTC counter value
void RTC_EnableFreeRunningReset ( RTC_Type *  base,
bool  enable 
)
Parameters
baseRTC peripheral base address.
enabletrue to enable the reset, false to disable.
void RTC_SetFreeRunningInterruptThreshold ( RTC_Type *  base,
uint32_t  value 
)
Parameters
baseRTC peripheral base address.
valueFree running interrupt threshold value.
static uint32_t RTC_GetFreeRunningInterruptThreshold ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address.
Returns
Free running interrupt threshold value.
void RTC_SetFreeRunningResetThreshold ( RTC_Type *  base,
uint32_t  value 
)
Parameters
baseRTC peripheral base address.
valueFree running reset threshold value.
static uint32_t RTC_GetFreeRunningResetThreshold ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address.
Returns
Free running reset threshold value.
static uint32_t RTC_GetFreeRunningCount ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address.
Returns
Free running counter value
void RTC_FreeRunningEnable ( RTC_Type *  base,
bool  enable 
)
Parameters
baseRTC peripheral base address.
enabletrue 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
baseRTC 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
baseRTC peripheral base address.
maskThe 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
baseRTC peripheral base address.
maskThe interrupts to enable. Logical OR of _rtc_interrupt_enable.
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
baseRTC peripheral base address.
maskThe interrupts to disable. Logical OR of _rtc_interrupt_enable.