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       WatchdogCC32XX.h
34  *  @brief      Watchdog timer driver implementation for CC32XX
35  *
36  *  The Watchdog header file for CC32XX should be included in an application
37  *  as follows:
38  *  @code
39  *  #include <ti/drivers/Watchdog.h>
40  *  #include <ti/drivers/watchdog/WatchdogCC32XX.h>
41  *  @endcode
42  *
43  *  Refer to @ref Watchdog.h for a complete description of APIs.
44  *
45  *  This Watchdog driver implementation is designed to operate on a CC32XX
46  *  device. Once opened, CC32XX Watchdog will count down from the reload
47  *  value specified in the WatchdogCC32XX_HWAttrs. If it times out, the
48  *  Watchdog interrupt flag will be set, and a user-provided callback function
49  *  will be called. If the Watchdog Timer is allowed to time out again while
50  *  the interrupt flag is still pending, a reset signal will be generated.
51  *  To prevent a reset, Watchdog_clear() must be called to clear the interrupt
52  *  flag.
53  *
54  *  @warning The watchdog peripheral does not support a Non-Maskable Interrupt (NMI).
55  *
56  *  The reload value from which the Watchdog Timer counts down may be changed
57  *  during runtime using Watchdog_setReload().
58  *
59  *  Watchdog_close() is <b>not</b> supported by this driver implementation.
60  *
61  *  By default the Watchdog driver has resets turned on. This feature cannot
62  *  be disabled.
63  *
64  *  To have a user-defined function run at the warning interrupt, first define
65  *  a void-type function that takes a Watchdog_Handle cast to a UArg as an
66  *  argument. The callback and code to start the Watchdog timer are shown below.
67  *
68  *  @code
69  *  void watchdogCallback(UArg handle);
70  *
71  *  ...
72  *
73  *  Watchdog_Handle handle;
74  *  Watchdog_Params params;
75  *  uint32_t tickValue;
76  *
77  *  Watchdog_Params_init(&params);
78  *  params.callbackFxn = watchdogCallback;
79  *  handle = Watchdog_open(Watchdog_configIndex, &params);
80  *  // Set timeout period to 100 ms
81  *  tickValue = Watchdog_convertMsToTicks(handle, 100);
82  *  Watchdog_setReload(handle, tickValue);
83  *
84  *  ...
85  *
86  *  void watchdogCallback(UArg handle)
87  *  {
88  *      // User-defined code here
89  *      ...
90  *
91  *  }
92  *  @endcode
93  *
94  *  # Power Driver Usage #
95  *
96  *  The watchdog timer driver does not set any power constraints. If the power
97  *  driver is enabled, the application will continue to aggressively attempt
98  *  to place the device into the lowest power state possible.
99  *
100  *  When the device enters Low Power Deep Sleep, the peripheral registers are
101  *  reset. After a transition from Low Power Deep Sleep, the watchdog timer will
102  *  be re-initialized automatically with the most recently set reload value. If
103  *  Watchdog_setReload() was never called, the
104  *  #WatchdogCC32XX_HWAttrs.reloadValue is used. With each transition to and
105  *  from Low Power Deep Sleep, the watchdog timer is implicitly cleared.
106  *
107  ******************************************************************************
108  */
109 
110 #ifndef ti_drivers_watchdog_WatchdogCC32XX__include
111 #define ti_drivers_watchdog_WatchdogCC32XX__include
112 
113 #include <stdint.h>
114 #include <stdbool.h>
115 #include <ti/drivers/Watchdog.h>
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 
121 /**
122  *  @addtogroup Watchdog_STATUS
123  *  WatchdogCC32XX_STATUS_* macros are command codes only defined in the
124  *  WatchdogCC32XX.h driver implementation and need to:
125  *  @code
126  *  #include <ti/drivers/watchdog/WatchdogCC32XX.h>
127  *  @endcode
128  *  @{
129  */
130 
131 /* Add WatchdogCC32XX_STATUS_* macros here */
132 
133 /** @}*/
134 
135 /**
136  *  @addtogroup Watchdog_CMD
137  *  WatchdogCC32XX_CMD_* macros are command codes only defined in the
138  *  WatchdogCC32XX.h driver implementation and need to:
139  *  @code
140  *  #include <ti/drivers/watchdog/WatchdogCC32XX.h>
141  *  @endcode
142  *  @{
143  */
144 
145 /*!
146  *  @brief Command used by Watchdog_control to determines
147  *  whether the watchdog timer is enabled
148  *
149  *  With this command code, @b arg is a pointer to a @c bool.
150  *  @b *arg contains @c true if the watchdog timer is enabled,
151  *  else @c false if it is not.
152  */
153 #define WatchdogCC32XX_CMD_IS_TIMER_ENABLE          (Watchdog_CMD_RESERVED + 0)
154 
155 
156 /*!
157  *  @brief Command used by Watchdog_control
158  *  to gets the current watchdog timer value
159  *
160  *  With this command code, @b arg is a pointer to an @a integer.
161  *  @b *arg contains the current value of the watchdog timer.
162  */
163 #define WatchdogCC32XX_CMD_GET_TIMER_VALUE          (Watchdog_CMD_RESERVED + 1)
164 
165 
166 /*!
167  *  @brief Command used by Watchdog_control to determines
168  *  whether the watchdog timer is locked
169  *
170  *  With this command code, @b arg is a pointer to a @c bool.
171  *  @b *arg contains @c true if the watchdog timer is locked,
172  *  else @c false if it is not.
173  */
174 #define WatchdogCC32XX_CMD_IS_TIMER_LOCKED          (Watchdog_CMD_RESERVED + 2)
175 
176 
177 /*!
178  *  @brief Command used by Watchdog_control
179  *  to gets the current watchdog timer reload value
180  *
181  *  With this command code, @b arg is a pointer to an @a integer.
182  *  @b *arg contains the current value loaded into the watchdog timer when
183  *  the count reaches zero for the first time.
184  */
185 #define WatchdogCC32XX_CMD_GET_TIMER_RELOAD_VALUE   (Watchdog_CMD_RESERVED + 3)
186 
187 
188 /** @}*/
189 
190 /*!  @brief  Watchdog function table for CC32XX */
191 extern const Watchdog_FxnTable WatchdogCC32XX_fxnTable;
192 
193 /*!
194  *  @brief  Watchdog hardware attributes for CC32XX
195  *
196  *  intPriority is the Watchdog timer's interrupt priority, as defined by the
197  *  underlying OS.  It is passed unmodified to the underlying OS's interrupt
198  *  handler creation code, so you need to refer to the OS documentation
199  *  for usage.  For example, for SYS/BIOS applications, refer to the
200  *  ti.sysbios.family.arm.m3.Hwi documentation for SYS/BIOS usage of
201  *  interrupt priorities.  If the driver uses the ti.dpl interface
202  *  instead of making OS calls directly, then the HwiP port handles the
203  *  interrupt priority in an OS specific way.  In the case of the SYS/BIOS
204  *  port, intPriority is passed unmodified to Hwi_create().
205  */
206 typedef struct {
207     unsigned int baseAddr;       /*!< Base address for Watchdog */
208     unsigned int intNum;         /*!< WDT interrupt number */
209     unsigned int intPriority;    /*!< WDT interrupt priority */
210     uint32_t     reloadValue;    /*!< Reload value for Watchdog */
211 } WatchdogCC32XX_HWAttrs;
212 
213 /*!
214  *  @brief      Watchdog Object for CC32XX
215  *
216  *  Not to be accessed by the user.
217  */
218 typedef struct {
219     Power_NotifyObj     notifyObj;
220     /*
221      * The reload value can be set at runtime; therefore we can't rely
222      * on the reload value supplied in the HWAttrs after a LPDS transition.
223      */
224     uint32_t            reloadValue;
225     Watchdog_DebugMode  debugMode;
226     bool                isOpen;
227 } WatchdogCC32XX_Object;
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* ti_drivers_watchdog_WatchdogCC32XX__include */
234