| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures
WDOG Peripheral Driver
Watchdog Timer (WDOG)

The section describes the programming interface of the WDOG Peripheral driver. More...

## Data Structures
struct | wdog_user_config_t
| Data struct for watchdog initialize. More...

## Watchdog Driver
void | wdog_init (const wdog_user_config_t *init_ptr)
| Initialize watchdog. More...
void | wdog_shutdown (void)
| Shutdown watchdog. More...
void | wdog_refresh (void)
| Refresh watchdog. More...
void | wdog_clear_reset_count (void)
| Clear watchdog reset count. More...
bool | wdog_is_running (void)
| Get watchdog running status. More...
void | wdog_reset_chip (void)
| Reset chip by watchdog. More...
uint32_t | wdog_get_reset_count (void)
| Get chip reset count that reset by watchdog. More...

### WDOG Peripheral Driver

# Overview

The WDOG driver is used to configure WDOG. It provides an easy way to make necessary module initializations and configure WDOG.

# Initialization

To initialize the WDOG module, call wdog_init() and pass in the initialization data structure. This function enables the WDOG module and clock automatically.
After wdog_init() is called, the WDOG is enabled and its count is working, so wdog_refresh() should be called before WDOG times out.This is example code for initializing and configuring the driver:
// Define device configuration.
const wdog_init_t wdogInit =
{
.clockSource = kWdogDedicatedClock, // Use dedicated clock source,LPO,1K HZ.
.clockPrescaler = kWdogClockPrescaler1, // Clock prescaler is 1.
.timeOutValue = 2048, // Timeout count is 2048.
.wdogCallbackFunc = NULL, // WDOG interrupt callback function is NULL, interrupt is disabled.
.updateRegisterEnable = true, // Enable WDOG register update after first configure.
.cpuWaitModeEnable = true, // Enable WDOG while CPU is in Wait mode.
.cpuStopModeEnable = true, // Enable WDOG while CPU is in Stop mode.
};
// Initialize WDOG.
WDOG_init(&wdogInit);

# WDOG Refresh

After WDOG is enabled, the wdog_refresh() should be called periodically to prevent the WDOG from timing out, or a RESET will assert. This is called "Feed Dog".

# WDOG Reset Count

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

1. wdog_get_reset_count() gets the reset count caused by WDOG timeout.
2. wdog_clear_reset_count() clears the reset count caused by WDOG timeout.

# Reset Chip

The WDOG can be used to reset the chip.

1. wdog_reset_chip() is used to reset the chip whether the WDOG is enabled or not.

## Data Structure Documentation

struct wdog_user_config_t

This structure is used when initialize the WDOG while wdog_init function is called. It contains all configure of the WDOG.

### Data Fields
wdog_clock_source_t | clockSource
| Clock source select.
bool | updateRegisterEnable
| Update write-once register enable.
bool | cpuDebugModeEnable
| Enable watchdog ini cpu debug mode.
bool | cpuWaitModeEnable
| Enable watchdog ini cpu wait mode.
bool | cpuStopModeEnable
| Enable watchdog ini cpu stop mode.
uint32_t | windowValue
| Window value.
uint32_t | timeOutValue
| Timeout value.
wdog_clock_prescaler_t | clockPrescaler
| Clock prescaler.
wdog_isr_callback_t | wdogCallbackFunc
| Isr callback function. More...

#### Field Documentation

wdog_isr_callback_t wdog_user_config_t::wdogCallbackFunc

must in 256 bus cycles.

## Function Documentation

void wdog_init | ( | const wdog_user_config_t * | init_ptr | ) |

This function is used to initialize the WDOG. When called, the WDOG runs immediately according to the configuration.

Parameters

  init_ptr | Watchdog Initialize data structure.

void wdog_shutdown | ( | void |  | ) |

This function is used to shut down the WDOG.

void wdog_refresh | ( | void |  | ) |

This function is used to feed the WDOG. It sets the WDOG timer count to zero and should be called before watchdog timer times out, otherwise a RESET will assert.

void wdog_clear_reset_count | ( | void |  | ) |

This function sets the WDOG reset count to zero. The WDOG_RSTCNT register will only clear on Power On Reset or clear by this function.

bool wdog_is_running | ( | void |  | ) |

This function gets the WDOG running status.

Returns
  watchdog running status, 0 means not running, 1 means running

void wdog_reset_chip | ( | void |  | ) |

This function is used to reset chip using WDOG.

uint32_t wdog_get_reset_count | ( | void |  | ) |

This function gets the WDOG_RSTCNT value.

Returns
  Chip reset count that reset by watchdog.