Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
WDOG Peripheral driver

Overview

This section describes the programming interface of the WDOG Peripheral driver. The WDOG driver configures and initializes the WDOG.

WDOG Initialization

To initialize the WDOG module, call the WDOG_DRV_Init() function and pass in the user configuration structure. This function automatically enables the WDOG module and clock.
After the WDOG_DRV_Init() function is called, the WDOG is enabled and its counter is working. Therefore, the WDOG_DRV_Refresh() function should be called before the WDOG times out.

This example code shows how to initialize and configure the driver:

// Define device configuration.
const wdog_user_config_t init =
{
.clockSource = kWdogClockSourceLpoClock, // WDOG clock source is LPO clock //
.clockPrescalerValue = kWdogClockPrescalerValueDevide1, // Clock prescaler divide by 1 //
.timeoutValue = 2048, // Timeout count is 2048 //
.interruptEnable = false, // Interrupt configure, false means disable interrupt //
.updateRegisterEnable = true, // Enable WDOG register update after first configure //
.workInWaitModeEnable = true, // Enable WDOG while CPU is in Wait mode //
.workInStopModeEnable = true, // Enable WDOG while CPU is in Stop mode //
};
// Initialize WDOG.

WDOG Refresh

After the WDOG is enabled, the WDOG_DRV_Refresh() function should be called periodically to prevent the WDOG from timing out.
Otherwise, a reset is asserted. This is called "Feed Dog".

WDOG Reset Count

The WDOG can record the reset count caused by the WDOG timeout.

  1. WDOG_DRV_GetResetCount() gets the reset count caused by the WDOG timeout.
  2. WDOG_DRV_ClearResetCount() clears the reset count caused by the WDOG timeout.

WDOG Reset System

The WDOG can be used to reset the MCU.

  1. WDOG_DRV_ResetSystem() resets the MCU whether the WDOG is enabled or not.

WDOG interrupt

If the WDOG interrupt is enabled, the WDOG asserts an interrupt and resets the system after 256 bus clock.

  1. Enable the WDOG interrupt with the wdog_user_config_t.interruptEnable = true.
  2. Define the WDOG IRQ function.
void Watchdog_IRQHandler()
{
// Enter WDOG ISR //
}

Watchdog Driver

Data structure for Watchdog initialization

This structure is used when initializing the WDOG during the wdog_init function call. It contains all WDOG configurations.

wdog_status_t WDOG_DRV_Init (const wdog_config_t *userConfigPtr)
 Initializes the Watchdog. More...
 
wdog_status_t WDOG_DRV_Deinit (void)
 Shuts down the Watchdog. More...
 
void WDOG_DRV_Refresh (void)
 Refreshes the Watchdog. More...
 
bool WDOG_DRV_IsRunning (void)
 Gets the Watchdog running status. More...
 
void WDOG_DRV_ResetSystem (void)
 Resets the MCU by using the Watchdog. More...
 

Function Documentation

wdog_status_t WDOG_DRV_Init ( const wdog_config_t userConfigPtr)

This function initializes the WDOG. When called, the WDOG runs according to the requirements of the configuration.

Parameters
userConfigPtrWatchdog user configure data structure, see #wdog_user_config_t.
Returns
kStatus_WDOG_Success means success. Otherwise, means failure.
wdog_status_t WDOG_DRV_Deinit ( void  )

This function shuts down the WDOG.

Returns
kStatus_WDOG_Success means success. Otherwise, means failure.
void WDOG_DRV_Refresh ( void  )

This function feeds the WDOG. It sets the WDOG timer count to zero and should be called before the Watchdog timer times out. Otherwise, a reset is asserted. Enough time should be allowed for the refresh sequence to be detected by the Watchdog timer on the Watchdog clock.

bool WDOG_DRV_IsRunning ( void  )

This function gets the WDOG running status.

Returns
Watchdog running status, false means not running, true means running
void WDOG_DRV_ResetSystem ( void  )

This function resets the MCU by using the WDOG.