Watchdog.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2025, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file Watchdog.h
34  *
35  * @brief Watchdog driver interface
36  *
37  * @anchor ti_drivers_Watchdog_Overview
38  * # Overview #
39  *
40  * A watchdog timer can be used to generate a reset signal if a system has
41  * become unresponsive. The Watchdog driver simplifies configuring and starting
42  * the watchdog peripherals. The watchdog peripheral can be configured with
43  * resets either on or off and a user-specified timeout period.
44  *
45  * When the watchdog peripheral is configured not to generate a reset, it can
46  * be used to cause a hardware interrupt at a programmable interval. The driver
47  * provides the ability to specify a user-provided callback function that is
48  * called when the watchdog causes an interrupt.
49  *
50  * The Watchdog driver simplifies configuring and starting the Watchdog
51  * peripherals. The Watchdog can be set up to produce a reset signal after a
52  * timeout, or simply cause a hardware interrupt at a programmable interval.
53  * The driver provides the ability to specify a callback function that is
54  * called when the Watchdog causes an interrupt.
55  *
56  * When resets are turned on, it is the user application's responsibility to
57  * call Watchdog_clear() in order to clear the Watchdog and prevent a reset.
58  * Watchdog_clear() can be called at any time.
59  *
60  * @anchor ti_drivers_Watchdog_Usage
61  * # Usage #
62  *
63  * This section will cover driver usage.
64  * @anchor ti_drivers_Watchdog_Synopsis
65  * ## Synopsis #
66  *
67  * Open the driver with default settings:
68  * @code
69  * Watchdog_Handle watchdogHandle;
70  *
71  * Watchdog_init();
72  * watchdogHandle = Watchdog_open(WATCHDOG_INDEX, NULL);
73  * if (watchdogHandle == NULL) {
74  * // Spin forever
75  * while(1);
76  * }
77  * @endcode
78  *
79  * The Watchdog driver must be initialized by calling Watchdog_init(), before
80  * any other Watchdog APIs can be called.
81  * Once the watchdog is initialized, a Watchdog object can be created through
82  * the following steps:
83  * - Create and initialize the #Watchdog_Params structure.
84  * - Assign desired values to parameters.
85  * - Call Watchdog_open().
86  * - Save the Watchdog_Handle returned by Watchdog_open(). This will be used
87  * to interact with the Watchdog object just created.
88  *
89  * To have a user-defined function run at the hardware interrupt caused by a
90  * watchdog timer timeout, define a function of the following type:
91  * @code
92  * typedef void (*Watchdog_Callback)(uintptr_t);
93  * @endcode
94  * Then pass the function to Watchdog_open() through the #Watchdog_Params
95  * structure.
96  *
97  * An example of the Watchdog creation process that uses a callback function:
98  * @anchor ti_drivers_Watchdog_example_callback
99  * @code
100  * void UserCallbackFxn(Watchdog_Handle handle)
101  * {
102  * printf("Watchdog timer triggered!\n");
103  * releaseResources();
104  * }
105  *
106  * ...
107  *
108  * Watchdog_Params params;
109  * Watchdog_Handle watchdogHandle;
110  *
111  * Watchdog_init();
112  *
113  * Watchdog_Params_init(&params);
114  * params.resetMode = Watchdog_RESET_ON;
115  * params.callbackFxn = (Watchdog_Callback) UserCallbackFxn;
116  *
117  * watchdogHandle = Watchdog_open(CONFIG_WATCHDOG0, &params);
118  * if (watchdogHandle == NULL) {
119  * // Error opening Watchdog
120  * while (1);
121  * }
122  *
123  * @endcode
124  *
125  * If no #Watchdog_Params structure is passed to Watchdog_open(), the default
126  * values are used. By default, the Watchdog driver has resets turned on, no
127  * callback function specified, and stalls the timer at breakpoints during
128  * debugging. For CC35XX devices, debug stalling is not supported.
129  *
130  * Options for the resetMode parameter are #Watchdog_RESET_ON and
131  * #Watchdog_RESET_OFF. The latter allows the watchdog to be used like another
132  * timer interrupt. When resetMode is #Watchdog_RESET_ON, it is up to the
133  * application to call Watchdog_clear() to clear the Watchdog interrupt flag to
134  * prevent a reset. Watchdog_clear() can be called at any time.
135  *
136  * @anchor ti_drivers_Watchdog_Examples
137  * # Examples
138  * - @ref ti_drivers_Watchdog_Synopsis "Default Example"
139  * - @ref ti_drivers_Watchdog_example_callback "Callback Function before watchdog reset"
140  *
141  * @anchor ti_drivers_Watchdog_Configuration
142  * # Configuration
143  *
144  * Refer to the @ref driver_configuration "Driver's Configuration" section for
145  * more information.
146  *
147  *******************************************************************************
148  */
149 
150 #ifndef ti_drivers_Watchdog__include
151 #define ti_drivers_Watchdog__include
152 
153 #include <stdint.h>
154 
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158 
176 #define Watchdog_CMD_RESERVED (32)
177 
190 #define Watchdog_STATUS_RESERVED (-32)
191 
205 #define Watchdog_STATUS_SUCCESS (0)
206 
213 #define Watchdog_STATUS_ERROR (-1)
214 
222 #define Watchdog_STATUS_UNDEFINEDCMD (-2)
223 
231 #define Watchdog_STATUS_UNSUPPORTED (-3)
232 
242 /* Add Watchdog_CMD_<commands> here */
243 
252 
261 typedef enum
262 {
266 
274 typedef enum
275 {
279 
288 typedef void (*Watchdog_Callback)(uintptr_t handle);
289 
298 typedef struct
299 {
302  Watchdog_ResetMode resetMode;
304  Watchdog_DebugMode debugStallMode;
306  void *custom;
309 
314 typedef void (*Watchdog_ClearFxn)(Watchdog_Handle handle);
315 
320 typedef void (*Watchdog_CloseFxn)(Watchdog_Handle handle);
321 
326 typedef int_fast16_t (*Watchdog_ControlFxn)(Watchdog_Handle handle, uint_fast16_t cmd, void *arg);
327 
332 typedef void (*Watchdog_InitFxn)(Watchdog_Handle handle);
333 
338 typedef Watchdog_Handle (*Watchdog_OpenFxn)(Watchdog_Handle handle, Watchdog_Params *params);
339 
344 typedef int_fast16_t (*Watchdog_SetReloadFxn)(Watchdog_Handle handle, uint32_t ticks);
345 
350 typedef uint32_t (*Watchdog_ConvertMsToTicksFxn)(Watchdog_Handle handle, uint32_t milliseconds);
351 
357 typedef struct
358 {
367 
379 typedef struct Watchdog_Config_
380 {
385 
387  void *object;
388 
390  void const *hwAttrs;
392 
401 extern void Watchdog_clear(Watchdog_Handle handle);
402 
414 extern void Watchdog_close(Watchdog_Handle handle);
415 
454 extern int_fast16_t Watchdog_control(Watchdog_Handle handle, uint_fast16_t cmd, void *arg);
455 
464 extern void Watchdog_init(void);
465 
485 extern Watchdog_Handle Watchdog_open(uint_least8_t index, Watchdog_Params *params);
486 
499 
523 extern int_fast16_t Watchdog_setReload(Watchdog_Handle handle, uint32_t ticks);
524 
550 extern uint32_t Watchdog_convertMsToTicks(Watchdog_Handle handle, uint32_t milliseconds);
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 
556 #endif /* ti_drivers_Watchdog__include */
ADC_Params params
Definition: Driver_Init.h:11
Watchdog_Callback callbackFxn
Definition: Watchdog.h:300
Watchdog_DebugMode debugStallMode
Definition: Watchdog.h:304
void Watchdog_clear(Watchdog_Handle handle)
Clears the Watchdog.
void * custom
Definition: Watchdog.h:306
Watchdog_ControlFxn watchdogControl
Definition: Watchdog.h:361
Watchdog_Handle(* Watchdog_OpenFxn)(Watchdog_Handle handle, Watchdog_Params *params)
A function pointer to a driver specific implementation of Watchdog_open().
Definition: Watchdog.h:338
Watchdog_ConvertMsToTicksFxn watchdogConvertMsToTicks
Definition: Watchdog.h:365
void(* Watchdog_Callback)(uintptr_t handle)
Watchdog callback pointer.
Definition: Watchdog.h:288
Watchdog_ResetMode resetMode
Definition: Watchdog.h:302
void * object
Definition: Watchdog.h:387
Watchdog Parameters.
Definition: Watchdog.h:298
void(* Watchdog_InitFxn)(Watchdog_Handle handle)
A function pointer to a driver specific implementation of Watchdog_init().
Definition: Watchdog.h:332
Definition: Watchdog.h:276
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().
Definition: Watchdog.h:326
void const * hwAttrs
Definition: Watchdog.h:390
Watchdog Global configuration.
Definition: Watchdog.h:379
void Watchdog_Params_init(Watchdog_Params *params)
Function to initialize the Watchdog_Params structure to its defaults.
int_fast16_t Watchdog_control(Watchdog_Handle handle, uint_fast16_t cmd, void *arg)
Function performs implementation specific features on a given Watchdog_Handle.
void(* Watchdog_CloseFxn)(Watchdog_Handle handle)
A function pointer to a driver specific implementation of Watchdog_close().
Definition: Watchdog.h:320
Watchdog_DebugMode
Watchdog debug stall settings.
Definition: Watchdog.h:261
struct Watchdog_Config_ * Watchdog_Handle
Watchdog Handle.
Definition: Watchdog.h:251
Watchdog_OpenFxn watchdogOpen
Definition: Watchdog.h:363
int_fast16_t(* Watchdog_SetReloadFxn)(Watchdog_Handle handle, uint32_t ticks)
A function pointer to a driver specific implementation of Watchdog_setReload().
Definition: Watchdog.h:344
void Watchdog_close(Watchdog_Handle handle)
Function to close a Watchdog peripheral specified by the Watchdog handle. It stops (holds) the Watchd...
void Watchdog_init(void)
Initializes the Watchdog module.
void(* Watchdog_ClearFxn)(Watchdog_Handle handle)
A function pointer to a driver specific implementation of Watchdog_clear().
Definition: Watchdog.h:314
uint32_t(* Watchdog_ConvertMsToTicksFxn)(Watchdog_Handle handle, uint32_t milliseconds)
A function pointer to a driver specific implementation of Watchdog_ConvertMsToTicksFxn().
Definition: Watchdog.h:350
uint32_t Watchdog_convertMsToTicks(Watchdog_Handle handle, uint32_t milliseconds)
Converts milliseconds to Watchdog clock ticks.
Watchdog_ClearFxn watchdogClear
Definition: Watchdog.h:359
Watchdog_SetReloadFxn watchdogSetReload
Definition: Watchdog.h:364
Definition: Watchdog.h:277
The definition of a Watchdog function table that contains the required set of functions to control a ...
Definition: Watchdog.h:357
Watchdog_ResetMode
Watchdog reset mode settings.
Definition: Watchdog.h:274
Definition: Watchdog.h:263
struct Watchdog_Config_ Watchdog_Config
Watchdog Global configuration.
Watchdog_InitFxn watchdogInit
Definition: Watchdog.h:362
Definition: Watchdog.h:264
Watchdog_FxnTable const * fxnTablePtr
Definition: Watchdog.h:384
Watchdog_Handle Watchdog_open(uint_least8_t index, Watchdog_Params *params)
Opens a Watchdog.
Watchdog_CloseFxn watchdogClose
Definition: Watchdog.h:360
int_fast16_t Watchdog_setReload(Watchdog_Handle handle, uint32_t ticks)
Sets the Watchdog reload value.
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale