WatchdogCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, 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.
74  *
75  * The reload value from which the Watchdog timer counts down may be changed
76  * during runtime using #Watchdog_setReload(). This value should be specified
77  * in Watchdog clock ticks and should not exceed the maximum value of 32 bits,
78  * which corresponds to a timeout period of 2863.3 seconds at the Watchdog rate
79  * of 1.5 MHz. If the reload value is set to zero, the Watchdog interrupt is
80  * immediately generated.
81  *
82  * Since the device is not reset on the first Watchdog timeout, the maximum
83  * time lapse between the time when the device gets locked up and the time when
84  * it is reset can be up to <b>two</b> Watchdog timeout periods.
85  *
86  * Watchdog_close() is <b>not</b> supported by this driver implementation. Once
87  * started, the Watchdog timer can only be stopped by a hardware reset.
88  *
89  * <b>No</b> CC13XX/CC26XX specific command has been implemented. Any call to
90  * Watchdog_control() will receive the return code Watchdog_STATUS_UNDEFINEDCMD.
91  *
92  * By default the Watchdog driver has reset enabled. However, it may be
93  * disabled in the #Watchdog_Params which allows the Watchdog Timer to be used
94  * like another timer interrupt. This functionality is <b>not</b> supported by
95  * all platforms, refer to device specific documentation for details.
96  *
97  * # Power Management #
98  * Once started, the Watchdog will keep running in Active or Idle mode. When
99  * the device enters Standby mode, the Watchdog timer will stop counting down
100  * but the counter value will be preserved. When the device wakes up from
101  * Standby, the Watchdog timer will continue to count down from the previous
102  * counter value.
103  *
104  * This means that if a system goes into Standby 50% of the time and the
105  * Watchdog reload value is set to 1 second, the Watchdog timer will actually
106  * time out in 2 seconds. A system which is only in Active/Idle mode for 1% of
107  * the time, the Watchdog timer will time out in 100 seconds. However, if a bug
108  * locks up the application in Active mode, the Watchdog timer will time out in
109  * the configured time.
110  *
111  *
112  * # Supported Functions #
113  * | Generic API Function | API Function | Description |
114  * |------------------------------ |---------------------------------- |---------------------------------------------------|
115  * | #Watchdog_init() | WatchdogCC26XX_init() | Initialize Watchdog driver |
116  * | #Watchdog_open() | WatchdogCC26XX_open() | Initialize Watchdog HW and set system dependencies|
117  * | #Watchdog_clear() | WatchdogCC26XX_clear() | Clear Watchdog interrupt flag and reload counter |
118  * | #Watchdog_setReload() | WatchdogCC26XX_setReload() | Set Watchdog timer reload value in clock ticnks |
119  * | #Watchdog_convertMsToTicks() | WatchdogCC26XX_convertMsToTicks() | Converts milliseconds to clock ticks |
120  *
121  * @note All calls should go through the generic API. Please refer to @ref Watchdog.h for a
122  * complete description of the generic APIs.
123  *
124  * # Use Cases #
125  * ## Basic Watchdog #
126  * In this basic watchdog example, the application is expected to define a
127  * Watchdog callback function and start the Watchdog timer by calling #Watchdog_open().
128  * If needed, #Watchdog_setReload() may be called to change the timeout period.
129  * If all monitored tasks are doing alright, #Watchdog_clear() should be called
130  * regularly to reload the counter so as to restart the timeout period and to
131  * avoid the Watchdog interrupt being triggered. If the #Watchdog_clear() is
132  * missed and the Watchdog timer is allowed to timeout, the user-defined
133  * callback function is called. In this function, the user may do whatever is
134  * appropriate for the application.
135  * Here are some suggestions:
136  * - do nothing so that the timer will timeout again and trigger the reset
137  * - immediately reset the device
138  * - do self-test to check the integrity of the application
139  *
140  * @note The Watchdog interrupt is configured as a non-maskable interrupt
141  * (NMI) and the user-defined callback function is called in NMI context.
142  * Therefore it is not safe to call any OS APIs from the Watchdog callback
143  * function. This includes any driver calls that rely on OS APIs.
144  *
145  * The following code example shows how to define the callback function and to
146  * start the Watchdog timer.
147  * @code
148  * void watchdogCallback(uintptr_t handle);
149  *
150  * ...
151  *
152  * Watchdog_Handle handle;
153  * Watchdog_Params params;
154  * uint32_t tickValue;
155  *
156  * Watchdog_Params_init(&params);
157  * params.callbackFxn = watchdogCallback;
158  * handle = Watchdog_open(Watchdog_configIndex, &params);
159  * // set timeout period to 100 ms
160  * tickValue = Watchdog_convertMsToTicks(handle, 100);
161  * Watchdog_setReload(handle, tickValue);
162  *
163  * ...
164  *
165  * void watchdogCallback(uintptr_t handle)
166  * {
167  * // User-defined code here
168  * ...
169  * }
170  *
171  * @endcode
172  */
173 
174 #ifndef ti_drivers_watchdog_WatchdogCC26XX__include
175 #define ti_drivers_watchdog_WatchdogCC26XX__include
176 
177 #include <stdint.h>
178 #include <stdbool.h>
179 #include <ti/drivers/Watchdog.h>
180 #include <ti/drivers/dpl/HwiP.h>
181 
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185 
196 /* Add WatchdogCC26XX_STATUS_* macros here */
197 
210 /* Add WatchdogCC26XX_CMD_* macros here */
211 
216 
220 typedef struct {
221  unsigned int baseAddr;
222  unsigned long reloadValue;
224 
230 typedef struct {
231  bool isOpen; /* Flag for open/close status */
232  Watchdog_Callback callbackFxn; /* Pointer to callback. Not supported
233  on all targets. */
234  Watchdog_ResetMode resetMode; /* Mode to enable resets.
235  Not supported on all targets. */
236  Watchdog_DebugMode debugStallMode; /* Mode to stall Watchdog at breakpoints.
237  Not supported on all targets. */
238  /* Watchdog SYS/BIOS objects */
239  HwiP_Struct hwi; /* Hwi object */
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif /* ti_drivers_watchdog_WatchdogCC26XX__include */
void(* Watchdog_Callback)(uintptr_t handle)
Watchdog callback pointer.
Definition: Watchdog.h:289
unsigned int baseAddr
Definition: WatchdogCC26XX.h:221
Watchdog driver interface.
Watchdog hardware attributes for CC26XX.
Definition: WatchdogCC26XX.h:220
Watchdog_Callback callbackFxn
Definition: WatchdogCC26XX.h:232
bool isOpen
Definition: WatchdogCC26XX.h:231
Watchdog_DebugMode
Watchdog debug stall settings.
Definition: Watchdog.h:264
Watchdog Object for CC26XX.
Definition: WatchdogCC26XX.h:230
unsigned long reloadValue
Definition: WatchdogCC26XX.h:222
Watchdog_ResetMode resetMode
Definition: WatchdogCC26XX.h:234
const Watchdog_FxnTable WatchdogCC26XX_fxnTable
Watchdog function table for CC26XX.
Watchdog_DebugMode debugStallMode
Definition: WatchdogCC26XX.h:236
The definition of a Watchdog function table that contains the required set of functions to control a ...
Definition: Watchdog.h:362
Watchdog_ResetMode
Watchdog reset mode settings.
Definition: Watchdog.h:276
HwiP_Struct hwi
Definition: WatchdogCC26XX.h:239
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale