CC26xx Driver Library
[watchdog.h] Watchdog Timer

Functions

static bool WatchdogRunning (void)
 Determines if the watchdog timer is enabled. More...
 
static void WatchdogEnable (void)
 Enables the watchdog timer. More...
 
static void WatchdogResetEnable (void)
 Enables the watchdog timer reset. More...
 
static void WatchdogResetDisable (void)
 Disables the watchdog timer reset. More...
 
static void WatchdogLock (void)
 Enables the watchdog timer lock mechanism. More...
 
static void WatchdogUnlock (void)
 Disables the watchdog timer lock mechanism. More...
 
static bool WatchdogLockState (void)
 Gets the state of the watchdog timer lock mechanism. More...
 
static void WatchdogReloadSet (uint32_t ui32LoadVal)
 Sets the watchdog timer reload value. More...
 
static uint32_t WatchdogReloadGet (void)
 Gets the watchdog timer reload value. More...
 
static uint32_t WatchdogValueGet (void)
 Gets the current watchdog timer value. More...
 
static void WatchdogIntRegister (void(*pfnHandler)(void))
 Registers an interrupt handler for the watchdog timer interrupt in the dynamic interrupt table. More...
 
static void WatchdogIntUnregister (void)
 Unregisters an interrupt handler for the watchdog timer interrupt in the dynamic interrupt table. More...
 
static void WatchdogIntEnable (void)
 Enables the watchdog timer. More...
 
static uint32_t WatchdogIntStatus (void)
 Gets the current watchdog timer interrupt status. More...
 
static void WatchdogIntClear (void)
 Clears the watchdog timer interrupt. More...
 
static void WatchdogIntTypeSet (uint32_t ui32Type)
 Sets the type of interrupt generated by the watchdog. More...
 
static void WatchdogStallEnable (void)
 Enables stalling of the watchdog timer during debug events. More...
 
static void WatchdogStallDisable (void)
 Disables stalling of the watchdog timer during debug events. More...
 

Detailed Description

Introduction

The Watchdog Timer (WDT) allows the application to regain control if the system stalls due to unexpected software behavior. The WDT can generate a normal interrupt or a non-maskable interrupt on the first time-out and a system reset on the following time-out if the application fails to restart the WDT.

WDT has the following features:

The WDT runs at system HF clock divided by 32; however, when in powerdown it runs at LF clock (32 kHz) - if the LF clock to the MCU domain is enabled.

If application does not restart the WDT, using WatchdogIntClear(), before a time-out:

Note
By default, a "warm reset" triggers a pin reset and thus reboots the device.

A reset caused by the WDT can be detected as a "warm reset" using SysCtrlResetSourceGet(). However, it is not possible to detect which of the warm reset sources that caused the reset.

Typical use case:

API

The API functions can be grouped like this:

Watchdog configuration:

Status:

Interrupt configuration:

Register protection:

Stall configuration for debugging:

Function Documentation

static void WatchdogEnable ( void  )
inlinestatic

Enables the watchdog timer.

This function enables the watchdog timer counter and interrupt.

Once enabled, the watchdog interrupt can only be disabled by a hardware reset.

Note
This function has no effect if the watchdog timer has been locked.
Returns
None
See also
WatchdogLock(), WatchdogUnlock()

Referenced by WatchdogIntEnable().

137 {
138  // Enable the watchdog timer module.
139  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTEN_BITN) = 1;
140 }
static void WatchdogIntClear ( void  )
inlinestatic

Clears the watchdog timer interrupt.

The watchdog timer interrupt source is cleared, so that it no longer asserts.

Note
Due to write buffers and synchronizers in the system it may take several clock cycles from a register write clearing an event in a module and until the event is actually cleared in the NVIC of the system CPU. It is recommended to clear the event source early in the interrupt service routine (ISR) to allow the event clear to propagate to the NVIC before returning from the ISR. At the same time, an early event clear allows new events of the same type to be pended instead of ignored if the event is cleared later in the ISR. It is the responsibility of the programmer to make sure that enough time has passed before returning from the ISR to avoid false re-triggering of the cleared event. A simple, although not necessarily optimal, way of clearing an event before returning from the ISR is:
  1. Write to clear event (interrupt source). (buffered write)
  2. Dummy read from the event source module. (making sure the write has propagated)
  3. Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
Returns
None
430 {
431  // Clear the interrupt source.
433 }
#define WATCHDOG_INT_TIMEOUT
Definition: watchdog.h:86
static void WatchdogIntEnable ( void  )
inlinestatic

Enables the watchdog timer.

This function enables the watchdog timer interrupt by calling WatchdogEnable().

Returns
None
See also
WatchdogEnable()
377 {
378  // Enable the Watchdog interrupt.
379  WatchdogEnable();
380 }
static void WatchdogEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:136

Here is the call graph for this function:

static void WatchdogIntRegister ( void(*)(void)  pfnHandler)
inlinestatic

Registers an interrupt handler for the watchdog timer interrupt in the dynamic interrupt table.

Note
Only use this function if you want to use the dynamic vector table (in SRAM)!

This function registers a function as the interrupt handler for a specific interrupt and enables the corresponding interrupt in the interrupt controller.

The watchdog timer interrupt must be enabled via WatchdogIntEnable(). It is the interrupt handler's responsibility to clear the interrupt source via WatchdogIntClear().

Note
This function registers the standard watchdog interrupt handler. To register the NMI watchdog handler, use IntRegister() to register the handler for the INT_NMI_FAULT interrupt.
Parameters
pfnHandleris a pointer to the function to be called when the watchdog timer interrupt occurs.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
327 {
328  // Register the interrupt handler.
329  IntRegister(INT_WDT_IRQ, pfnHandler);
330 
331  // Enable the watchdog timer interrupt.
332  IntEnable(INT_WDT_IRQ);
333 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:153
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283

Here is the call graph for this function:

static uint32_t WatchdogIntStatus ( void  )
inlinestatic

Gets the current watchdog timer interrupt status.

This function returns the interrupt status for the watchdog timer module.

Returns
Returns the interrupt status.
  • 1 : Watchdog time-out has occurred.
  • 0 : Watchdog time-out has not occurred.
See also
WatchdogIntClear();
397 {
398  // Return either the interrupt status or the raw interrupt status as
399  // requested.
400  return(HWREG(WDT_BASE + WDT_O_RIS));
401 }
static void WatchdogIntTypeSet ( uint32_t  ui32Type)
inlinestatic

Sets the type of interrupt generated by the watchdog.

This function sets the type of interrupt that is generated if the watchdog timer expires.

When configured to generate an NMI, the watchdog interrupt must still be enabled with WatchdogIntEnable(), and it must still be cleared inside the NMI handler with WatchdogIntClear().

Parameters
ui32Typeis the type of interrupt to generate.
Returns
None
455 {
456  // Check the arguments.
457  ASSERT((ui32Type == WATCHDOG_INT_TYPE_INT) ||
458  (ui32Type == WATCHDOG_INT_TYPE_NMI));
459 
460  // Set the interrupt type.
461  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTTYPE_BITN) = (ui32Type == WATCHDOG_INT_TYPE_INT)? 0 : 1;
462 }
#define WATCHDOG_INT_TYPE_NMI
Definition: watchdog.h:94
#define ASSERT(expr)
Definition: debug.h:73
#define WATCHDOG_INT_TYPE_INT
Definition: watchdog.h:93
static void WatchdogIntUnregister ( void  )
inlinestatic

Unregisters an interrupt handler for the watchdog timer interrupt in the dynamic interrupt table.

This function does the actual unregistering of the interrupt handler. This function clears the handler to be called when a watchdog timer interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

Note
This function registers the standard watchdog interrupt handler. To register the NMI watchdog handler, use IntRegister() to register the handler for the INT_NMI_FAULT interrupt.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
356 {
357  // Disable the interrupt.
358  IntDisable(INT_WDT_IRQ);
359 
360  // Unregister the interrupt handler.
361  IntUnregister(INT_WDT_IRQ);
362 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:189
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327

Here is the call graph for this function:

static void WatchdogLock ( void  )
inlinestatic

Enables the watchdog timer lock mechanism.

This function locks out write access to the watchdog timer configuration registers.

Returns
None
196 {
197  // Lock out watchdog register writes. Writing anything to the WDT_O_LOCK
198  // register causes the lock to go into effect.
200 }
#define WATCHDOG_LOCK_LOCKED
Definition: watchdog.h:77
static bool WatchdogLockState ( void  )
inlinestatic

Gets the state of the watchdog timer lock mechanism.

This function returns the lock state of the watchdog timer registers.

Returns
Returns state of lock mechanism.
  • true : Watchdog timer registers are locked.
  • false : Registers are not locked.
232 {
233  // Get the lock state.
234  return((HWREG(WDT_BASE + WDT_O_LOCK) == WATCHDOG_LOCK_LOCKED) ?
235  true : false);
236 }
#define WATCHDOG_LOCK_LOCKED
Definition: watchdog.h:77
static uint32_t WatchdogReloadGet ( void  )
inlinestatic

Gets the watchdog timer reload value.

This function gets the value that is loaded into the watchdog timer when the count reaches zero for the first time.

Returns
None
See also
WatchdogReloadSet()
278 {
279  // Get the load register.
280  return(HWREG(WDT_BASE + WDT_O_LOAD));
281 }
static void WatchdogReloadSet ( uint32_t  ui32LoadVal)
inlinestatic

Sets the watchdog timer reload value.

This function configures the value to load into the watchdog timer when the count reaches zero for the first time; if the watchdog timer is running when this function is called, then the value is immediately loaded into the watchdog timer counter. If the ui32LoadVal parameter is 0, then an interrupt is immediately generated.

Note
This function has no effect if the watchdog timer has been locked.
Parameters
ui32LoadValis the load value for the watchdog timer.
Returns
None
See also
WatchdogLock(), WatchdogUnlock(), WatchdogReloadGet()
259 {
260  // Set the load register.
261  HWREG(WDT_BASE + WDT_O_LOAD) = ui32LoadVal;
262 }
static void WatchdogResetDisable ( void  )
inlinestatic

Disables the watchdog timer reset.

This function disables the capability of the watchdog timer to issue a reset to the processor after a second timeout condition.

Note
This function has no effect if the watchdog timer has been locked.
Returns
None
See also
WatchdogLock(), WatchdogUnlock()
179 {
180  // Disable the watchdog reset.
181  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 0;
182 }
static void WatchdogResetEnable ( void  )
inlinestatic

Enables the watchdog timer reset.

This function enables the capability of the watchdog timer to issue a reset to the processor after a second timeout condition.

Note
This function has no effect if the watchdog timer has been locked.
Returns
None
See also
WatchdogLock(), WatchdogUnlock()
158 {
159  // Enable the watchdog reset.
160  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 1;
161 }
static bool WatchdogRunning ( void  )
inlinestatic

Determines if the watchdog timer is enabled.

This function checks to see if the watchdog timer is enabled.

Returns
Returns status of Watchdog Timer:
  • true : Watchdog timer is enabled.
  • false : Watchdog timer is disabled.
115 {
116  // See if the watchdog timer module is enabled, and return.
117  return((HWREG(WDT_BASE + WDT_O_CTL) & WDT_CTL_INTEN) ? true : false);
118 }
static void WatchdogStallDisable ( void  )
inlinestatic

Disables stalling of the watchdog timer during debug events.

This function disables the debug mode stall of the watchdog timer. By doing so, the watchdog timer continues to count regardless of the processor debug state.

Returns
None
498 {
499  // Disable timer stalling.
500  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 0;
501 }
static void WatchdogStallEnable ( void  )
inlinestatic

Enables stalling of the watchdog timer during debug events.

This function allows the watchdog timer to stop counting when the processor is stopped by the debugger. By doing so, the watchdog is prevented from expiring and resetting the system (if reset is enabled). The watchdog instead expires after the appropriate number of processor cycles have been executed while debugging (or at the appropriate time after the processor has been restarted).

Returns
None
480 {
481  // Enable timer stalling.
482  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 1;
483 }
static void WatchdogUnlock ( void  )
inlinestatic

Disables the watchdog timer lock mechanism.

This function enables write access to the watchdog timer configuration registers.

Returns
None
214 {
215  // Unlock watchdog register writes.
217 }
#define WATCHDOG_LOCK_UNLOCK
Definition: watchdog.h:78
static uint32_t WatchdogValueGet ( void  )
inlinestatic

Gets the current watchdog timer value.

This function reads the current value of the watchdog timer.

Returns
Returns the current value of the watchdog timer.
294 {
295  // Get the current watchdog timer register value.
296  return(HWREG(WDT_BASE + WDT_O_VALUE));
297 }

Macro Definition Documentation

#define WATCHDOG_INT_TIMEOUT   0x00000001

Referenced by WatchdogIntClear().

#define WATCHDOG_INT_TYPE_INT   0x00000000

Referenced by WatchdogIntTypeSet().

#define WATCHDOG_INT_TYPE_NMI   0x00000004

Referenced by WatchdogIntTypeSet().

#define WATCHDOG_LOCK_LOCKED   0x00000001

Referenced by WatchdogLock(), and WatchdogLockState().

#define WATCHDOG_LOCK_UNLOCK   0x1ACCE551

Referenced by WatchdogUnlock().

#define WATCHDOG_LOCK_UNLOCKED   0x00000000