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 driver for the Real Time Clock (RTC) of MCUXpresso SDK devices.

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.

Get current counter

The function RTC_GetCounter() reads the current counter.

Set & Get Alarm

The function RTC_SetAlarm() sets the alarm counter. When the RTC counter reaches the value of alarm counter, the alarm interrupt may occur.

The function RTC_GetAlarm() reads the alarm counter.

Start & Stop timer

The function RTC_StartTimer() starts the RTC time counter.

The function RTC_StopTimer() stops the RTC time counter.

The function RTC_ResetTimer() resets 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 alarm. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtc

Data Structures

struct  rtc_config_t
 RTC config structure. More...
 

Enumerations

enum  rtc_interrupt_enable_t {
  kRTC_AlarmInterruptEnable = (1U << 15U),
  kRTC_TimeOverflowInterruptEnable = (1U << 16U),
  kRTC_AllInterruptsEnable = (3U << 15U)
}
 List of RTC interrupts. More...
 
enum  rtc_status_flags_t {
  kRTC_CntRunFlag = (1U << 0U),
  kRTC_CntRstDoneFlag = (1U << 1U),
  kRTC_ResetFlag = (1U << 2U),
  kRTC_AlarmFlag = (1U << 15U),
  kRTC_TimeOverflowFlag = (1U << 16U),
  kRTC_AllNonClearableFlags = (7U << 0U),
  kRTC_AllClearableFlags = (3U << 15U)
}
 List of RTC flags. More...
 
enum  rtc_clock_div_t {
  kRTC_ClockDiv1 = 0U,
  kRTC_ClockDiv2 = 1U,
  kRTC_ClockDiv4 = 2U,
  kRTC_ClockDiv8 = 3U,
  kRTC_ClockDiv16 = 4U,
  kRTC_ClockDiv32 = 5U,
  kRTC_ClockDiv64 = 6U,
  kRTC_ClockDiv128 = 7U,
  kRTC_ClockDiv256 = 8U,
  kRTC_ClockDiv512 = 9U,
  kRTC_ClockDiv1024 = 10U,
  kRTC_ClockDiv2048 = 11U,
  kRTC_ClockDiv4096 = 12U,
  kRTC_ClockDiv8192 = 13U,
  kRTC_ClockDiv16384 = 14U,
  kRTC_ClockDiv32768 = 15U
}
 List of clock divider. More...
 

Driver version

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

Initialization and deinitialization

void RTC_Init (RTC_Type *base, const rtc_config_t *config)
 Ungates the RTC clock and configures the peripheral for basic operation. More...
 
void RTC_Deinit (RTC_Type *base)
 Stops the timer and gate the RTC clock. More...
 
void RTC_GetDefaultConfig (rtc_config_t *config)
 Fills in the RTC config struct with the default settings. More...
 

Current Time & Alarm

uint32_t RTC_GetCounter (RTC_Type *base)
 Gets current RTC counter value. More...
 
status_t RTC_SetAlarm (RTC_Type *base, uint32_t alarmCnt)
 Sets the RTC alarm time. More...
 
uint32_t RTC_GetAlarm (RTC_Type *base)
 Returns the RTC alarm counter value. More...
 

Interrupt Interface

void RTC_EnableInterrupts (RTC_Type *base, uint32_t mask)
 Enables the selected RTC interrupts. More...
 
void RTC_DisableInterrupts (RTC_Type *base, uint32_t mask)
 Disables the selected RTC interrupts. More...
 
uint32_t RTC_GetEnabledInterrupts (RTC_Type *base)
 Gets the enabled RTC interrupts. More...
 

Status Interface

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

Timer Start and Stop

void RTC_StartTimer (RTC_Type *base)
 Starts the RTC time counter. More...
 
void RTC_StopTimer (RTC_Type *base)
 Stops the RTC time counter. More...
 
void RTC_ResetTimer (RTC_Type *base)
 Performs a counter reset on the RTC module. More...
 

Data Structure Documentation

struct rtc_config_t

This structure holds the configuration settings for the RTC peripheral. To initialize this structure to reasonable defaults, call the RTC_GetDefaultConfig() function and pass a pointer to your config structure instance.

The config struct can be made const so it resides in flash

Data Fields

bool ignoreInRunning
 true: If the counter is already running, the configuration will be ignored. More...
 
bool autoUpdateCntVal
 true: CNT_VAL is updated on every counter clock tick. More...
 
bool stopCntInDebug
 true: In debug mode, stop the counters. More...
 
rtc_clock_div_t clkDiv
 Counter clock divider. More...
 
uint32_t cntUppVal
 If counter reaches this value, the counter will overflow to 0. More...
 

Field Documentation

bool rtc_config_t::ignoreInRunning

false: Counter will always be reset and the the configurations will always be set.

bool rtc_config_t::autoUpdateCntVal

false: CNT_VAL is not updated.

bool rtc_config_t::stopCntInDebug

false: In debug mode, counters are not affected.

rtc_clock_div_t rtc_config_t::clkDiv
uint32_t rtc_config_t::cntUppVal

Enumeration Type Documentation

Enumerator
kRTC_AlarmInterruptEnable 

Alarm interrupt.

kRTC_TimeOverflowInterruptEnable 

Time overflow interrupt.

kRTC_AllInterruptsEnable 

All interrupts to enable.

Enumerator
kRTC_CntRunFlag 

Counter reset done flag.

kRTC_CntRstDoneFlag 

Counter reset done flag.

kRTC_ResetFlag 

Module reset flag.

kRTC_AlarmFlag 

Alarm flag.

kRTC_TimeOverflowFlag 

Time overflow flag.

kRTC_AllNonClearableFlags 

All non-clearable flags.

kRTC_AllClearableFlags 

All clearable flags.

Enumerator
kRTC_ClockDiv1 

Clock divider 1.

kRTC_ClockDiv2 

Clock divider 2.

kRTC_ClockDiv4 

Clock divider 4.

kRTC_ClockDiv8 

Clock divider 8.

kRTC_ClockDiv16 

Clock divider 16.

kRTC_ClockDiv32 

Clock divider 32.

kRTC_ClockDiv64 

Clock divider 64.

kRTC_ClockDiv128 

Clock divider 128.

kRTC_ClockDiv256 

Clock divider 256.

kRTC_ClockDiv512 

Clock divider 512.

kRTC_ClockDiv1024 

Clock divider 1024.

kRTC_ClockDiv2048 

Clock divider 2048.

kRTC_ClockDiv4096 

Clock divider 4096.

kRTC_ClockDiv8192 

Clock divider 8192.

kRTC_ClockDiv16384 

Clock divider 16384.

kRTC_ClockDiv32768 

Clock divider 32768.

Function Documentation

void RTC_Init ( RTC_Type *  base,
const rtc_config_t config 
)

This function configures the RTC only if the counter is not running.

Note
This API should be called at the beginning of the application using the RTC driver.
Parameters
baseRTC peripheral base address
configPointer to the user's RTC configuration structure.
void RTC_Deinit ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
void RTC_GetDefaultConfig ( rtc_config_t config)

The default values are as follows.

* config->ignoreInRunning = true;
* config->autoUpdateCntVal = true;
* config->stopCntInDebug = true;
* config->clkDiv = kRTC_ClockDiv32;
* config->cntUppVal = 0xFFFFFFFFU;
*
Parameters
configPointer to the user's RTC configuration structure.
uint32_t RTC_GetCounter ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
Returns
counter value in RTC.
status_t RTC_SetAlarm ( RTC_Type *  base,
uint32_t  alarmCnt 
)

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
baseRTC peripheral base address
alarmCntCounter value to trigger the alarm.
Returns
kStatus_Success: success in setting the RTC alarm kStatus_Fail: Error because the alarm time has already passed
uint32_t RTC_GetAlarm ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
Returns
Alarm counter value in RTC.
void RTC_EnableInterrupts ( RTC_Type *  base,
uint32_t  mask 
)
Parameters
baseRTC peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration rtc_interrupt_enable_t
void RTC_DisableInterrupts ( RTC_Type *  base,
uint32_t  mask 
)
Parameters
baseRTC peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration rtc_interrupt_enable_t
uint32_t RTC_GetEnabledInterrupts ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration rtc_interrupt_enable_t
uint32_t RTC_GetStatusFlags ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration rtc_status_flags_t
void RTC_ClearStatusFlags ( RTC_Type *  base,
uint32_t  mask 
)
Parameters
baseRTC peripheral base address
maskThe status flags to clear. This is a logical OR of members of the enumeration rtc_status_flags_t
void RTC_StartTimer ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
void RTC_StopTimer ( RTC_Type *  base)
Parameters
baseRTC peripheral base address
void RTC_ResetTimer ( RTC_Type *  base)
Parameters
baseRTC peripheral base address