Watchdog driver interface.
The Watchdog header file should be included in an application as follows:
A watchdog timer can be used to generate a reset signal if a system has become unresponsive. The Watchdog driver simplifies configuring and starting the watchdog peripherals. The watchdog peripheral can be configured with resets either on or off and a user-specified timeout period.
When the watchdog peripheral is configured not to generate a reset, it can be used to cause a hardware interrupt at a programmable interval. The driver provides the ability to specify a user-provided callback function that is called when the watchdog causes an interrupt.
The Watchdog driver simplifies configuring and starting the Watchdog peripherals. The Watchdog can be set up to produce a reset signal after a timeout, or simply cause a hardware interrupt at a programmable interval. The driver provides the ability to specify a callback function that is called when the Watchdog causes an interrupt.
When resets are turned on, it is the user application's responsibility to call Watchdog_clear() in order to clear the Watchdog and prevent a reset. Watchdog_clear() can be called at any time.
The Watchdog driver must be initialized by calling Watchdog_init(), before any other Watchdog APIs can be called. Once the watchdog is initialized, a Watchdog object can be created through the following steps:
To have a user-defined function run at the hardware interrupt caused by a watchdog timer timeout, define a function of the following type:
Then pass the function to Watchdog_open() through the Watchdog_Params structure.
An example of the Watchdog creation process that uses a callback function:
If no Watchdog_Params structure is passed to Watchdog_open(), the default values are used. By default, the Watchdog driver has resets turned on, no callback function specified, and stalls the timer at breakpoints during debugging.
Options for the resetMode parameter are Watchdog_RESET_ON and Watchdog_RESET_OFF. The latter allows the watchdog to be used like another timer interrupt. When resetMode is Watchdog_RESET_ON, it is up to the application to call Watchdog_clear() to clear the Watchdog interrupt flag to prevent a reset. Watchdog_clear() can be called at any time.
This module serves as the main interface for TI-RTOS applications. Its purpose is to redirect the module's APIs to specific peripheral implementations which are specified using a pointer to a Watchdog_FxnTable.
The Watchdog driver interface module is joined (at link time) to a NULL-terminated array of Watchdog_Config data structures named Watchdog_config. Watchdog_config is implemented in the application with each entry being an instance of a Watchdog peripheral. Each entry in Watchdog_config contains a:
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | Watchdog_Params_ |
Watchdog Parameters. More... | |
struct | Watchdog_FxnTable_ |
The definition of a Watchdog function table that contains the required set of functions to control a specific Watchdog driver implementation. More... | |
struct | Watchdog_Config_ |
Watchdog Global configuration. More... | |
Macros | |
#define | Watchdog_CMD_RESERVED (32) |
#define | Watchdog_STATUS_RESERVED (-32) |
#define | Watchdog_STATUS_SUCCESS (0) |
Successful status code returned by Watchdog_control(). More... | |
#define | Watchdog_STATUS_ERROR (-1) |
Generic error status code returned by Watchdog_control(). More... | |
#define | Watchdog_STATUS_UNDEFINEDCMD (-2) |
An error status code returned by Watchdog_control() for undefined command codes. More... | |
#define | Watchdog_STATUS_UNSUPPORTED (-3) |
An error status code returned by Watchdog_setReload() for drivers which do not support the aforementioned API. More... | |
Typedefs | |
typedef struct Watchdog_Config_ * | Watchdog_Handle |
Watchdog Handle. More... | |
typedef enum Watchdog_DebugMode_ | Watchdog_DebugMode |
Watchdog debug stall settings. More... | |
typedef enum Watchdog_ResetMode_ | Watchdog_ResetMode |
Watchdog reset mode settings. More... | |
typedef void(* | Watchdog_Callback) (uintptr_t handle) |
Watchdog callback pointer. More... | |
typedef struct Watchdog_Params_ | Watchdog_Params |
Watchdog Parameters. More... | |
typedef void(* | Watchdog_ClearFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_clear(). More... | |
typedef void(* | Watchdog_CloseFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_close(). More... | |
typedef int_fast16_t(* | Watchdog_ControlFxn) (Watchdog_Handle handle, uint_fast16_t cmd, void *arg) |
A function pointer to a driver specific implementation of Watchdog_control(). More... | |
typedef void(* | Watchdog_InitFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_init(). More... | |
typedef Watchdog_Handle(* | Watchdog_OpenFxn) (Watchdog_Handle handle, Watchdog_Params *params) |
A function pointer to a driver specific implementation of Watchdog_open(). More... | |
typedef int_fast16_t(* | Watchdog_SetReloadFxn) (Watchdog_Handle handle, uint32_t ticks) |
A function pointer to a driver specific implementation of Watchdog_setReload(). More... | |
typedef uint32_t(* | Watchdog_ConvertMsToTicksFxn) (Watchdog_Handle handle, uint32_t milliseconds) |
A function pointer to a driver specific implementation of Watchdog_ConvertMsToTicksFxn(). More... | |
typedef struct Watchdog_FxnTable_ | Watchdog_FxnTable |
The definition of a Watchdog function table that contains the required set of functions to control a specific Watchdog driver implementation. More... | |
typedef struct Watchdog_Config_ | Watchdog_Config |
Watchdog Global configuration. More... | |
Enumerations | |
enum | Watchdog_DebugMode_ { Watchdog_DEBUG_STALL_ON, Watchdog_DEBUG_STALL_OFF } |
Watchdog debug stall settings. More... | |
enum | Watchdog_ResetMode_ { Watchdog_RESET_OFF, Watchdog_RESET_ON } |
Watchdog reset mode settings. More... | |
Functions | |
void | Watchdog_clear (Watchdog_Handle handle) |
Clears the Watchdog. More... | |
void | Watchdog_close (Watchdog_Handle handle) |
Function to close a Watchdog peripheral specified by the Watchdog handle.It stops (holds) the Watchdog counting on applicable platforms. More... | |
int_fast16_t | Watchdog_control (Watchdog_Handle handle, uint_fast16_t cmd, void *arg) |
Function performs implementation specific features on a given Watchdog_Handle. More... | |
void | Watchdog_init (void) |
Initializes the Watchdog module. More... | |
Watchdog_Handle | Watchdog_open (uint_least8_t index, Watchdog_Params *params) |
Opens a Watchdog. More... | |
void | Watchdog_Params_init (Watchdog_Params *params) |
Function to initialize the Watchdog_Params structure to its defaults. More... | |
int_fast16_t | Watchdog_setReload (Watchdog_Handle handle, uint32_t ticks) |
Sets the Watchdog reload value. More... | |
uint32_t | Watchdog_convertMsToTicks (Watchdog_Handle handle, uint32_t milliseconds) |
Converts milliseconds to Watchdog clock ticks. More... | |
typedef struct Watchdog_Config_* Watchdog_Handle |
Watchdog Handle.
typedef enum Watchdog_DebugMode_ Watchdog_DebugMode |
Watchdog debug stall settings.
This enumeration defines the debug stall modes for the Watchdog. On some targets, the Watchdog timer will continue to count down while a debugging session is halted. To avoid unwanted resets, the Watchdog can be set to stall while the processor is stopped by the debugger.
typedef enum Watchdog_ResetMode_ Watchdog_ResetMode |
Watchdog reset mode settings.
This enumeration defines the reset modes for the Watchdog. The Watchdog can be configured to either generate a reset upon timeout or simply produce a periodic interrupt.
typedef void(* Watchdog_Callback) (uintptr_t handle) |
Watchdog callback pointer.
This is the typedef for the function pointer that will allow a callback function to be specified in the Watchdog_Params structure. The function will take a Watchdog_Handle of the Watchdog causing the interrupt (cast as a uintptr_t) as an argument.
typedef struct Watchdog_Params_ Watchdog_Params |
Watchdog Parameters.
Watchdog parameters are used to with the Watchdog_open() call. Default values for these parameters are set using Watchdog_Params_init().
typedef void(* Watchdog_ClearFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_clear().
typedef void(* Watchdog_CloseFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_close().
typedef int_fast16_t(* Watchdog_ControlFxn) (Watchdog_Handle handle, uint_fast16_t cmd, void *arg) |
A function pointer to a driver specific implementation of Watchdog_control().
typedef void(* Watchdog_InitFxn) (Watchdog_Handle handle) |
A function pointer to a driver specific implementation of Watchdog_init().
typedef Watchdog_Handle(* Watchdog_OpenFxn) (Watchdog_Handle handle, Watchdog_Params *params) |
A function pointer to a driver specific implementation of Watchdog_open().
typedef int_fast16_t(* Watchdog_SetReloadFxn) (Watchdog_Handle handle, uint32_t ticks) |
A function pointer to a driver specific implementation of Watchdog_setReload().
typedef uint32_t(* Watchdog_ConvertMsToTicksFxn) (Watchdog_Handle handle, uint32_t milliseconds) |
A function pointer to a driver specific implementation of Watchdog_ConvertMsToTicksFxn().
typedef struct Watchdog_FxnTable_ Watchdog_FxnTable |
The definition of a Watchdog function table that contains the required set of functions to control a specific Watchdog driver implementation.
typedef struct Watchdog_Config_ Watchdog_Config |
Watchdog Global configuration.
The Watchdog_Config structure contains a set of pointers used to characterize the Watchdog driver implementation.
This structure needs to be defined before calling Watchdog_init() and it must not be changed thereafter.
enum Watchdog_DebugMode_ |
Watchdog debug stall settings.
This enumeration defines the debug stall modes for the Watchdog. On some targets, the Watchdog timer will continue to count down while a debugging session is halted. To avoid unwanted resets, the Watchdog can be set to stall while the processor is stopped by the debugger.
Enumerator | |
---|---|
Watchdog_DEBUG_STALL_ON | Watchdog will be stalled at breakpoints |
Watchdog_DEBUG_STALL_OFF | Watchdog will keep running at breakpoints |
enum Watchdog_ResetMode_ |
Watchdog reset mode settings.
This enumeration defines the reset modes for the Watchdog. The Watchdog can be configured to either generate a reset upon timeout or simply produce a periodic interrupt.
Enumerator | |
---|---|
Watchdog_RESET_OFF | Timeouts generate interrupts only |
Watchdog_RESET_ON | Generates reset after timeout |
void Watchdog_clear | ( | Watchdog_Handle | handle | ) |
Clears the Watchdog.
Clears the Watchdog to to prevent a reset signal from being generated if the module is in Watchdog_RESET_ON reset mode.
handle | Watchdog Handle |
void Watchdog_close | ( | Watchdog_Handle | handle | ) |
Function to close a Watchdog peripheral specified by the Watchdog handle.It stops (holds) the Watchdog counting on applicable platforms.
handle | A Watchdog_Handle returned from Watchdog_open |
int_fast16_t Watchdog_control | ( | Watchdog_Handle | handle, |
uint_fast16_t | cmd, | ||
void * | arg | ||
) |
Function performs implementation specific features on a given Watchdog_Handle.
Commands for Watchdog_control can originate from Watchdog.h or from implementation specific Watchdog*.h (WatchdogCC26XX.h, WatchdogMSP432.h, etc.. ) files. While commands from Watchdog.h are API portable across driver implementations, not all implementations may support all these commands. Conversely, commands from driver implementation specific Watchdog*.h files add unique driver capabilities but are not API portable across all Watchdog driver implementations.
Commands supported by Watchdog.h follow a Watchdog_CMD_<cmd> naming convention.
Commands supported by Watchdog*.h follow a Watchdog*_CMD_<cmd> naming convention.
Each control command defines arg differently. The types of arg are documented with each command.
See Watchdog_control command codes for command codes.
See Watchdog_control return status codes for status codes.
handle | A Watchdog handle returned from Watchdog_open() |
cmd | Watchdog.h or Watchdog*.h commands. |
arg | An optional R/W (read/write) command argument accompanied with cmd |
void Watchdog_init | ( | void | ) |
Initializes the Watchdog module.
The application-provided Watchdog_config must be present before the Watchdog_init function is called. The Watchdog_config must be persistent and not changed after Watchdog_init is called. This function must be called before any of the other Watchdog driver APIs.
Watchdog_Handle Watchdog_open | ( | uint_least8_t | index, |
Watchdog_Params * | params | ||
) |
Opens a Watchdog.
Opens a Watchdog object with the index and parameters specified, and returns a Watchdog_Handle.
index | Logical peripheral number for the Watchdog indexed into the Watchdog_config table |
params | Pointer to an parameter block, if NULL it will use default values. All the fields in this structure are RO (read-only). |
void Watchdog_Params_init | ( | Watchdog_Params * | params | ) |
Function to initialize the Watchdog_Params structure to its defaults.
params | An pointer to Watchdog_Params structure for initialization |
Default parameters: callbackFxn = NULL resetMode = Watchdog_RESET_ON debugStallMode = Watchdog_DEBUG_STALL_ON
int_fast16_t Watchdog_setReload | ( | Watchdog_Handle | handle, |
uint32_t | ticks | ||
) |
Sets the Watchdog reload value.
Sets the value from which the Watchdog will countdown after it reaches zero. This is how the reload value can be changed after the Watchdog has already been opened. The new reload value will be loaded into the Watchdog timer when this function is called. Watchdog_setReload is not reentrant. For CC13XX/CC26XX, if the parameter 'ticks' is set to zero (0), a Watchdog interrupt is immediately generated.
This API is not applicable for all platforms. See the page for your specific driver implementation for details.
handle | Watchdog Handle |
ticks | Value to be loaded into Watchdog timer Unit is in Watchdog clock ticks |
uint32_t Watchdog_convertMsToTicks | ( | Watchdog_Handle | handle, |
uint32_t | milliseconds | ||
) |
Converts milliseconds to Watchdog clock ticks.
Converts the input value into number of Watchdog clock ticks as close as possible. If the converted value exceeds 32 bits, a zero (0) will be returned to indicate overflow. The converted value can be used as the function parameter 'ticks' in Watchdog_setReload().
This API is not applicable for all platforms. See the page for your specific driver implementation for details.
handle | Watchdog Handle |
milliseconds | Value to be converted |