All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
WDOG: Watchdog Timer Driver

## Overview

The KSDK provides a peripheral driver for the Watchdog module (WDOG) of Kinetis devices.

# Typical use case

wdog_config_t config;
WDOG_GetDefaultConfig(&config);
config.timeoutValue = 0x7ffU;
config.enableWindowMode = true;
config.windowValue = 0x1ffU;
WDOG_Init(wdog_base,&config);

## Data Structures

struct | wdog_work_mode_t
| Defines WDOG work mode. More...
struct | wdog_config_t
| Describes WDOG configuration structure. More...
struct | wdog_test_config_t
| Describes WDOG test mode configuration structure. More...

## Enumerations

enum | wdog_clock_source_t { kWDOG_LpoClockSource = 0U, kWDOG_AlternateClockSource = 1U }
| Describes WDOG clock source. More...
enum | wdog_clock_prescaler_t { kWDOG_ClockPrescalerDivide1 = 0x0U, kWDOG_ClockPrescalerDivide2 = 0x1U, kWDOG_ClockPrescalerDivide3 = 0x2U, kWDOG_ClockPrescalerDivide4 = 0x3U, kWDOG_ClockPrescalerDivide5 = 0x4U, kWDOG_ClockPrescalerDivide6 = 0x5U, kWDOG_ClockPrescalerDivide7 = 0x6U, kWDOG_ClockPrescalerDivide8 = 0x7U }
| Describes the selection of the clock prescaler. More...
enum | wdog_test_mode_t { kWDOG_QuickTest = 0U, kWDOG_ByteTest = 1U }
| Describes WDOG test mode. More...
enum | wdog_tested_byte_t { kWDOG_TestByte0 = 0U, kWDOG_TestByte1 = 1U, kWDOG_TestByte2 = 2U, kWDOG_TestByte3 = 3U }
| Describes WDOG tested byte selection in byte test mode. More...
enum | _wdog_interrupt_enable_t { kWDOG_InterruptEnable = WDOG_STCTRLH_IRQRSTEN_MASK }
| WDOG interrupt configuration structure, default settings all disabled. More...
enum | _wdog_status_flags_t { kWDOG_RunningFlag = WDOG_STCTRLH_WDOGEN_MASK, kWDOG_TimeoutFlag = WDOG_STCTRLL_INTFLG_MASK }
| WDOG status flags. More...

## Driver version

#define | FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
| Defines WDOG driver version 2.0.0. More...

## Unlock sequence

#define | WDOG_FIRST_WORD_OF_UNLOCK (0xC520U)
| First word of unlock sequence.
#define | WDOG_SECOND_WORD_OF_UNLOCK (0xD928U)
| Second word of unlock sequence.

## Refresh sequence

#define | WDOG_FIRST_WORD_OF_REFRESH (0xA602U)
| First word of refresh sequence.
#define | WDOG_SECOND_WORD_OF_REFRESH (0xB480U)
| Second word of refresh sequence.

## WDOG Initialization and De-initialization

void | WDOG_GetDefaultConfig (wdog_config_t *config)
| Initializes WDOG configure sturcture. More...
void | WDOG_Init (WDOG_Type *base, const wdog_config_t *config)
| Initializes the WDOG. More...
void | WDOG_Deinit (WDOG_Type *base)
| Shuts down the WDOG. More...
void | WDOG_SetTestModeConfig (WDOG_Type *base, wdog_test_config_t *config)
| Configures WDOG functional test. More...

## WDOG Functional Operation

static void | WDOG_Enable (WDOG_Type *base)
| Enables the WDOG module. More...
static void | WDOG_Disable (WDOG_Type *base)
| Disables the WDOG module. More...
static void | WDOG_EnableInterrupts (WDOG_Type *base, uint32_t mask)
| Enable WDOG interrupt. More...
static void | WDOG_DisableInterrupts (WDOG_Type *base, uint32_t mask)
| Disable WDOG interrupt. More...
uint32_t | WDOG_GetStatusFlags (WDOG_Type *base)
| Gets WDOG all status flags. More...
void | WDOG_ClearStatusFlags (WDOG_Type *base, uint32_t mask)
| Clear WDOG flag. More...
static void | WDOG_SetTimeoutValue (WDOG_Type *base, uint32_t timeoutCount)
| Set the WDOG timeout value. More...
static void | WDOG_SetWindowValue (WDOG_Type *base, uint32_t windowValue)
| Sets the WDOG window value. More...
static void | WDOG_Unlock (WDOG_Type *base)
| Unlocks the WDOG register written. More...
void | WDOG_Refresh (WDOG_Type *base)
| Refreshes the WDOG timer. More...
static uint16_t | WDOG_GetResetCount (WDOG_Type *base)
| Gets the WDOG reset count. More...
static void | WDOG_ClearResetCount (WDOG_Type *base)
| Clears the WDOG reset count. More...

## Data Structure Documentation

struct wdog_work_mode_t

### Data Fields

bool | enableStop
| Enables or disables WDOG in stop mode.
bool | enableDebug
| Enables or disables WDOG in debug mode.

struct wdog_config_t

### Data Fields

bool | enableWdog
| Enables or disables WDOG.
wdog_clock_source_t | clockSource
| Clock source select.
wdog_clock_prescaler_t | prescaler
| Clock prescaler value.
wdog_work_mode_t | workMode
| Configures WDOG work mode in debug stop and wait mode.
bool | enableUpdate
| Update write-once register enable.
bool | enableInterrupt
| Enables or disables WDOG interrupt.
bool | enableWindowMode
| Enables or disables WDOG window mode.
uint32_t | windowValue
| Window value.
uint32_t | timeoutValue
| Timeout value.

struct wdog_test_config_t

### Data Fields

wdog_test_mode_t | testMode
| Selects test mode.
wdog_tested_byte_t | testedByte
| Selects tested byte in byte test mode.
uint32_t | timeoutValue
| Timeout value.

## Macro Definition Documentation

#define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))

## Enumeration Type Documentation

enum wdog_clock_source_t

Enumerator
kWDOG_LpoClockSource | WDOG clock sourced from LPO.
kWDOG_AlternateClockSource | WDOG clock sourced from alternate clock source.

enum wdog_clock_prescaler_t

Enumerator
kWDOG_ClockPrescalerDivide1 | Divided by 1.
kWDOG_ClockPrescalerDivide2 | Divided by 2.
kWDOG_ClockPrescalerDivide3 | Divided by 3.
kWDOG_ClockPrescalerDivide4 | Divided by 4.
kWDOG_ClockPrescalerDivide5 | Divided by 5.
kWDOG_ClockPrescalerDivide6 | Divided by 6.
kWDOG_ClockPrescalerDivide7 | Divided by 7.
kWDOG_ClockPrescalerDivide8 | Divided by 8.

enum wdog_test_mode_t

Enumerator
kWDOG_QuickTest | Selects quick test.
kWDOG_ByteTest | Selects byte test.

enum wdog_tested_byte_t

Enumerator
kWDOG_TestByte0 | Byte 0 selected in byte test mode.
kWDOG_TestByte1 | Byte 1 selected in byte test mode.
kWDOG_TestByte2 | Byte 2 selected in byte test mode.
kWDOG_TestByte3 | Byte 3 selected in byte test mode.

enum _wdog_interrupt_enable_t

This structure contains the settings for all of the WDOG interrupt configurations.

Enumerator
kWDOG_InterruptEnable | WDOG timeout generates an interrupt before reset.

enum _wdog_status_flags_t

This structure contains the WDOG status flags for use in the WDOG functions.

Enumerator
kWDOG_RunningFlag | Running flag, set when WDOG is enabled.
kWDOG_TimeoutFlag | Interrupt flag, set when an exception occurs.

## Function Documentation

void WDOG_GetDefaultConfig | ( | wdog_config_t * | config | ) |

This function initializes the WDOG configuration structure to default value. The default values are:

* wdogConfig->enableWdog = true;
* wdogConfig->clockSource = kWDOG_LpoClockSource;
* wdogConfig->prescaler = kWDOG_ClockPrescalerDivide1;
* wdogConfig->workMode.enableWait = true;
* wdogConfig->workMode.enableStop = false;
* wdogConfig->workMode.enableDebug = false;
* wdogConfig->enableUpdate = true;
* wdogConfig->enableInterrupt = false;
* wdogConfig->enableWindowMode = false;
* wdogConfig->windowValue = 0;
* wdogConfig->timeoutValue = 0xFFFFU;
*

Parameters

  config | Pointer to WDOG config structure.

See Also
  wdog_config_t

void WDOG_Init | ( | WDOG_Type * | base,
|  | const wdog_config_t * | config
| ) |  |

This function initializes the WDOG. When called, the WDOG runs according to the configuration. If user wants to reconfigure WDOG without forcing a reset first, enableUpdate must be set to true in configuration.

Example:

* wdog_config_t config;
* WDOG_GetDefaultConfig(&config);
* config.timeoutValue = 0x7ffU;
* config.enableUpdate = true;
* WDOG_Init(wdog_base,&config);
*

Parameters

  base | WDOG peripheral base address
  config | The configuration of WDOG

void WDOG_Deinit | ( | WDOG_Type * | base | ) |

This function shuts down the WDOG. Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.

void WDOG_SetTestModeConfig | ( | WDOG_Type * | base,
|  | wdog_test_config_t * | config
| ) |  |

This function is used to configure the WDOG functional test. When called, the WDOG goes into test mode and runs according to the configuration. Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.

Example:

* wdog_test_config_t test_config;
* test_config.testMode = kWDOG_QuickTest;
* test_config.timeoutValue = 0xfffffu;
* WDOG_SetTestModeConfig(wdog_base, &test_config);
*

Parameters

  base | WDOG peripheral base address
  config | The functional test configuration of WDOG

static void WDOG_Enable | ( | WDOG_Type * | base | ) |

inlinestatic

This function write value into WDOG_STCTRLH register to enable the WDOG, it is a write-once register, make sure that the WCT window is still open and this register has not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address

static void WDOG_Disable | ( | WDOG_Type * | base | ) |

inlinestatic

This function write value into WDOG_STCTRLH register to disable the WDOG, it is a write-once register, make sure that the WCT window is still open and this register has not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address

static void WDOG_EnableInterrupts | ( | WDOG_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

This function write value into WDOG_STCTRLH register to enable WDOG interrupt, it is a write-once register, make sure that the WCT window is still open and this register has not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address

  mask

  The interrupts to enable The parameter can be combination of the following source if defined:
  - kWDOG_InterruptEnable

static void WDOG_DisableInterrupts | ( | WDOG_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

This function write value into WDOG_STCTRLH register to disable WDOG interrupt, it is a write-once register, make sure that the WCT window is still open and this register has not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address

  mask

  The interrupts to disable The parameter can be combination of the following source if defined:
  - kWDOG_InterruptEnable

uint32_t WDOG_GetStatusFlags | ( | WDOG_Type * | base | ) |

This function gets all status flags.

Example for getting Running Flag:

* uint32_t status;
* status = WDOG_GetStatusFlags(wdog_base) & kWDOG_RunningFlag;
*

Parameters

  base | WDOG peripheral base address

Returns
  State of the status flag: asserted (true) or not-asserted (false).

See Also
  _wdog_status_flags_t
  - true: a related status flag has been set.
  - false: a related status flag is not set.

void WDOG_ClearStatusFlags | ( | WDOG_Type * | base,
|  | uint32_t | mask
| ) |  |

This function clears WDOG status flag.

Example for clearing timeout(interrupt) flag:

* WDOG_ClearStatusFlags(wdog_base,kWDOG_TimeoutFlag);
*

Parameters

  base | WDOG peripheral base address
  mask | The status flags to clear. The parameter could be any combination of the following values: kWDOG_TimeoutFlag

static void WDOG_SetTimeoutValue | ( | WDOG_Type * | base,
|  | uint32_t | timeoutCount
| ) |  |

inlinestatic

This function sets the timeout value. It should be ensured that the time-out value for the WDOG is always greater than 2xWCT time + 20 bus clock cycles. This function write value into WDOG_TOVALH and WDOG_TOVALL registers which are wirte-once. Make sure the WCT window is still open and these two registers have not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address
  timeoutCount | WDOG timeout value, count of WDOG clock tick.

static void WDOG_SetWindowValue | ( | WDOG_Type * | base,
|  | uint32_t | windowValue
| ) |  |

inlinestatic

This function sets the WDOG window value. This function write value into WDOG_WINH and WDOG_WINL registers which are wirte-once. Make sure the WCT window is still open and these two registers have not been written in this WCT while this function is called.

Parameters

  base | WDOG peripheral base address
  windowValue | WDOG window value.

static void WDOG_Unlock | ( | WDOG_Type * | base | ) |

inlinestatic

This function unlocks the WDOG register written. Before starting the unlock sequence and following congfiguration, disable the global interrupts. Otherwise, an interrupt could effectively invalidate the unlock sequence and the WCT may expire, After the configuration finishes, re-enable the global interrupts.

Parameters

  base | WDOG peripheral base address

void WDOG_Refresh | ( | WDOG_Type * | base | ) |

This function feeds the WDOG. This function should be called before WDOG timer is in timeout. Otherwise, a reset is asserted.

Parameters

  base | WDOG peripheral base address

static uint16_t WDOG_GetResetCount | ( | WDOG_Type * | base | ) |

inlinestatic

This function gets the WDOG reset count value.

Parameters

  base | WDOG peripheral base address

Returns
  WDOG reset count value

static void WDOG_ClearResetCount | ( | WDOG_Type * | base | ) |

inlinestatic

This function clears the WDOG reset count value.

Parameters

  base | WDOG peripheral base address