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:
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:
datetimeToSet.
year = 2013;
datetimeToSet.
month = 10;
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.
datetimeToSet.
year = 2013;
datetimeToSet.
month = 10;
alrmTimeToSet.
year = datetimeToSet.
year;
alrmTimeToSet.
day = datetimeToSet.
day;
|
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...
|
|
Enables the IRTC clock and interrupts if requested by the user.
- Parameters
-
instance | The IRTC peripheral instance number. |
datetime | Date and time need to set, pass NULL to ignore. |
alarmDatetime | Alarm of date and time need to set, pass NULL to ignore. |
alarmMode | Alarm mode to set when will generate alarm. |
daylightTime | Daylight saving time need to set, pass NULL to ignore. |
- Returns
- Error or success returned by API.
- Parameters
-
instance | The 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
-
instance | The IRTC peripheral instance number. |
datetime | Pointer 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
-
instance | The IRTC peripheral instance number. |
datetime | Pointer 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
-
instance | The IRTC peripheral instance number. |
alarmType | Alarm match selections that when an alarm will happen. |
static void IRTC_DRV_SetAlarm |
( |
uint32_t |
instance, |
|
|
irtc_datetime_t * |
alarmTime |
|
) |
| |
|
inlinestatic |
- Parameters
-
instance | The IRTC peripheral instance number. |
alarmTime | Pointer to structure where the alarm time is store. |
static void IRTC_DRV_GetAlarm |
( |
uint32_t |
instance, |
|
|
irtc_datetime_t * |
date |
|
) |
| |
|
inlinestatic |
- Parameters
-
instance | The IRTC peripheral instance number. |
date | Pointer 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
-
instance | The IRTC peripheral instance number. |
interrupt | The interrupt name, defined in type irtc_int_t. |
enable | Enable(ture) or disable(false) related interrupt. |
static bool IRTC_DRV_GetIntCmd |
( |
uint32_t |
instance, |
|
|
irtc_int_t |
interrupt |
|
) |
| |
|
inlinestatic |
- Parameters
-
instance | The IRTC peripheral instance number. |
interrupt | The 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.
- Parameters
-
instance | The IRTC peripheral instance number. |
statusFlag | The 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.
Tamper interrupt status flag is cleared when the TAMPER_SCR[TMPR_STS] is cleared.
- Parameters
-
instance | The IRTC peripheral instance number. |
statusFlag | The status flag, defined in type irtc_int_status_flag_t. |
RTC_Type* const g_irtcBase[RTC_INSTANCE_COUNT] |
const IRQn_Type g_irtcIrqId[RTC_INSTANCE_COUNT] |