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 module of MCUXpresso SDK devices.

Typical use case

Example use of RTC API. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/rtc/

Data Structures

struct  rtc_datetime_t
 Structure is used to hold the date and time. More...
 
struct  rtc_config_t
 RTC config structure. More...
 

Typedefs

typedef void(* rtc_alarm_callback_t )(void)
 RTC alarm callback function. More...
 

Enumerations

enum  rtc_clock_source_t {
  kRTC_ExternalClock = 0U,
  kRTC_LPOCLK = 1U,
  kRTC_ICSIRCLK = 2U,
  kRTC_BusClock = 3U
}
 List of RTC clock source. More...
 
enum  rtc_clock_prescaler_t {
  kRTC_ClockDivide_off = 0U,
  kRTC_ClockDivide_1_128 = 1U,
  kRTC_ClockDivide_2_256 = 2U,
  kRTC_ClockDivide_4_512 = 3U,
  kRTC_ClockDivide_8_1024 = 4U,
  kRTC_ClockDivide_16_2048 = 5U,
  kRTC_ClockDivide_32_100 = 6U,
  kRTC_ClockDivide_64_1000 = 7U
}
 List of RTC clock prescaler. More...
 
enum  rtc_interrupt_enable_t { kRTC_InterruptEnable = RTC_SC_RTIE_MASK }
 List of RTC interrupts. More...
 
enum  rtc_interrupt_flags_t { kRTC_InterruptFlag = RTC_SC_RTIF_MASK }
 List of RTC Interrupt flags. More...
 
enum  rtc_output_enable_t { kRTC_OutputEnable = RTC_SC_RTCO_MASK }
 List of RTC Output. More...
 

Driver version

#define FSL_RTC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))
 Version 2.0.3.
 

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

status_t RTC_SetDatetime (rtc_datetime_t *datetime)
 Sets the RTC date and time according to the given time structure. More...
 
void RTC_GetDatetime (rtc_datetime_t *datetime)
 Gets the RTC time and stores it in the given time structure. More...
 
void RTC_SetAlarm (uint32_t second)
 Sets the RTC alarm time. More...
 
void RTC_GetAlarm (rtc_datetime_t *datetime)
 Returns the RTC alarm time. More...
 
void RTC_SetAlarmCallback (rtc_alarm_callback_t callback)
 Set the RTC alarm callback. More...
 

Select Source clock

static void RTC_SelectSourceClock (RTC_Type *base, rtc_clock_source_t clock, rtc_clock_prescaler_t divide)
 Select Real-Time Clock Source and Clock Prescaler. More...
 
uint32_t RTC_GetDivideValue (RTC_Type *base)
 Get the RTC Divide 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...
 
static uint32_t RTC_GetEnabledInterrupts (RTC_Type *base)
 Gets the enabled RTC interrupts. More...
 
static uint32_t RTC_GetInterruptFlags (RTC_Type *base)
 Gets the RTC interrupt flags. More...
 
static void RTC_ClearInterruptFlags (RTC_Type *base, uint32_t mask)
 Clears the RTC interrupt flags. More...
 

Output Interface

static void RTC_EnableOutput (RTC_Type *base, uint32_t mask)
 Enable the RTC output. More...
 
static void RTC_DisableOutput (RTC_Type *base, uint32_t mask)
 Disable the RTC output. More...
 

Set module value and Get Count value

static void RTC_SetModuloValue (RTC_Type *base, uint32_t value)
 Set the RTC module value. More...
 
static uint16_t RTC_GetCountValue (RTC_Type *base)
 Get the RTC Count value. 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
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.

Typedef Documentation

typedef void(* rtc_alarm_callback_t)(void)

Enumeration Type Documentation

Enumerator
kRTC_ExternalClock 

External clock source.

kRTC_LPOCLK 

Real-time clock source is 1 kHz (LPOCLK)

kRTC_ICSIRCLK 

Internal reference clock (ICSIRCLK)

kRTC_BusClock 

Bus clock.

Enumerator
kRTC_ClockDivide_off 

Off.

kRTC_ClockDivide_1_128 

If RTCLKS = x0, it is 1; if RTCLKS = x1, it is 128.

kRTC_ClockDivide_2_256 

If RTCLKS = x0, it is 2; if RTCLKS = x1, it is 256.

kRTC_ClockDivide_4_512 

If RTCLKS = x0, it is 4; if RTCLKS = x1, it is 512.

kRTC_ClockDivide_8_1024 

If RTCLKS = x0, it is 8; if RTCLKS = x1, it is 1024.

kRTC_ClockDivide_16_2048 

If RTCLKS = x0, it is 16; if RTCLKS = x1, it is 2048.

kRTC_ClockDivide_32_100 

If RTCLKS = x0, it is 32; if RTCLKS = x1, it is 100.

kRTC_ClockDivide_64_1000 

If RTCLKS = x0, it is 64; if RTCLKS = x1, it is 1000.

Enumerator
kRTC_InterruptEnable 

Interrupt enable.

Enumerator
kRTC_InterruptFlag 

Interrupt flag.

Enumerator
kRTC_OutputEnable 

Output enable.

Function Documentation

void RTC_Init ( RTC_Type *  base,
const rtc_config_t config 
)
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->clockSource = kRTC_BusClock;
* config->prescaler = kRTC_ClockDivide_16_2048;
* config->time_us = 1000000U;
*
Parameters
configPointer to the user's RTC configuration structure.
status_t RTC_SetDatetime ( rtc_datetime_t datetime)
Parameters
datetimePointer to the structure where the date and time details 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_datetime_t datetime)
Parameters
datetimePointer to the structure where the date and time details are stored.
void RTC_SetAlarm ( uint32_t  second)
Parameters
secondSecond value. User input the number of second. After seconds user input, alarm occurs.
void RTC_GetAlarm ( rtc_datetime_t datetime)
Parameters
datetimePointer to the structure where the alarm date and time details are stored.
void RTC_SetAlarmCallback ( rtc_alarm_callback_t  callback)
Parameters
callbackThe callback function.
static void RTC_SelectSourceClock ( RTC_Type *  base,
rtc_clock_source_t  clock,
rtc_clock_prescaler_t  divide 
)
inlinestatic
Parameters
baseRTC peripheral base address
clockSelect RTC clock source
divideSelect RTC clock prescaler value
uint32_t RTC_GetDivideValue ( RTC_Type *  base)
Note
This API should be called after selecting clock source and clock prescaler.
Parameters
baseRTC peripheral base address
Returns
The Divider value. The Divider value depends on clock source and clock prescaler
static void RTC_EnableInterrupts ( 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 void RTC_DisableInterrupts ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
basePIT peripheral base address
maskThe interrupts to disable. This is a logical OR of members of the enumeration rtc_interrupt_enable_t
static uint32_t RTC_GetEnabledInterrupts ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC 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_GetInterruptFlags ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address
Returns
The interrupt flags. This is the logical OR of members of the enumeration rtc_interrupt_flags_t
static void RTC_ClearInterruptFlags ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseRTC peripheral base address
maskThe interrupt flags to clear. This is a logical OR of members of the enumeration rtc_interrupt_flags_t
static void RTC_EnableOutput ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic

If RTC output is enabled, the RTCO pinout will be toggled when RTC counter overflows

Parameters
baseRTC peripheral base address
maskThe Output to enable. This is a logical OR of members of the enumeration rtc_output_enable_t
static void RTC_DisableOutput ( RTC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseRTC peripheral base address
maskThe Output to disable. This is a logical OR of members of the enumeration rtc_output_enable_t
static void RTC_SetModuloValue ( RTC_Type *  base,
uint32_t  value 
)
inlinestatic
Parameters
baseRTC peripheral base address
valueThe Module Value. The RTC Modulo register allows the compare value to be set to any value from 0x0000 to 0xFFFF
static uint16_t RTC_GetCountValue ( RTC_Type *  base)
inlinestatic
Parameters
baseRTC peripheral base address
Returns
The Count Value. The Count Value is allowed from 0x0000 to 0xFFFF