14.10.2.2.2 Workflow

  1. Initialize system.
    system_init();
    
  2. Configure and enable module.
    configure_rtc_count();
    
  3. Create a RTC configuration structure to hold the desired RTC driver settings and fill it with the default driver configuration values.
    struct rtc_count_config config_rtc_count;
    rtc_count_get_config_defaults(&config_rtc_count);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  4. Alter the RTC driver configuration to run in 16-bit counting mode, with continuous counter register updates and a compare value of 1000ms.
    config_rtc_count.prescaler           = RTC_COUNT_PRESCALER_DIV_1;
    config_rtc_count.mode                = RTC_COUNT_MODE_16BIT;
    #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
        config_rtc_count.continuously_update = true;
    #endif
    
  5. Initialize the RTC module.
    rtc_count_init(&rtc_instance, RTC, &config_rtc_count);
    
  6. Enable the RTC module, so that it may begin counting.
    rtc_count_enable(&rtc_instance);
    
  7. Configure callback functionality.
    configure_rtc_callbacks();
    
    1. Register overflow callback.
      rtc_count_register_callback(
              &rtc_instance, rtc_overflow_callback, RTC_COUNT_CALLBACK_OVERFLOW);
      
    2. Enable overflow callback.
      rtc_count_enable_callback(&rtc_instance, RTC_COUNT_CALLBACK_OVERFLOW);
      
  8. Set period.
    rtc_count_set_period(&rtc_instance, 2000);