Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the IRTC Peripheral Driver. The IRTC Peripheral driver sets and gets the IRTC clock, sets and reads the IRTC alarm time.

IRTC Peripheral Driver Initialization

To initialize, call the IRTC_DRV_Init() function with the IRTC instance number. Most SoCs have only one IRTC instance. Therefore, the instance number is zero. The driver initialization function un-gates the IRTC module clock, initializes the IRTC HAL layer driver, and enables the IRTC interrupts when an alarm is set.

This is an example how to create the irtc_init() function:

// init the irtc module //

IRTCS Setting and reading the IRTC time

The IRTC driver uses an instantiation of the irtc_datetime_t structure either to configure or read the date and time. Call the IRTC_DRV_SetDatetime() function to configure the current date and time and call the IRTC_DRV_GetDatetime() function to read the current date and time at a later time. This example shows how to use these functions:

irtc_datetime_t datetimeToSet;
datetimeToSet.year = 2013;
datetimeToSet.month = 10;
datetimeToSet.day = 13;
datetimeToSet.hour = 18;
datetimeToSet.minute = 55;
datetimeToSet.second = 30;
// set the datetime //
result = IRTC_DRV_SetDatetime(0, &datetime);
// get datetime //
IRTC_DRV_GetDatetime(0, &datetime);
printf("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second);

IRTC Triggering an Alarm

Call the IRTC_DRV_SetAlarm() function to set the alarm time and call the IRTC_DRV_GetAlarm() function to read the configured alarm time. Set the current time using the steps mentioned earlier prior to using the call to set the alarm time. The user can enable the option to trigger an interrupt when an alarm occurs. This is done by calling the IRTC_DRV_SetIntCmd() and IRTC_DRV_SetAlarmMatchMode() functions. This is an example to set an IRTC alarm. This example causes an alarm interrupt to be triggered after 5 minutes.

irtc_datetime_t datetimeToSet;
irtc_datetime_t alrmTimeToSet;
datetimeToSet.year = 2013;
datetimeToSet.month = 10;
datetimeToSet.day = 13;
datetimeToSet.hour = 18;
datetimeToSet.minute = 55;
datetimeToSet.second = 30;
IRTC_DRV_SetDatetime(0, &datetimeToSet);
alrmTimeToSet.year = datetimeToSet.year;
alrmTimeToSet.month = datetimeToSet.month;
alrmTimeToSet.day = datetimeToSet.day;
alrmTimeToSet.minute = datetimeToSet.minute + 5;
alrmTimeToSet.second = datetimeToSet.second;
IRTC_DRV_SetAlarm(0, &alrmTimeToSet);
IRTC_HAL_SetIntCmd(0, kIRTCAlarmIntFlag);

Variables

RTC_Type *const g_irtcBase [RTC_INSTANCE_COUNT]
 Table of base addresses for IRTC instances. More...
 
const IRQn_Type g_irtcIrqId [RTC_INSTANCE_COUNT]
 Table to save IRTC Alarm IRQ numbers for IRTC instances. More...
 

Initialization and De-initialization

irtc_status_t IRTC_DRV_Init (uint32_t instance, const irtc_datetime_t *datetime, const irtc_datetime_t *alarmDatetime, irtc_alarm_match_t alarmMode, const irtc_daylight_time_t *daylightTime)
 Initializes the IRTC module. More...
 
irtc_status_t IRTC_DRV_Deinit (uint32_t instance)
 Disables the IRTC module clock gate control. More...
 

IRTC Datetime Set and Get

static void IRTC_DRV_SetDatetime (uint32_t instance, irtc_datetime_t *datetime)
 Sets the IRTC date and time according to the given time structure. More...
 
static void IRTC_DRV_GetDatetime (uint32_t instance, irtc_datetime_t *datetime)
 Gets the IRTC time and stores it in the given time structure. More...
 

IRTC Alarm

static void IRTC_DRV_SetAlarmMatchMode (uint32_t instance, irtc_alarm_match_t alarmType)
 Sets the alarm match type. More...
 
static void IRTC_DRV_SetAlarm (uint32_t instance, irtc_datetime_t *alarmTime)
 Sets the IRTC alarm time. More...
 
static void IRTC_DRV_GetAlarm (uint32_t instance, irtc_datetime_t *date)
 Returns the IRTC alarm time. More...
 

Interrupts

static void IRTC_DRV_SetIntCmd (uint32_t instance, irtc_int_t interrupt, bool enable)
 Enables or disables the related IRTC interrupt. More...
 
static bool IRTC_DRV_GetIntCmd (uint32_t instance, irtc_int_t interrupt)
 Gets whether the IRTC interrupt is enabled or not. More...
 
static bool IRTC_DRV_GetIntStatusFlag (uint32_t instance, irtc_int_status_flag_t statusFlag)
 Gets the IRTC interrupt status flag state. More...
 
static void IRTC_DRV_ClearIntStatusFlag (uint32_t instance, irtc_int_status_flag_t statusFlag)
 Clears the IRTC interrupt status flag. More...
 

Function Documentation

irtc_status_t IRTC_DRV_Init ( uint32_t  instance,
const irtc_datetime_t datetime,
const irtc_datetime_t alarmDatetime,
irtc_alarm_match_t  alarmMode,
const irtc_daylight_time_t daylightTime 
)

Enables the IRTC clock and interrupts if requested by the user.

Parameters
instanceThe IRTC peripheral instance number.
datetimeDate and time need to set, pass NULL to ignore.
alarmDatetimeAlarm of date and time need to set, pass NULL to ignore.
alarmModeAlarm mode to set when will generate alarm.
daylightTimeDaylight saving time need to set, pass NULL to ignore.
Returns
Error or success returned by API.
irtc_status_t IRTC_DRV_Deinit ( uint32_t  instance)
Parameters
instanceThe IRTC peripheral instance number.
Returns
Error or success returned by API.
static void IRTC_DRV_SetDatetime ( uint32_t  instance,
irtc_datetime_t datetime 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
datetimePointer to structure where the date and time details to set are stored.
static void IRTC_DRV_GetDatetime ( uint32_t  instance,
irtc_datetime_t datetime 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
datetimePointer to structure where the date and time details are stored.
static void IRTC_DRV_SetAlarmMatchMode ( uint32_t  instance,
irtc_alarm_match_t  alarmType 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
alarmTypeAlarm match selections that when an alarm will happen.
static void IRTC_DRV_SetAlarm ( uint32_t  instance,
irtc_datetime_t alarmTime 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
alarmTimePointer to structure where the alarm time is store.
static void IRTC_DRV_GetAlarm ( uint32_t  instance,
irtc_datetime_t date 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
datePointer to structure where the alarm date and time details are stored.
static void IRTC_DRV_SetIntCmd ( uint32_t  instance,
irtc_int_t  interrupt,
bool  enable 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
interruptThe interrupt name, defined in type irtc_int_t.
enableEnable(ture) or disable(false) related interrupt.
static bool IRTC_DRV_GetIntCmd ( uint32_t  instance,
irtc_int_t  interrupt 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
interruptThe interrupt name, defined in type irtc_int_t.
Returns
State of the interrupt: asserted (true) or not-asserted (false).
  • true: related interrupt is being enabled.
  • false: related interrupt is not enabled.
static bool IRTC_DRV_GetIntStatusFlag ( uint32_t  instance,
irtc_int_status_flag_t  statusFlag 
)
inlinestatic
Parameters
instanceThe IRTC peripheral instance number.
statusFlagThe status flag, defined in type irtc_int_status_flag_t.
Returns
State of the status flag: asserted (true) or not-asserted (false).
  • true: related status flag is being set.
  • false: related status flag is not set.
static void IRTC_DRV_ClearIntStatusFlag ( uint32_t  instance,
irtc_int_status_flag_t  statusFlag 
)
inlinestatic

Tamper interrupt status flag is cleared when the TAMPER_SCR[TMPR_STS] is cleared.

Parameters
instanceThe IRTC peripheral instance number.
statusFlagThe status flag, defined in type irtc_int_status_flag_t.

Variable Documentation

RTC_Type* const g_irtcBase[RTC_INSTANCE_COUNT]
const IRQn_Type g_irtcIrqId[RTC_INSTANCE_COUNT]