Description

u8_set_app_watchdog_time_sec() allows to configure the watchdog time after which the watchdog will reset the device in case it does not get triggered by the application in time. [seconds] – default: 0 (off)
The bootloader will start (if set > 0) the watchdog right before it jumps into the application, meaning the watchdog is not active in bootloader mode.

Syntax

u8_set_app_watchdog_time_sec( ou8_new_app_wdog_time );

Parameters

uint8_t ou8_new_app_wdog_time: the watchdog time in seconds [0, 1, 2, 4, 8, 16]

The value 0 switches the watchdog off (it will not be started by the bootloader). Range is 0, 1, 2, 4, 8 or 16 seconds.

Returns

uint8_t return value meaning:
0 – setting changed (accepted).
2 – the value ou8_new_app_wdog_time is out of range (0, 1, 2, 4, 8 or 16)

Example Code

This example shows how to read, set and store the ‘application watchdog time’ of the bootloader settings and how to trigger the watchdog.

void setup()
{  
  Serial.begin();
  while (!Serial) 
  {
    yield(); // wait for PC CAN2SER-monitor to open 
  }
  
  Serial.println("Current bootloader settings:");
  Serial.print(" - app. watchdog:   ");
  if(BOOTLOADER_SETTING.u8_get_app_watchdog_time_sec() != 0)
    Serial.println( String( BOOTLOADER_SETTING.u8_get_app_watchdog_time_sec() ) + "sec");
  else
    Serial.println( String("off"));
  
  delay(2000);
  Serial.println("Modify the settings");
  BOOTLOADER_SETTING.u8_set_app_watchdog_time_sec(8);
  
  delay(2000);
  Serial.println("Store the settings in flash");
  
  uint8_t u8_ret = BOOTLOADER_SETTING.u8_store_bootloader_settings();
  
  if(u8_ret != 0)
	Serial.println("Error writing into flash");
  
  Serial.println("DONE");
}

void loop () 
{
  BOOTLOADER_SETTING.u8_trigger_wdog();
}

Notes and Warnings

Don’t forget to call the function u8_store_bootloader_settings() to write the changed settings into flash, so that the bootloader (and app.) has the new values at the next system start / reset.

The watchdog is a useful measure to make an application more failsafe, particularly in situations where the device runs unsupervised or at a location that is hard to reach. Still if you make use of it always make sure that the application will trigger the watchdog in time. Pay particular attention if you are using libraries that do not do trigger the watchdog and that might have function return times that are longer or hard to predict.

Use the function u8_trigger_wdog() to trigger the watchdog regularly.

See also

u8_store_bootloader_settings()
u8_trigger_wdog()
u8_get_app_watchdog_time_sec()
SAMC21_CAN