14.10.3.1.2 Code

Add to the main application source file, outside of any functions:

struct rtc_module rtc_instance;
struct dma_resource example_resource;
COMPILER_ALIGNED(16)
DmacDescriptor example_descriptor SECTION_DMAC_DESCRIPTOR;
The following must be added to the user application: Function for setting up the module:
void configure_rtc(void)
{
    struct rtc_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);

    struct rtc_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);
}
Callback function:
void rtc_tamper_callback(void)
{
    /* Do something on RTC tamper capture here */
    LED_On(LED_0_PIN);
}
Function for setting up the callback functionality of the driver:
void configure_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);
}
Add to user application initialization (typically the start of main()):
/* 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 */
}