S32 SDK
Real Time Clock Driver (RTC)

Detailed Description

The S32 SDK provides both HAL and Peripheral Driver for the Real Time Clock (RTC) module of S32 SDK devices.
.

Hardware background

The Real Time Clock Module is a independent timer that keeps track of the exact date and time with no software overhead, with low power usage.

Features of the RTC module include:

How to use the RTC driver in your application

In order to be able to use the RTC in your application, the first thing to do is initializing it with the desired configuration. This is done by calling the RTC_DRV_Init function. One of the arguments passed to this function is the configuration which will be used for the RTC instance, specified by the rtc_init_config_t structure.

The rtc_init_config_t structure allows you to configure the following:

The rtc_seconds_int_config_t structure configures the time seconds interrupt. To setup an interrupt every seconds you have to configure the structure mentioned with the following parameters:

An alarm is configured with rtc_alarm_config_t structure, which is described by the following parameters:

Note If the alarm interrupt is not enabled, the user must make the updates of the alarm time manually.

After the RTC_DRV_Init call and, if needed, alarm and other configurations the RTC counter is started by calling RTC_DRV_Enable, with start time as parameter in rtc_timedate_t format.

To get the current time and date you can call RTC_DRV_GetCurrentTimeDate function, this method will get the seconds from the Time Seconds Register and will convert into human readable format as rtc_timedate_t.

Example

void rtcAlarmCallback(void)
{
rtc_timedate_t currentTime;
RTC_DRV_GetCurrentTimeDate(0U, &currentTime);
/* Do something with the time and date */
}
int main()
{
/* rtcTimer1 configuration structure */
const rtc_init_config_t rtcTimer1_Config0 =
{
/* Time compensation interval */
/* Time compensation value */
.compensation = 0,
/* RTC Clock Source is 32 KHz crystal */
.clockSelect = RTC_CLK_SRC_OSC_32KHZ,
/* RTC Clock Out is 32 KHz clock */
.clockOutConfig = RTC_CLKOUT_SRC_32KHZ,
/* Update of the TCE bit is not allowed */
.updateEnable = false,
/* Non-supervisor mode write accesses are not supported and generate
* a bus error.
*/
.nonSupervisorAccessEnable = false
};
/* RTC Initial Time and Date */
rtc_timedate_t rtcStartTime =
{
/* Year */
.year = 2016U,
/* Month */
.month = 01U,
/* Day */
.day = 01U,
/* Hour */
.hour = 00U,
/* Minutes */
.minutes = 00U,
/* Seconds */
.seconds = 00U
};
/* rtcTimer1 Alarm configuration 0 */
rtc_alarm_config_t alarmConfig0 =
{
/* Alarm Date */
{
/* Year */
.year = 2016U,
/* Month */
.month = 01U,
/* Day */
.day = 01U,
/* Hour */
.hour = 00U,
/* Minutes */
.minutes = 00U,
/* Seconds */
.seconds = 03U,
},
/* Alarm repeat interval */
.repetitionInterval = 3UL,
/* Number of alarm repeats */
.numberOfRepeats = 0UL,
/* Repeat alarm forever */
.repeatForever = true,
/* Alarm interrupt disabled */
.alarmIntEnable = true,
/* Alarm interrupt handler */
.alarmCallback = (void *)rtcAlarmCallback,
/* Alarm interrupt handler parameters */
.callbackParams = (void *)NULL
};
/* Call the init function */
RTC_DRV_Init(0UL, &rtcInitConfig);
/* Set the time and date */
RTC_DRV_SetTimeDate(0UL, &rtcStartTime);
/* Start RTC counter */
/* Configure an alarm every 3 seconds */
RTC_DRV_ConfigureAlarm(0UL, &rtcAlarmConfig0);
while(1);
}

Important Notes

Modules

 Real Time Clock Driver
 Real Time Clock Driver Peripheral Driver.
 
 Real Time Clock HAL
 Real Time Clock Hardware Abstraction Layer.