27.8.2.1.3 Workflow

  1. Configure and enable the Watchdog driver.
    1. Create a Watchdog module configuration struct, which can be filled out to adjust the configuration of the Watchdog.
      struct wdt_conf config_wdt;
      
    2. Initialize the Watchdog configuration struct with the module's default values.
      wdt_get_config_defaults(&config_wdt);
      
      Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Adjust the configuration struct to set the timeout and early warning periods of the Watchdog.
      config_wdt.always_on            = false;
      #if !((SAML21) || (SAMC21) || (SAML22))
          config_wdt.clock_source         = GCLK_GENERATOR_4;
      #endif
          config_wdt.timeout_period       = WDT_PERIOD_4096CLK;
      config_wdt.early_warning_period = WDT_PERIOD_2048CLK;
      
    4. Sets up the WDT hardware module with the requested settings.
      wdt_set_config(&config_wdt);
      
  2. Register and enable the Early Warning callback handler.
    1. Register the user-provided Early Warning callback function with the driver, so that it will be run when an Early Warning condition occurs.
      wdt_register_callback(watchdog_early_warning_callback,
          WDT_CALLBACK_EARLY_WARNING);
      
    2. Enable the Early Warning callback so that it will generate callbacks.
      wdt_enable_callback(WDT_CALLBACK_EARLY_WARNING);