14.10.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_count(void){structrtc_count_config config_rtc_count;rtc_count_get_config_defaults(&config_rtc_count);config_rtc_count.prescaler = RTC_COUNT_PRESCALER_DIV_1;config_rtc_count.mode = RTC_COUNT_MODE_16BIT;#ifdef FEATURE_RTC_CONTINUOUSLY_UPDATEDconfig_rtc_count.continuously_update =true;#endifrtc_count_init(&rtc_instance, RTC, &config_rtc_count);rtc_count_enable(&rtc_instance);}
Function for setting up the callback functionality of the driver:voidrtc_overflow_callback(void){/* Do something on RTC overflow here */port_pin_toggle_output_level(LED_0_PIN);}
Add to user application main():voidconfigure_rtc_callbacks(void){rtc_count_register_callback(&rtc_instance, rtc_overflow_callback, RTC_COUNT_CALLBACK_OVERFLOW);rtc_count_enable_callback(&rtc_instance, RTC_COUNT_CALLBACK_OVERFLOW);}
/* Initialize system. Must configure conf_clocks.h first. */system_init();/* Configure and enable RTC */configure_rtc_count();/* Configure and enable callback */configure_rtc_callbacks();/* Set period */rtc_count_set_period(&rtc_instance, 2000);
