15.9.2.2.2 Workflow
- Initialize system.
system_init();
- Create and initialize a time structure.
struct
rtc_calendar_time time;
rtc_calendar_get_time_defaults(&time);
time.year = 2012;
time.month = 12;
time.day = 31;
time.hour = 23;
time.minute = 59;
time.second = 59;
- Configure and enable module.
configure_rtc_calendar();
- Create a RTC configuration structure to hold the desired RTC driver settings and fill it with the default driver configuration values.
struct
rtc_calendar_config config_rtc_calendar;
rtc_calendar_get_config_defaults(&config_rtc_calendar);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Create and initialize an alarm.
alarm.time.year = 2013;
alarm.time.month = 1;
alarm.time.day = 1;
alarm.time.hour = 0;
alarm.time.minute = 0;
alarm.time.second = 4;
- Change settings in the configuration and set alarm.
config_rtc_calendar.clock_24h =
true
;
config_rtc_calendar.alarm[0].time = alarm.time;
config_rtc_calendar.alarm[0].mask = RTC_CALENDAR_ALARM_MASK_YEAR;
- Initialize the module with the set configurations.
rtc_calendar_init(&rtc_instance, RTC, &config_rtc_calendar);
- Enable the module.
rtc_calendar_enable(&rtc_instance);
- Configure callback functionality.
configure_rtc_callbacks();
- Register overflow callback.
rtc_calendar_register_callback(
&rtc_instance, rtc_match_callback, RTC_CALENDAR_CALLBACK_ALARM_0);
- Enable overflow callback.
rtc_calendar_enable_callback(&rtc_instance, RTC_CALENDAR_CALLBACK_ALARM_0);
- Set time of the RTC calendar.
rtc_calendar_set_time(&rtc_instance, &time);