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).

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

Files

file  fsl_rtc.h
 

Data Structures

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

Macros

#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...
 

Enumerations

enum  rtc_interrupt_enable_t { kRTC_CountDownInterruptEnable = RTC_IMIS_IE_MASK }
 List of RTC interrupts. More...
 
enum  rtc_status_flags_t {
  kRTC_EnabledFlag = RTC_SR_EN_MASK,
  kRTC_FreezedFlag = RTC_SR_FREEZE_MASK,
  kRTC_RunFlag = RTC_SR_RUN_MASK
}
 List of RTC flags. More...
 
enum  rtc_raw_interrupt_status_t { kRTC_CountDownRawStatus = RTC_RIS_RIS_MASK }
 List of RTC raw interrupt status. More...
 
enum  rtc_masked_interrupt_status_t { kRTC_CountDownMaskedStatus = RTC_MIS_MIS_MASK }
 List of RTC masked interrupt status. More...
 

Driver version

#define FSL_RTC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 Version 2.0.1.
 

Bus synchornous operations.

void RTC_WriteRegister (__IO uint32_t *reg, uint32_t value)
 Write value to RTC register. More...
 
uint32_t RTC_ReadRegister (__I uint32_t *reg)
 Read data from RTC register. More...
 

Initialization and deinitialization

void RTC_Init (RTC_Type *base, rtc_config_t *config)
 Initalize the RTC mudule. More...
 
static void RTC_Deinit (RTC_Type *base)
 Stop the timer and gate the RTC clock. More...
 
void RTC_GetDefaultConfig (RTC_Type *base, rtc_config_t *config)
 Get default config for RTC setting. More...
 

Current Time date.

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...
 
static void RTC_SetSleepTime (RTC_Type *base, uint32_t value)
 Sets the RTC sleep time. More...
 
static uint32_t RTC_GetSleepTime (RTC_Type *base)
 Returns the current RTC sleep time value. More...
 

Interrupt Interface

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

Status Interface

static uint32_t RTC_GetStatusFlags (RTC_Type *base)
 Gets the RTC status flags. More...
 
static uint32_t RTC_GetRawInterruptStatus (RTC_Type *base)
 Gets the RTC Raw interrupt status. More...
 
static uint32_t RTC_GetMaskedInterruptStatus (RTC_Type *base)
 Gets the RTC status flags. More...
 
static void RTC_ClearMaskedInterruptStatus (RTC_Type *base, uint32_t mask)
 Clear masked interrupt status. More...
 

Timer Start and Stop

static void RTC_StartTimer (RTC_Type *base)
 Starts the RTC time counter. More...
 
static void RTC_StopTimer (RTC_Type *base)
 Stops the RTC time counter. More...
 
void RTC_EnableSleepAutoStart (RTC_Type *base, bool enable)
 Enable the sleep count down auto Start. More...
 
static void RTC_StartSleep (RTC_Type *base)
 Start the count down manually. More...
 
static void RTC_SetCalibrationValue (RTC_Type *base, uint32_t value)
 Set calibration value. More...
 
static uint32_t RTC_GetCalibrationValue (RTC_Type *base)
 Get the calibration value from register. 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

Macro Definition Documentation

#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.

Enumeration Type Documentation

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.

Function Documentation

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
baseRTC peripheral base address
configconfiguration for initializing RTC.
static void RTC_Deinit ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC 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
baseRTC peripheral base address
configconfigure structure for setting RTC module. refer to .
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.
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
baseRTC peripheral base address
valuesleep time, uint is seconds.
static uint32_t RTC_GetSleepTime ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address
Returns
The sleep remaining in register.
static void RTC_EnableInterrupts ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseRTC peripheral base address
maskThe interrupts to enable. Refer to the enumeration rtc_interrupt_enable_t
static void RTC_DisableInterrupts ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseRTC peripheral base address
maskThe 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
baseRTC 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
baseRTC 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
baseRTC 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
baseRTC 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
baseRTC 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
baseRTC peripheral base address
void RTC_EnableSleepAutoStart ( RTC_Type *  base,
bool  enable 
)
Parameters
baseRTC peripheral base address
enable1 for enable, 0 for disable.
static void RTC_StartSleep ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC 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
baseRTC peripheral base address
valueThe value to be set.
static uint32_t RTC_GetCalibrationValue ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address