WatchdogCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2021, 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 WatchdogCC26XX.h
34  *
35  * @brief Watchdog driver implementation for CC13XX/CC26XX
36  *
37  * # Driver include #
38  * The Watchdog header file should be included in an application as follows:
39  * @code
40  * #include <ti/drivers/Watchdog.h>
41  * #include <ti/drivers/watchdog/WatchdogCC26XX.h>
42  * @endcode
43  *
44  * Refer to @ref Watchdog.h for a complete description of APIs.
45  *
46  * # Overview #
47  *
48  * The general Watchdog API should be used in application code, i.e.
49  * #Watchdog_open() should be used instead of WatchdogCC26XX_open(). The board
50  * file will define the device specific config, and casting in the general API
51  * will ensure that the correct device specific functions are called.
52  *
53  * # General Behavior #
54  * This Watchdog driver implementation is designed to operate on a CC13XX/CC26XX
55  * device. Before using the Watchdog in CC13XX/CC26XX, the Watchdog driver is
56  * initialized by calling #Watchdog_init(). The Watchdog HW is configured by
57  * calling #Watchdog_open(). Once opened, the Watchdog will count down from
58  * the reload value specified in #WatchdogCC26XX_HWAttrs. If it times out, a
59  * non-maskable interrupt will be triggered, the Watchdog interrupt flag will
60  * be set, and a user-provided callback function will be called. If reset is
61  * enabled in the #Watchdog_Params and the Watchdog timer is allowed to time
62  * out again while the interrupt flag is still pending, a reset signal will be
63  * generated. To prevent a reset, #Watchdog_clear() must be called to clear the
64  * interrupt flag and to reload the timer.
65  *
66  * The Watchdog counts down at a rate of the device clock SCLK_HF (48 MHz)
67  * divided by a fixed-division ratio of 32, which equals to 1.5 MHz. The
68  * Watchdog rate will change if SCLK_HF deviates from 48 MHz.
69  *
70  * @note The Watchdog interrupt is configured as a non-maskable interrupt
71  * (NMI) and the user-defined callback function is called in the context of
72  * NMI. Because the Watchdog interrupt is non-maskable, it is not safe to call
73  * any BIOS APIs from the Watchdog callback function. Calls to DPL and TIDRIVERS
74  * APIs should also be avoided given that they may indirectly make calls to BIOS
75  * APIs. Furthermore, the watchdog callback should only be reached if the
76  * watchdog times out. This should indicate an error event and allow logging
77  * or other housekeeping before resetting the device. Clearing of the watchdog
78  * and checking alive signals should be done in another execution context.
79  *
80  * The reload value from which the Watchdog timer counts down may be changed
81  * during runtime using #Watchdog_setReload(). This value should be specified
82  * in Watchdog clock ticks and should not exceed the maximum value of 32 bits,
83  * which corresponds to a timeout period of 2863.3 seconds at the Watchdog rate
84  * of 1.5 MHz. If the reload value is set to zero, the Watchdog interrupt is
85  * immediately generated.
86  *
87  * Since the device is not reset on the first Watchdog timeout, the maximum
88  * time lapse between the time when the device gets locked up and the time when
89  * it is reset can be up to <b>two</b> Watchdog timeout periods.
90  *
91  * Watchdog_close() is <b>not</b> supported by this driver implementation. Once
92  * started, the Watchdog timer can only be stopped by a hardware reset.
93  *
94  * <b>No</b> CC13XX/CC26XX specific command has been implemented. Any call to
95  * Watchdog_control() will receive the return code Watchdog_STATUS_UNDEFINEDCMD.
96  *
97  * By default the Watchdog driver has reset enabled. However, it may be
98  * disabled in the #Watchdog_Params which allows the Watchdog Timer to be used
99  * like another timer interrupt. This functionality is <b>not</b> supported by
100  * all platforms, refer to device specific documentation for details.
101  *
102  * # Power Management #
103  * Once started, the Watchdog will keep running in Active or Idle mode. When
104  * the device enters Standby mode, the Watchdog timer will stop counting down
105  * but the counter value will be preserved. When the device wakes up from
106  * Standby, the Watchdog timer will continue to count down from the previous
107  * counter value.
108  *
109  * This means that if a system goes into Standby 50% of the time and the
110  * Watchdog reload value is set to 1 second, the Watchdog timer will actually
111  * time out in 2 seconds. A system which is only in Active/Idle mode for 1% of
112  * the time, the Watchdog timer will time out in 100 seconds. However, if a bug
113  * locks up the application in Active mode, the Watchdog timer will time out in
114  * the configured time.
115  *
116  *
117  * # Supported Functions #
118  * | Generic API Function | API Function | Description |
119  * |------------------------------ |----------------------------------
120  * |---------------------------------------------------| | #Watchdog_init() | WatchdogCC26XX_init() |
121  * Initialize Watchdog driver | | #Watchdog_open() | WatchdogCC26XX_open() |
122  * Initialize Watchdog HW and set system dependencies| | #Watchdog_clear() | WatchdogCC26XX_clear() | Clear
123  * Watchdog interrupt flag and reload counter | | #Watchdog_setReload() | WatchdogCC26XX_setReload() |
124  * Set Watchdog timer reload value in clock ticnks | | #Watchdog_convertMsToTicks() |
125  * WatchdogCC26XX_convertMsToTicks() | Converts milliseconds to clock ticks |
126  *
127  * @note All calls should go through the generic API. Please refer to @ref Watchdog.h for a
128  * complete description of the generic APIs.
129  *
130  * # Use Cases #
131  * ## Basic Watchdog #
132  * In this basic watchdog example, the application is expected to define a
133  * Watchdog callback function and start the Watchdog timer by calling #Watchdog_open().
134  * If needed, #Watchdog_setReload() may be called to change the timeout period.
135  * If all monitored tasks are doing alright, #Watchdog_clear() should be called
136  * regularly to reload the counter so as to restart the timeout period and to
137  * avoid the Watchdog interrupt being triggered. If the #Watchdog_clear() is
138  * missed and the Watchdog timer is allowed to timeout, the user-defined
139  * callback function is called. In this function, the user may do whatever is
140  * appropriate for the application.
141  * Here are some suggestions:
142  * - do nothing so that the timer will timeout again and trigger the reset
143  * - immediately reset the device
144  * - do self-test to check the integrity of the application
145  *
146  * @note The Watchdog interrupt is configured as a non-maskable interrupt
147  * (NMI) and the user-defined callback function is called in NMI context.
148  * Therefore it is not safe to call any OS APIs from the Watchdog callback
149  * function. This includes any driver calls that rely on OS APIs.
150  *
151  * The following code example shows how to define the callback function and to
152  * start the Watchdog timer.
153  * @code
154  * void watchdogCallback(uintptr_t handle);
155  *
156  * ...
157  *
158  * Watchdog_Handle handle;
159  * Watchdog_Params params;
160  * uint32_t tickValue;
161  *
162  * Watchdog_Params_init(&params);
163  * params.callbackFxn = watchdogCallback;
164  * handle = Watchdog_open(Watchdog_configIndex, &params);
165  * // set timeout period to 100 ms
166  * tickValue = Watchdog_convertMsToTicks(handle, 100);
167  * Watchdog_setReload(handle, tickValue);
168  *
169  * ...
170  *
171  * void watchdogCallback(uintptr_t handle)
172  * {
173  * // User-defined code here
174  * ...
175  * }
176  *
177  * @endcode
178  */
179 
180 #ifndef ti_drivers_watchdog_WatchdogCC26XX__include
181 #define ti_drivers_watchdog_WatchdogCC26XX__include
182 
183 #include <stdint.h>
184 #include <stdbool.h>
185 #include <ti/drivers/Watchdog.h>
186 #include <ti/drivers/dpl/HwiP.h>
187 
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 
202 /* Add WatchdogCC26XX_STATUS_* macros here */
203 
216 /* Add WatchdogCC26XX_CMD_* macros here */
217 
222 
226 typedef struct
227 {
228  unsigned int baseAddr;
229  unsigned long reloadValue;
231 
237 typedef struct
238 {
239  bool isOpen; /* Flag for open/close status */
240  Watchdog_Callback callbackFxn; /* Pointer to callback. Not supported
241  on all targets. */
242  Watchdog_ResetMode resetMode; /* Mode to enable resets.
243  Not supported on all targets. */
244  Watchdog_DebugMode debugStallMode; /* Mode to stall Watchdog at breakpoints.
245  Not supported on all targets. */
246  /* Watchdog SYS/BIOS objects */
247  HwiP_Struct hwi; /* Hwi object */
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* ti_drivers_watchdog_WatchdogCC26XX__include */
void(* Watchdog_Callback)(uintptr_t handle)
Watchdog callback pointer.
Definition: Watchdog.h:291
unsigned int baseAddr
Definition: WatchdogCC26XX.h:228
Watchdog driver interface.
Watchdog hardware attributes for CC26XX.
Definition: WatchdogCC26XX.h:226
Watchdog_Callback callbackFxn
Definition: WatchdogCC26XX.h:240
bool isOpen
Definition: WatchdogCC26XX.h:239
Watchdog_DebugMode
Watchdog debug stall settings.
Definition: Watchdog.h:264
Watchdog Object for CC26XX.
Definition: WatchdogCC26XX.h:237
unsigned long reloadValue
Definition: WatchdogCC26XX.h:229
Watchdog_ResetMode resetMode
Definition: WatchdogCC26XX.h:242
const Watchdog_FxnTable WatchdogCC26XX_fxnTable
Watchdog function table for CC26XX.
Watchdog_DebugMode debugStallMode
Definition: WatchdogCC26XX.h:244
The definition of a Watchdog function table that contains the required set of functions to control a ...
Definition: Watchdog.h:360
Watchdog_ResetMode
Watchdog reset mode settings.
Definition: Watchdog.h:277
HwiP_Struct hwi
Definition: WatchdogCC26XX.h:247
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale