14.10.3.1.2 Code
Add to the main application source file, outside of any functions:
structrtc_module rtc_instance;
structdma_resource example_resource;
The following must be added to the user application: Function for setting up the module:COMPILER_ALIGNED(16)DmacDescriptor example_descriptor SECTION_DMAC_DESCRIPTOR;
Callback function:voidconfigure_rtc(void){structrtc_count_config config_rtc_count;rtc_count_get_config_defaults(&config_rtc_count);config_rtc_count.prescaler = RTC_COUNT_PRESCALER_DIV_1;rtc_count_init(&rtc_instance, RTC, &config_rtc_count);structrtc_tamper_config config_rtc_tamper;rtc_tamper_get_config_defaults(&config_rtc_tamper);config_rtc_tamper.dma_tamper_enable =true;config_rtc_tamper.in_cfg[0].level = RTC_TAMPER_LEVEL_RISING;config_rtc_tamper.in_cfg[0].action = RTC_TAMPER_INPUT_ACTION_CAPTURE;rtc_tamper_set_config(&rtc_instance, &config_rtc_tamper);rtc_count_enable(&rtc_instance);}
Function for setting up the callback functionality of the driver:voidrtc_tamper_callback(void){/* Do something on RTC tamper capture here */LED_On(LED_0_PIN);}
Add to user application initialization (typically the start of main()):voidconfigure_rtc_callbacks(void){rtc_count_register_callback(&rtc_instance, rtc_tamper_callback, RTC_COUNT_CALLBACK_TAMPER);rtc_count_enable_callback(&rtc_instance, RTC_COUNT_CALLBACK_TAMPER);}
/* Initialize system. Must configure conf_clocks.h first. */system_init();/* Configure and enable RTC */configure_rtc();/* Configure and enable callback */configure_rtc_callbacks();configure_dma_resource(&example_resource);setup_transfer_descriptor(&example_descriptor);dma_add_descriptor(&example_resource, &example_descriptor);while(true) {/* Infinite while loop */}
