Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
WDT_SAM4L - SAM4L Watchdog Timer

Driver for the WDT (Watchdog Timer).

This driver provides access to the main features of the WDT controller. The Watchdog Timer can be used to prevent system lock-up if the software becomes trapped in a deadlock. It can generate a general reset or a processor reset only.

See Quickstart guide for SAM4L watchdog driver.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the WDT_SAM4L - SAM4L Watchdog Timer.
 

Data Structures

struct  wdt_config
 Watchdog Timer configuration structure. More...
 
struct  wdt_dev_inst
 Watchdog Timer driver software instance structure. More...
 

Enumerations

enum  wdt_period {
  WDT_PERIOD_NONE = 0,
  WDT_PERIOD_MIN_CLK = 7,
  WDT_PERIOD_256_CLK = 7,
  WDT_PERIOD_512_CLK = 8,
  WDT_PERIOD_1024_CLK = 9,
  WDT_PERIOD_2048_CLK = 10,
  WDT_PERIOD_4096_CLK = 11,
  WDT_PERIOD_8192_CLK = 12,
  WDT_PERIOD_16384_CLK = 13,
  WDT_PERIOD_32768_CLK = 14,
  WDT_PERIOD_65536_CLK = 15,
  WDT_PERIOD_131072_CLK = 16,
  WDT_PERIOD_262144_CLK = 17,
  WDT_PERIOD_524288_CLK = 18,
  WDT_PERIOD_1048576_CLK = 19,
  WDT_PERIOD_2097152_CLK = 20,
  WDT_PERIOD_4194304_CLK = 21,
  WDT_PERIOD_8388608_CLK = 22,
  WDT_PERIOD_16777216_CLK = 23,
  WDT_PERIOD_33554432_CLK = 24,
  WDT_PERIOD_67108864_CLK = 25,
  WDT_PERIOD_134217728_CLK = 26,
  WDT_PERIOD_268435456_CLK = 27,
  WDT_PERIOD_536870912_CLK = 28,
  WDT_PERIOD_1073741824_CLK = 29,
  WDT_PERIOD_2147483648_CLK = 30,
  WDT_PERIOD_4294967296_CLK = 31,
  WDT_PERIOD_MAX_CLK = 31
}
 Watchdog Timer period configuration enum. More...
 

Functions

void wdt_clear (struct wdt_dev_inst *const dev_inst)
 Restart the watchdog timer. More...
 
static void wdt_clear_interrupt (struct wdt_dev_inst *const dev_inst)
 Clear the WDT module interrupt status. More...
 
void wdt_disable (struct wdt_dev_inst *const dev_inst)
 Disable the WDT module. More...
 
static void wdt_disable_interrupt (struct wdt_dev_inst *const dev_inst)
 Disable the WDT module interrupt. More...
 
void wdt_enable (struct wdt_dev_inst *const dev_inst)
 Enable the WDT module. More...
 
static void wdt_enable_interrupt (struct wdt_dev_inst *const dev_inst)
 Enable the WDT module interrupt. More...
 
void wdt_get_config_defaults (struct wdt_config *const cfg)
 Initializes a Watchdog Timer configuration structure to defaults. More...
 
static uint32_t wdt_get_interrupt_mask (struct wdt_dev_inst *const dev_inst)
 Get the watchdog interrupt mask. More...
 
static uint32_t wdt_get_interrupt_status (struct wdt_dev_inst *const dev_inst)
 Get the watchdog interrupt status. More...
 
static uint32_t wdt_get_status (struct wdt_dev_inst *const dev_inst)
 Get the watchdog timer status. More...
 
bool wdt_init (struct wdt_dev_inst *const dev_inst, Wdt *const wdt, struct wdt_config *const cfg)
 Initialize the WDT module. More...
 
bool wdt_reset_mcu (void)
 Reset MCU by generating a WDT reset as soon as possible. More...
 
static void wdt_set_ctrl (uint32_t ctrl)
 Sets the WatchDog Timer Control register to the ctrl value thanks to the WatchDog Timer key. More...
 
#define WDT_FIRST_KEY   0x55ul
 Watchdog control register first write keys. More...
 
#define WDT_SECOND_KEY   0xAAul
 Watchdog control register second write keys. More...
 

#define WDT_FIRST_KEY   0x55ul

Watchdog control register first write keys.

Referenced by wdt_clear(), and wdt_set_ctrl().

#define WDT_SECOND_KEY   0xAAul

Watchdog control register second write keys.

Referenced by wdt_clear(), and wdt_set_ctrl().

enum wdt_period

Watchdog Timer period configuration enum.

Enum for the possible period settings of the Watchdog timer module, for values requiring a period as a number of Watchdog timer clock ticks.

Formula for Ttimeout = 2pow(PSEL+1) / Fclk_cnt Formula for Ttimeban = 2pow(TBAN+1) / Fclk_cnt

Enumerator
WDT_PERIOD_NONE 
WDT_PERIOD_MIN_CLK 
WDT_PERIOD_256_CLK 
WDT_PERIOD_512_CLK 
WDT_PERIOD_1024_CLK 
WDT_PERIOD_2048_CLK 
WDT_PERIOD_4096_CLK 
WDT_PERIOD_8192_CLK 
WDT_PERIOD_16384_CLK 
WDT_PERIOD_32768_CLK 
WDT_PERIOD_65536_CLK 
WDT_PERIOD_131072_CLK 
WDT_PERIOD_262144_CLK 
WDT_PERIOD_524288_CLK 
WDT_PERIOD_1048576_CLK 
WDT_PERIOD_2097152_CLK 
WDT_PERIOD_4194304_CLK 
WDT_PERIOD_8388608_CLK 
WDT_PERIOD_16777216_CLK 
WDT_PERIOD_33554432_CLK 
WDT_PERIOD_67108864_CLK 
WDT_PERIOD_134217728_CLK 
WDT_PERIOD_268435456_CLK 
WDT_PERIOD_536870912_CLK 
WDT_PERIOD_1073741824_CLK 
WDT_PERIOD_2147483648_CLK 
WDT_PERIOD_4294967296_CLK 
WDT_PERIOD_MAX_CLK 

void wdt_clear ( struct wdt_dev_inst *const  dev_inst)

Restart the watchdog timer.

Parameters
dev_instDevice structure pointer.

References wdt_dev_inst::hw_dev, WDT_FIRST_KEY, and WDT_SECOND_KEY.

static void wdt_clear_interrupt ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Clear the WDT module interrupt status.

Parameters
dev_instDevice structure pointer.

References wdt_dev_inst::hw_dev.

void wdt_disable ( struct wdt_dev_inst *const  dev_inst)

Disable the WDT module.

Parameters
dev_instDevice structure pointer.

References wdt_dev_inst::hw_dev, sysclk_disable_peripheral_clock(), and wdt_set_ctrl().

Referenced by run_wdt_test_all().

static void wdt_disable_interrupt ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Disable the WDT module interrupt.

Parameters
dev_instDevice structure pointer.

References wdt_dev_inst::hw_dev.

void wdt_enable ( struct wdt_dev_inst *const  dev_inst)

Enable the WDT module.

Parameters
dev_instDevice structure pointer.

References wdt_config::always_on, wdt_dev_inst::hw_dev, sysclk_enable_peripheral_clock(), wdt_dev_inst::wdt_cfg, and wdt_set_ctrl().

Referenced by main(), run_wdt_test_all(), and wdt_reset_mcu().

static void wdt_enable_interrupt ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Enable the WDT module interrupt.

Parameters
dev_instDevice structure pointer.

References wdt_dev_inst::hw_dev.

void wdt_get_config_defaults ( struct wdt_config *const  cfg)

Initializes a Watchdog Timer configuration structure to defaults.

Initializes a given Watchdog Timer configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is as follows:

  • Select the RCSYS oscillator as clock source.
  • Not locked, to allow for further (re-)configuration.
  • A timeout period of 131072 clocks of the Watchdog module clock (about 1s).
  • No window period, so that the watchdog count can be reset at any time.
Parameters
cfgConfiguration structure to initialize to default values.

References wdt_config::always_on, Assert, wdt_config::clk_src, wdt_config::disable_flash_cali, wdt_config::disable_wdt_after_reset, wdt_config::timeout_period, WDT_CLK_SRC_RCSYS, wdt_config::wdt_int, WDT_INT_DIS, wdt_config::wdt_mode, WDT_MODE_BASIC, WDT_PERIOD_131072_CLK, WDT_PERIOD_NONE, and wdt_config::window_period.

Referenced by main(), run_wdt_test_all(), and wdt_reset_mcu().

static uint32_t wdt_get_interrupt_mask ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Get the watchdog interrupt mask.

Returns
Bitmask of watchdog interrupt mask.

References wdt_dev_inst::hw_dev.

static uint32_t wdt_get_interrupt_status ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Get the watchdog interrupt status.

Returns
Bitmask of watchdog interrupt status.

References wdt_dev_inst::hw_dev.

static uint32_t wdt_get_status ( struct wdt_dev_inst *const  dev_inst)
inlinestatic

Get the watchdog timer status.

Returns
Bitmask of watchdog timer status.

References wdt_dev_inst::hw_dev.

bool wdt_init ( struct wdt_dev_inst *const  dev_inst,
Wdt *const  wdt,
struct wdt_config *const  cfg 
)

Initialize the WDT module.

Parameters
dev_instDevice structure pointer.
wdtBase address of the WDT instance.
cfgPointer to WDT configuration.
Return values
trueif the initialization was successful.
falseif initialization failed.

References Assert, wdt_config::clk_src, wdt_config::disable_flash_cali, wdt_config::disable_wdt_after_reset, wdt_dev_inst::hw_dev, sysclk_disable_peripheral_clock(), sysclk_enable_peripheral_clock(), wdt_config::timeout_period, wdt_dev_inst::wdt_cfg, wdt_config::wdt_int, wdt_config::wdt_mode, wdt_set_ctrl(), and wdt_config::window_period.

Referenced by main(), run_wdt_test_all(), and wdt_reset_mcu().

bool wdt_reset_mcu ( void  )

Reset MCU by generating a WDT reset as soon as possible.

Note
This function will not work if the SFV bit was previously set (The WDT configuration has previously been locked).
Returns
false Cannot reset MCU with a WDT reset, or the MCU will be reset.

References Disable_global_interrupt, wdt_config::disable_wdt_after_reset, wdt_config::timeout_period, wdt_enable(), wdt_get_config_defaults(), wdt_init(), and WDT_PERIOD_MIN_CLK.

Referenced by main(), and run_wdt_test_all().

static void wdt_set_ctrl ( uint32_t  ctrl)
static

Sets the WatchDog Timer Control register to the ctrl value thanks to the WatchDog Timer key.

Parameters
ctrlValue to set the WatchDog Timer Control register to.

References div_ceil, OSC_RC32K_NOMINAL_HZ, OSC_RCSYS_NOMINAL_HZ, sysclk_get_cpu_hz(), WDT_CLK_SRC_RCSYS, WDT_FIRST_KEY, and WDT_SECOND_KEY.

Referenced by wdt_disable(), wdt_enable(), and wdt_init().