15.9.2.2.2 Workflow

  1. Initialize system.
    system_init();
    
  2. 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;
    
  3. Configure and enable module.
    configure_rtc_calendar();
    
    1. 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.
    2. 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;
      
    3. 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;
      
    4. Initialize the module with the set configurations.
      rtc_calendar_init(&rtc_instance, RTC, &config_rtc_calendar);
      
    5. Enable the module.
      rtc_calendar_enable(&rtc_instance);
      
  4. Configure callback functionality.
    configure_rtc_callbacks();
    
    1. Register overflow callback.
      rtc_calendar_register_callback(
              &rtc_instance, rtc_match_callback, RTC_CALENDAR_CALLBACK_ALARM_0);
      
    2. Enable overflow callback.
      rtc_calendar_enable_callback(&rtc_instance, RTC_CALENDAR_CALLBACK_ALARM_0);
      
  5. Set time of the RTC calendar.
    rtc_calendar_set_time(&rtc_instance, &time);