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 HAL driver. The IRTC HAL driver initializes the IRTC registers and provides functions to read or modify the IRTC registers. These are mostly invoked by the IRTC Peripheral driver.

IRTC Initialization

This function initiates a soft-reset of the IRTC module to reset the IRTC registers and configure IRTC according to user settings. It doesn't un-gate the IRTC clock.

IRTC Setting and reading the IRTC time

The HAL driver provides IRTC_HAL_SetDatetime() and IRTC_HAL_GetDatetime() functions to set and read the date and time using an instantiation of the irtc_datetime_t structure. This example describes the structure:

typedef struct IrtcDatetime
{
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t weekDay;

IRTC Setting and reading the Alarm

The HAL driver provides IRTC_HAL_SetAlarm() and IRTC_HAL_GetAlarm() functions to set an alarm and read back the alarm time.

Files

file  fsl_irtc_hal.h
 

Data Structures

struct  irtc_datetime_t
 Structure is used to hold the time in a simple "date" format. More...
 
struct  irtc_daylight_time_t
 Structure is used to hold the daylight saving time. More...
 
struct  irtc_tamper_config_t
 Structure is used to define the parameters to configure a RTC tamper event. More...
 

Enumerations

enum  irtc_status_t
 Error codes for the IRTC driver. More...
 
enum  irtc_filter_clock_source_t {
  kIRTC32K = 0x0,
  kIRTC512 = 0x1,
  kIRTC128 = 0x2,
  kIRTC64 = 0x3,
  kIRTC16 = 0x4,
  kIRTC8 = 0x5,
  kIRTC4 = 0x6,
  kIRTC2 = 0x7
}
 IRTC filter clock source options. More...
 
enum  irtc_tamper_pins_t {
  kIRTCTamper0 = 0x0,
  kIRTCTamper1 = 0x1,
  kIRTCTamper2 = 0x2,
  kIRTCTamper3 = 0x3
}
 IRTC Tamper pins. More...
 
enum  irtc_clock_output_t {
  kIRTCNoOutputClk = 0x0,
  kIRTCFine1hzClk = 0x1,
  kIRTC32khzClk = 0x2,
  kIRTCCoarse1hzClck = 0x3
}
 IRTC clock output selection. More...
 
enum  irtc_alarm_match_t {
  kIRTCSecMinHour = 0x0,
  kIRTCSecMinHourDay = 0x1,
  kIRTCSecMinHourDayMon = 0x2,
  kIRTCSecMinHourDayMonYear = 0x3
}
 IRTC alarm match selection. More...
 
enum  irtc_status_flag_t
 IRTC status flags. More...
 
enum  irtc_int_status_flag_t
 IRTC interrupt status flags. More...
 
enum  irtc_int_t
 IRTC interrupts. More...
 

Initialization

void IRTC_HAL_Init (RTC_Type *base)
 Resets the IRTC module. More...
 
void IRTC_HAL_SetLockRegisterCmd (RTC_Type *base, bool lock)
 Locks or unlocks IRTC registers for write access. More...
 

Date and Time Setting

Note
All Date and Time settings APIs except the IRTC_HAL_SetDatetime and the IRTC_HAL_GetDatetime settings, should first determine the state of the INVAL bit in the STATUS(bit 0) to determine that the counters are stable before their value can be read or changed (this be done by calling IRTC_HAL_GetStatusFlag(base, kIRTCInvalidate)). The assertion of INVAL bit ensures that no operation is done at the boundary of a second when counters change value.
void IRTC_HAL_SetYearMonth (RTC_Type *base, uint16_t year, uint16_t month)
 Sets the IRTC year and month. More...
 
void IRTC_HAL_GetYearMonth (RTC_Type *base, uint16_t *year, uint16_t *month)
 Gets the IRTC current year and month. More...
 
static void IRTC_HAL_SetDayWeek (RTC_Type *base, uint16_t day, uint16_t weekDay)
 Sets the IRTC day and day of week. More...
 
void IRTC_HAL_GetDayWeek (RTC_Type *base, uint16_t *day, uint16_t *weekDay)
 Gets the IRTC current day and day of week. More...
 
static void IRTC_HAL_SetHourMin (RTC_Type *base, uint16_t hour, uint16_t min)
 Sets the IRTC hours and minutes. More...
 
void IRTC_HAL_GetHourMin (RTC_Type *base, uint16_t *hour, uint16_t *min)
 Gets the IRTC current hours and minutes. More...
 
static void IRTC_HAL_SetSec (RTC_Type *base, uint16_t sec)
 Sets the IRTC second counter. More...
 
static void IRTC_HAL_GetSec (RTC_Type *base, uint16_t *sec)
 Gets the IRTC current second counter. More...
 
void IRTC_HAL_SetDatetime (RTC_Type *base, const irtc_datetime_t *datetime)
 Sets the IRTC date and time according to the given time structure. More...
 
void IRTC_HAL_GetDatetime (RTC_Type *base, irtc_datetime_t *datetime)
 Gets the IRTC time and stores it in the given time structure. More...
 

Alarm Time Setting

static void IRTC_HAL_SetAlarmMatchMode (RTC_Type *base, irtc_alarm_match_t alarmType)
 Sets the alarm match type. More...
 
void IRTC_HAL_SetAlarm (RTC_Type *base, const irtc_datetime_t *datetime)
 Sets the IRTC alarm time and enables the alarm interrupt. More...
 
void IRTC_HAL_GetAlarm (RTC_Type *base, irtc_datetime_t *datetime)
 Reads the value of the time alarm. More...
 

Daylight Saving Time Setting

static void IRTC_HAL_SetDaylightMonth (RTC_Type *base, uint16_t startMonth, uint16_t endMonth)
 Sets IRTC daylight savings start month and end month. More...
 
void IRTC_HAL_GetDaylightMonth (RTC_Type *base, uint16_t *startMonth, uint16_t *endMonth)
 Gets the IRTC current daylight savings start and end month. More...
 
static void IRTC_HAL_SetDaylightDay (RTC_Type *base, uint16_t startDay, uint16_t endDay)
 Sets the IRTC daylight savings start and end day. More...
 
void IRTC_HAL_GetDaylightDay (RTC_Type *base, uint16_t *startDay, uint16_t *endDay)
 Gets the IRTC current daylight savings start and end day. More...
 
static void IRTC_HAL_SetDaylightHour (RTC_Type *base, uint16_t startHour, uint16_t endHour)
 Sets the IRTC current daylight savings start and end hour. More...
 
void IRTC_HAL_GetDaylightHour (RTC_Type *base, uint16_t *startHour, uint16_t *endHour)
 Gets the IRTC current daylight savings start and end hour. More...
 
void IRTC_HAL_SetDaylightTime (RTC_Type *base, const irtc_daylight_time_t *datetime)
 Sets the IRTC daylight savings date and time. More...
 
void IRTC_HAL_GetDaylightTime (RTC_Type *base, irtc_daylight_time_t *datetime)
 Gets the IRTC daylight savings time and stores it in the given time structure. More...
 

Status

static bool IRTC_HAL_GetStatusFlag (RTC_Type *base, irtc_status_flag_t statusFlag)
 Gets the IRTC status flag state. More...
 

Interrupts

static void IRTC_HAL_SetIntCmd (RTC_Type *base, irtc_int_t interrupt, bool enable)
 Enables or disables the related IRTC interrupt. More...
 
static bool IRTC_HAL_GetIntCmd (RTC_Type *base, irtc_int_t interrupt)
 Indicates whether the IRTC interrupt is enabled or not. More...
 
static bool IRTC_HAL_GetIntStatusFlag (RTC_Type *base, irtc_int_status_flag_t statusFlag)
 Gets the IRTC interrupt status flag state. More...
 
static void IRTC_HAL_ClearIntStatusFlag (RTC_Type *base, irtc_int_status_flag_t statusFlag)
 Clears the IRTC interrupt status flag. More...
 

IRTC Time Compensation

void IRTC_HAL_SetCoarseCompensation (RTC_Type *base, uint8_t compVal, uint8_t compInterval)
 Enables the coarse compensation and sets the value to the IRTC compensation register. More...
 
void IRTC_HAL_SetFineCompensation (RTC_Type *base, uint8_t integralVal, uint8_t fracVal, bool accumulateFrac)
 Enables the fine compensation and sets the value to the IRTC compensation register. More...
 

IRTC Control

static void IRTC_HAL_SetClockOutMode (RTC_Type *base, irtc_clock_output_t clock)
 Selects which clock to output from the SoC for use outside the RTC. More...
 
static void IRTC_HAL_SoftwareReset (RTC_Type *base)
 Performs a software reset on the IRTC module. More...
 

IRTC Tamper

void IRTC_HAL_ConfigTamperParams (RTC_Type *base, irtc_tamper_pins_t tamperNum, irtc_tamper_config_t *tamperConfig)
 This function allows configuring the four tamper inputs. More...
 
static void IRTC_HAL_EnableTamper (RTC_Type *base)
 Enables the tamper feature. More...
 
static void IRTC_HAL_DisableTamper (RTC_Type *base)
 Disables the tamper feature. More...
 

Data Structure Documentation

struct irtc_datetime_t

Data Fields

uint16_t year
 Range from 1984 to 2239.
 
uint16_t month
 Range from 1 to 12.
 
uint16_t day
 Range from 1 to 31 (depending on month).
 
uint16_t weekDay
 Range from 0(Sunday) to 6(Saturday).
 
uint16_t hour
 Range from 0 to 23.
 
uint16_t minute
 Range from 0 to 59.
 
uint16_t second
 Range from 0 to 59.
 
struct irtc_daylight_time_t

Data Fields

uint16_t startMonth
 Range from 1 to 12.
 
uint16_t endMonth
 Range from 1 to 12.
 
uint16_t startDay
 Range from 1 to 31 (depending on month).
 
uint16_t endDay
 Range from 1 to 31 (depending on month).
 
uint16_t startHour
 Range from 0 to 23.
 
uint16_t endHour
 Range from 0 to 23.
 
struct irtc_tamper_config_t

Data Fields

bool pinPolarity
 true: tamper has active low polarity; false: active high polarity
 
irtc_filter_clock_source_t filterClk
 Clock source for the tamper filter.
 
uint8_t filterDuration
 Tamper filter duration. More...
 

Field Documentation

uint8_t irtc_tamper_config_t::filterDuration

Enumeration Type Documentation

Enumerator
kIRTC32K 

Use 32 kHz clock source for the tamper filter.

kIRTC512 

Use 512 Hz clock source for the tamper filter.

kIRTC128 

Use 128 Hz clock source for the tamper filter.

kIRTC64 

Use 64 Hz clock source for the tamper filter.

kIRTC16 

Use 16 Hz clock source for the tamper filter.

kIRTC8 

Use 8 Hz clock source for the tamper filter.

kIRTC4 

Use 4 Hz clock source for the tamper filter.

kIRTC2 

Use 2 Hz clock source for the tamper filter.

Enumerator
kIRTCTamper0 

External Tamper 0.

kIRTCTamper1 

External Tamper 1.

kIRTCTamper2 

External Tamper 2.

kIRTCTamper3 

Internal tamper, does not have filter configuration.

Enumerator
kIRTCNoOutputClk 

No output clock.

kIRTCFine1hzClk 

Fine 1 Hz clock.

kIRTC32khzClk 

32.768 kHz clock

kIRTCCoarse1hzClck 

Coarse 1Hz clock.

Enumerator
kIRTCSecMinHour 

Generate alarm when sec/min/hour are matched.

kIRTCSecMinHourDay 

Generate alarm when sec/min/hour/day are matched.

kIRTCSecMinHourDayMon 

Generate alarm when sec/min/hour/day/month are matched.

kIRTCSecMinHourDayMonYear 

Generate alarm when sec/min/hour/day/month/year are matched.

enum irtc_int_t

Function Documentation

void IRTC_HAL_Init ( RTC_Type *  base)

This function initiates a soft-reset of the IRTC module to reset the IRTC registers.

Parameters
baseThe IRTC base address pointer.
void IRTC_HAL_SetLockRegisterCmd ( RTC_Type *  base,
bool  lock 
)
Note
When the registers are unlocked, they remain in unlocked state for 2 seconds, after which they are locked automatically. After power-on-reset, the registers come out unlocked and they are locked automatically 15 seconds after power on.
Parameters
baseThe IRTC base address pointer.
lockLock(true) or unlock(false) IRTC registers.
void IRTC_HAL_SetYearMonth ( RTC_Type *  base,
uint16_t  year,
uint16_t  month 
)
Parameters
baseThe IRTC base address pointer
yearYear number from 1984 to 2239.
monthMonth number from 1 to 12.
void IRTC_HAL_GetYearMonth ( RTC_Type *  base,
uint16_t *  year,
uint16_t *  month 
)
Parameters
baseThe IRTC base address pointer
yearCurrent year number from 1984 to 2239.
monthCurrent month number from 1 to 12.
static void IRTC_HAL_SetDayWeek ( RTC_Type *  base,
uint16_t  day,
uint16_t  weekDay 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
dayDay number from 1 to 31.
weekDayDay of week number from 0(Sunday) to 6(Saturday).
void IRTC_HAL_GetDayWeek ( RTC_Type *  base,
uint16_t *  day,
uint16_t *  weekDay 
)
Parameters
baseThe IRTC base address pointer
dayCurrent day number from 1 to 31.
weekDayCurrent day of week number from 0(Sunday) to 6(Saturday).
static void IRTC_HAL_SetHourMin ( RTC_Type *  base,
uint16_t  hour,
uint16_t  min 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
hourHour number from 0 to 23.
minMin number from 0 to 59.
void IRTC_HAL_GetHourMin ( RTC_Type *  base,
uint16_t *  hour,
uint16_t *  min 
)
Parameters
baseThe IRTC base address pointer
hourCurrent hour number from 0 to 23.
minCurrent minute number from 0 to 59.
static void IRTC_HAL_SetSec ( RTC_Type *  base,
uint16_t  sec 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
secSecond number from 0 to 59.
static void IRTC_HAL_GetSec ( RTC_Type *  base,
uint16_t *  sec 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
secCurrent second number from 0 to 59.
void IRTC_HAL_SetDatetime ( RTC_Type *  base,
const irtc_datetime_t datetime 
)
Parameters
baseThe IRTC base address pointer
datetimePointer to a structure where the date and time details are stored.
void IRTC_HAL_GetDatetime ( RTC_Type *  base,
irtc_datetime_t datetime 
)
Parameters
baseThe IRTC base address pointer
datetimePointer to a structure where the date and time details are stored.
static void IRTC_HAL_SetAlarmMatchMode ( RTC_Type *  base,
irtc_alarm_match_t  alarmType 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
alarmTypeAlarm match selections that when an alarm happens.
void IRTC_HAL_SetAlarm ( RTC_Type *  base,
const irtc_datetime_t datetime 
)

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
baseThe IRTC base address pointer.
datetimePointer to structure where the alarm date and time details will be stored at.
void IRTC_HAL_GetAlarm ( RTC_Type *  base,
irtc_datetime_t datetime 
)
Parameters
baseThe IRTC base address pointer
datetimePointer to a variable where the alarm date and time details are stored.
static void IRTC_HAL_SetDaylightMonth ( RTC_Type *  base,
uint16_t  startMonth,
uint16_t  endMonth 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
startMonthDaylight saving start month number from 1 to 12.
endMonthDaylight saving end month number from 1 to 12.
void IRTC_HAL_GetDaylightMonth ( RTC_Type *  base,
uint16_t *  startMonth,
uint16_t *  endMonth 
)
Parameters
baseThe IRTC base address pointer
startMonthCurrent daylight saving start month number from 1 to 12.
endMonthCurrent daylight saving end month number from 1 to 12.
static void IRTC_HAL_SetDaylightDay ( RTC_Type *  base,
uint16_t  startDay,
uint16_t  endDay 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
startDayDaylight saving day start value number from 1 to 31.
endDayDaylight saving day end value number from 1 to 31.
void IRTC_HAL_GetDaylightDay ( RTC_Type *  base,
uint16_t *  startDay,
uint16_t *  endDay 
)
Parameters
baseThe IRTC base address pointer
startDayCurrent daylight saving day start value number from 1 to 31.
endDayCurrent daylight saving day end value number from 1 to 31.
static void IRTC_HAL_SetDaylightHour ( RTC_Type *  base,
uint16_t  startHour,
uint16_t  endHour 
)
inlinestatic
Parameters
baseThe IRTC base address pointer
startHourDaylight saving hour start value.
endHourDaylight saving hour end value.
void IRTC_HAL_GetDaylightHour ( RTC_Type *  base,
uint16_t *  startHour,
uint16_t *  endHour 
)
Parameters
baseThe IRTC base address pointer
startHourCurrent daylight saving hour start value.
endHourCurrent daylight saving hour end value.
void IRTC_HAL_SetDaylightTime ( RTC_Type *  base,
const irtc_daylight_time_t datetime 
)
Parameters
baseThe IRTC base address pointer
datetimePointer to a structure where the date and time details are stored.
void IRTC_HAL_GetDaylightTime ( RTC_Type *  base,
irtc_daylight_time_t datetime 
)
Parameters
baseThe IRTC base address pointer
datetimePointer to a structure where the date and time details are stored.
static bool IRTC_HAL_GetStatusFlag ( RTC_Type *  base,
irtc_status_flag_t  statusFlag 
)
inlinestatic
Parameters
baseThe IRTC peripheral base pointer.
statusFlagThe status flag, defined in type irtc_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_HAL_SetIntCmd ( RTC_Type *  base,
irtc_int_t  interrupt,
bool  enable 
)
inlinestatic
Parameters
baseThe IRTC peripheral base pointer.
interruptThe interrupt name, defined in type irtc_int_t.
enableEnable (true) or disable (false) related interrupt.
static bool IRTC_HAL_GetIntCmd ( RTC_Type *  base,
irtc_int_t  interrupt 
)
inlinestatic
Parameters
baseThe IRTC peripheral base pointer.
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_HAL_GetIntStatusFlag ( RTC_Type *  base,
irtc_int_status_flag_t  statusFlag 
)
inlinestatic
Parameters
baseThe IRTC peripheral base pointer.
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_HAL_ClearIntStatusFlag ( RTC_Type *  base,
irtc_int_status_flag_t  statusFlag 
)
inlinestatic

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

Parameters
baseThe IRTC peripheral base pointer.
statusFlagThe status flag, defined in type irtc_int_status_flag_t.
void IRTC_HAL_SetCoarseCompensation ( RTC_Type *  base,
uint8_t  compVal,
uint8_t  compInterval 
)
Parameters
baseThe IRTC base address pointer
compValCompensation value is a 2's complement value.
compIntervalCompensation interval.
void IRTC_HAL_SetFineCompensation ( RTC_Type *  base,
uint8_t  integralVal,
uint8_t  fracVal,
bool  accumulateFrac 
)
Parameters
baseThe IRTC base address pointer
integralValCompensation integral value is a twos complement value of the integer part.
fracValCompensation fraction value expressed as number of clock cycles of a fixed 4.194304Mhz clock that have to be added.
accumulateFracFlag indicating if we want to add to previous fractional part; true: accumulate fractional part, false: start afresh and overwrite current value
static void IRTC_HAL_SetClockOutMode ( RTC_Type *  base,
irtc_clock_output_t  clock 
)
inlinestatic
Parameters
baseThe IRTC base address pointer.
clockOUtput clock selection from list of irtc_clock_output_t.
static void IRTC_HAL_SoftwareReset ( RTC_Type *  base)
inlinestatic

This clears the contents of alarm, interrupt (status and enable except tamper interrupt enable bit) registers, STATUS[CMP_DONE], and STATUS[BUS_ERR] and has no effect on DST, calendaring, standby time, and tamper detect registers.

Parameters
baseThe IRTC base address pointer
void IRTC_HAL_ConfigTamperParams ( RTC_Type *  base,
irtc_tamper_pins_t  tamperNum,
irtc_tamper_config_t tamperConfig 
)

The function configures the filter properties for the three external tampers i.e., 0, 1, and 2. It also sets up active/passive and direction of the tamper bits, which are not available on all platforms. NOTE: This function programs the tamper filter parameters. The user must gate the 32 K clock to the RTC before calling this function. It is assumed that the time and date are set after this and the tamper parameters do not require to be changed again later.

Parameters
baseThe IRTC base address pointer
tamperNumThe IRTC tamper input to configure
tamperConfigThe IRTC tamper properties
static void IRTC_HAL_EnableTamper ( RTC_Type *  base)
inlinestatic

The function should be called after all required tamper features have been configured by calling the IRTC_HAL_ConfigTamperParams functions.

Parameters
baseThe IRTC base address pointer
static void IRTC_HAL_DisableTamper ( RTC_Type *  base)
inlinestatic
Parameters
baseThe IRTC base address pointer