MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
WDOG: Watchdog Timer Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Watchdog module (WDOG) of MCUXpresso SDK devices.

Typical use case

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/wdog

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 the WDOG configuration 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 the 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)
 Enables the WDOG interrupt. More...
 
static void WDOG_DisableInterrupts (WDOG_Type *base, uint32_t mask)
 Disables the WDOG interrupt. More...
 
uint32_t WDOG_GetStatusFlags (WDOG_Type *base)
 Gets the WDOG all status flags. More...
 
void WDOG_ClearStatusFlags (WDOG_Type *base, uint32_t mask)
 Clears the WDOG flag. More...
 
static void WDOG_SetTimeoutValue (WDOG_Type *base, uint32_t timeoutCount)
 Sets 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

Enumerator
kWDOG_LpoClockSource 

WDOG clock sourced from LPO.

kWDOG_AlternateClockSource 

WDOG clock sourced from alternate clock source.

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.

Enumerator
kWDOG_QuickTest 

Selects quick test.

kWDOG_ByteTest 

Selects byte test.

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.

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

Enumerator
kWDOG_InterruptEnable 

WDOG timeout generates an interrupt before reset.

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 values. The default values are as follows.

* 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
configPointer to the WDOG configuration 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. To reconfigure WDOG without forcing a reset first, enableUpdate must be set to true in the configuration.

This is an example.

* wdog_config_t config;
* config.timeoutValue = 0x7ffU;
* config.enableUpdate = true;
* WDOG_Init(wdog_base,&config);
*
Parameters
baseWDOG peripheral base address
configThe configuration of WDOG
void WDOG_Deinit ( WDOG_Type *  base)

This function shuts down the WDOG. Ensure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which indicates 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. Ensure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.

This is an example.

* wdog_test_config_t test_config;
* test_config.testMode = kWDOG_QuickTest;
* test_config.timeoutValue = 0xfffffu;
* WDOG_SetTestModeConfig(wdog_base, &test_config);
*
Parameters
baseWDOG peripheral base address
configThe 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
baseWDOG peripheral base address
static void WDOG_Disable ( WDOG_Type *  base)
inlinestatic

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

Parameters
baseWDOG peripheral base address
static void WDOG_EnableInterrupts ( WDOG_Type *  base,
uint32_t  mask 
)
inlinestatic

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

Parameters
baseWDOG peripheral base address
maskThe 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 writes a value into the WDOG_STCTRLH register to disable the WDOG interrupt. It is a write-once register. Ensure that the WCT window is still open and the register has not been written to in this WCT while the function is called.

Parameters
baseWDOG peripheral base address
maskThe 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.

This is an example for getting the Running Flag.

* uint32_t status;
* status = WDOG_GetStatusFlags (wdog_base) & kWDOG_RunningFlag;
*
Parameters
baseWDOG 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 the WDOG status flag.

This is an example for clearing the timeout (interrupt) flag.

Parameters
baseWDOG peripheral base address
maskThe 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 writes a value into WDOG_TOVALH and WDOG_TOVALL registers which are wirte-once. Ensure the WCT window is still open and the two registers have not been written to in this WCT while the function is called.

Parameters
baseWDOG peripheral base address
timeoutCountWDOG 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 writes a value into WDOG_WINH and WDOG_WINL registers which are wirte-once. Ensure the WCT window is still open and the two registers have not been written to in this WCT while the function is called.

Parameters
baseWDOG peripheral base address
windowValueWDOG 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 may invalidate the unlocking sequence and the WCT may expire. After the configuration finishes, re-enable the global interrupts.

Parameters
baseWDOG peripheral base address
void WDOG_Refresh ( WDOG_Type *  base)

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

Parameters
baseWDOG peripheral base address
static uint16_t WDOG_GetResetCount ( WDOG_Type *  base)
inlinestatic

This function gets the WDOG reset count value.

Parameters
baseWDOG 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
baseWDOG peripheral base address