15.9.2.2.1 Code
Create an rtc_module struct and add to the main application source file, outside of any functions:
The following must be added to the user application:structrtc_module rtc_instance;
Function for setting up the module:
Callback function:voidconfigure_rtc_calendar(void){/* Initialize RTC in calendar mode. */structrtc_calendar_config config_rtc_calendar;rtc_calendar_get_config_defaults(&config_rtc_calendar);alarm.time.year = 2013;alarm.time.month = 1;alarm.time.day = 1;alarm.time.hour = 0;alarm.time.minute = 0;alarm.time.second = 4;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;rtc_calendar_init(&rtc_instance, RTC, &config_rtc_calendar);rtc_calendar_enable(&rtc_instance);}
Function for setting up the callback functionality of the driver:voidrtc_match_callback(void){/* Do something on RTC alarm match here */port_pin_toggle_output_level(LED_0_PIN);/* Set new alarm in 5 seconds */alarm.mask = RTC_CALENDAR_ALARM_MASK_SEC;alarm.time.second += 5;alarm.time.second = alarm.time.second % 60;rtc_calendar_set_alarm(&rtc_instance, &alarm, RTC_CALENDAR_ALARM_0);}
Add to user application main():voidconfigure_rtc_callbacks(void){rtc_calendar_register_callback(&rtc_instance, rtc_match_callback, RTC_CALENDAR_CALLBACK_ALARM_0);rtc_calendar_enable_callback(&rtc_instance, RTC_CALENDAR_CALLBACK_ALARM_0);}
system_init();structrtc_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 RTC */configure_rtc_calendar();/* Configure and enable callback */configure_rtc_callbacks();/* Set current time. */rtc_calendar_set_time(&rtc_instance, &time);
