MSPM0G1X0X_G3X0X Driver Library  1.10.01.05
dl_wwdt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, 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 dl_wwdt.h
34  * @brief Window Watchdog Timer (WWDT) Driver Library
35  * @defgroup WWDT Window Watchdog Timer (WWDT)
36  *
37  * @anchor ti_dl_dl_wwdt_Overview
38  * # Overview
39  *
40  * The Window Watchdog Timer Driver Library allows full configuration of
41  * the MSPM0 WWDT module.
42  * The window watchdog timer (WWDT) supervises code execution.
43  * If the application software does not successfully reset the window
44  * watchdog within the programmed open time window, the window watchdog
45  * generates a SYSRST.
46  *
47  * <hr>
48  ******************************************************************************
49  */
53 #ifndef ti_dl_dl_wwdt__include
54 #define ti_dl_dl_wwdt__include
55 
56 #include <stdbool.h>
57 #include <stdint.h>
58 
59 #include <ti/devices/msp/msp.h>
60 
61 #ifdef __MSPM0_HAS_WWDT__
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 /* clang-format off */
68 
70 typedef enum {
72  DL_WWDT_CLOCK_DIVIDE_1 = 0x00000000,
74  DL_WWDT_CLOCK_DIVIDE_2 = 0x00000001,
76  DL_WWDT_CLOCK_DIVIDE_3 = 0x00000002,
78  DL_WWDT_CLOCK_DIVIDE_4 = 0x00000003,
80  DL_WWDT_CLOCK_DIVIDE_5 = 0x00000004,
82  DL_WWDT_CLOCK_DIVIDE_6 = 0x00000005,
84  DL_WWDT_CLOCK_DIVIDE_7 = 0x00000006,
88 
90 typedef enum {
92  DL_WWDT_WINDOW0 = WWDT_WWDTCTL1_WINSEL_WIN0,
94  DL_WWDT_WINDOW1 = WWDT_WWDTCTL1_WINSEL_WIN1
96 
98 typedef enum {
100  DL_WWDT_WINDOW_PERIOD_0 = WWDT_WWDTCTL0_WINDOW0_SIZE_0,
102  DL_WWDT_WINDOW_PERIOD_12 = WWDT_WWDTCTL0_WINDOW0_SIZE_12,
104  DL_WWDT_WINDOW_PERIOD_18 = WWDT_WWDTCTL0_WINDOW0_SIZE_18,
106  DL_WWDT_WINDOW_PERIOD_25 = WWDT_WWDTCTL0_WINDOW0_SIZE_25,
108  DL_WWDT_WINDOW_PERIOD_50 = WWDT_WWDTCTL0_WINDOW0_SIZE_50,
110  DL_WWDT_WINDOW_PERIOD_75 = WWDT_WWDTCTL0_WINDOW0_SIZE_75,
112  DL_WWDT_WINDOW_PERIOD_81 = WWDT_WWDTCTL0_WINDOW0_SIZE_81,
114  DL_WWDT_WINDOW_PERIOD_87 = WWDT_WWDTCTL0_WINDOW0_SIZE_87
116 
118 typedef enum {
120  DL_WWDT_TIMER_PERIOD_6_BITS = WWDT_WWDTCTL0_PER_EN_6,
122  DL_WWDT_TIMER_PERIOD_8_BITS = WWDT_WWDTCTL0_PER_EN_8,
124  DL_WWDT_TIMER_PERIOD_10_BITS = WWDT_WWDTCTL0_PER_EN_10,
126  DL_WWDT_TIMER_PERIOD_12_BITS = WWDT_WWDTCTL0_PER_EN_12,
128  DL_WWDT_TIMER_PERIOD_15_BITS = WWDT_WWDTCTL0_PER_EN_15,
130  DL_WWDT_TIMER_PERIOD_18_BITS = WWDT_WWDTCTL0_PER_EN_18,
132  DL_WWDT_TIMER_PERIOD_21_BITS = WWDT_WWDTCTL0_PER_EN_21,
134  DL_WWDT_TIMER_PERIOD_25_BITS = WWDT_WWDTCTL0_PER_EN_25
136 
138 typedef enum {
140  DL_WWDT_STOP_IN_SLEEP = WWDT_WWDTCTL0_STISM_STOP,
142  DL_WWDT_RUN_IN_SLEEP = WWDT_WWDTCTL0_STISM_CONT
144 
146 typedef enum {
150  DL_WWDT_INTERVAL_TIMER_MODE = WWDT_WWDTCTL0_MODE_INTERVAL
151 } DL_WWDT_MODE;
152 
154 typedef enum {
156  DL_WWDT_IIDX_NO_INT = WWDT_IIDX_STAT_NO_INTR,
158  DL_WWDT_IIDX_INTERVAL_TIMER = WWDT_IIDX_STAT_INTTIM
159 } DL_WWDT_IIDX;
160 
161 /* clang-format on */
162 
198 __STATIC_INLINE void DL_WWDT_initWatchdogMode(WWDT_Regs *wwdt,
199  DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period,
200  DL_WWDT_SLEEP_MODE sleepMode, DL_WWDT_WINDOW_PERIOD window0ClosedPeriod,
201  DL_WWDT_WINDOW_PERIOD window1ClosedPeriod)
202 {
203  /* Window1 is shifted because the #defines used as an input are shared
204  between window 0 and window 1 */
205  wwdt->WWDTCTL0 =
206  (WWDT_WWDTCTL0_KEY_UNLOCK_W | (uint32_t) divider | (uint32_t) period |
207  (uint32_t) sleepMode | (uint32_t) window0ClosedPeriod |
208  ((uint32_t) window1ClosedPeriod << 4));
209 }
210 
232 __STATIC_INLINE void DL_WWDT_initIntervalTimerMode(WWDT_Regs *wwdt,
233  DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period,
234  DL_WWDT_SLEEP_MODE sleepMode)
235 {
236  wwdt->WWDTCTL0 =
237  (WWDT_WWDTCTL0_KEY_UNLOCK_W | (uint32_t) divider | (uint32_t) period |
238  (uint32_t) sleepMode | WWDT_WWDTCTL0_MODE_INTERVAL);
239 }
240 
246 __STATIC_INLINE void DL_WWDT_enablePower(WWDT_Regs *wwdt)
247 {
248  wwdt->GPRCM.PWREN = (WWDT_PWREN_KEY_UNLOCK_W | WWDT_PWREN_ENABLE_ENABLE);
249 }
250 
256 __STATIC_INLINE void DL_WWDT_disablePower(WWDT_Regs *wwdt)
257 {
258  wwdt->GPRCM.PWREN = (WWDT_PWREN_KEY_UNLOCK_W | WWDT_PWREN_ENABLE_DISABLE);
259 }
260 
269 __STATIC_INLINE bool DL_WWDT_isPowerEnabled(WWDT_Regs *wwdt)
270 {
271  return ((wwdt->GPRCM.PWREN & WWDT_PWREN_ENABLE_MASK) ==
272  WWDT_PWREN_ENABLE_ENABLE);
273 }
274 
280 __STATIC_INLINE void DL_WWDT_reset(WWDT_Regs *wwdt)
281 {
282  wwdt->GPRCM.RSTCTL =
283  (WWDT_RSTCTL_KEY_UNLOCK_W | WWDT_RSTCTL_RESETSTKYCLR_CLR |
284  WWDT_RSTCTL_RESETASSERT_ASSERT);
285 }
286 
296 __STATIC_INLINE bool DL_WWDT_isReset(WWDT_Regs *wwdt)
297 {
298  return ((wwdt->GPRCM.STAT & WWDT_STAT_RESETSTKY_MASK) ==
299  WWDT_STAT_RESETSTKY_RESET);
300 }
301 
312 __STATIC_INLINE void DL_WWDT_restart(WWDT_Regs *wwdt)
313 {
314  wwdt->WWDTCNTRST = 0x00A7;
315 }
316 
327 __STATIC_INLINE bool DL_WWDT_isRunning(WWDT_Regs *wwdt)
328 {
329  return (wwdt->WWDTSTAT == WWDT_WWDTSTAT_RUN_ON);
330 }
331 
344 __STATIC_INLINE void DL_WWDT_setActiveWindow(
345  WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
346 {
347  wwdt->WWDTCTL1 = (WWDT_WWDTCTL1_KEY_UNLOCK_W | (uint32_t) window);
348 }
349 
359 __STATIC_INLINE DL_WWDT_WINDOW DL_WWDT_getActiveWindow(WWDT_Regs *wwdt)
360 {
361  uint32_t window = (wwdt->WWDTCTL1 & WWDT_WWDTCTL1_WINSEL_MASK);
362 
363  return (DL_WWDT_WINDOW)(window);
364 }
365 
375 __STATIC_INLINE DL_WWDT_SLEEP_MODE DL_WWDT_getSleepMode(WWDT_Regs *wwdt)
376 {
377  uint32_t mode = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_STISM_MASK);
378 
379  return (DL_WWDT_SLEEP_MODE)(mode);
380 }
381 
391 __STATIC_INLINE DL_WWDT_MODE DL_WWDT_getMode(WWDT_Regs *wwdt)
392 {
393  uint32_t mode = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_MODE_MASK);
394 
395  return (DL_WWDT_MODE)(mode);
396 }
397 
409 __STATIC_INLINE DL_WWDT_WINDOW_PERIOD DL_WWDT_getWindowPeriod(
410  WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
411 {
412  uint32_t period;
413 
414  if (window == DL_WWDT_WINDOW0) {
415  period = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_WINDOW0_MASK);
416  } else {
417  period = ((wwdt->WWDTCTL0 & WWDT_WWDTCTL0_WINDOW1_MASK) >> 4);
418  }
419 
420  return (DL_WWDT_WINDOW_PERIOD)(period);
421 }
422 
432 __STATIC_INLINE DL_WWDT_TIMER_PERIOD DL_WWDT_getTimerPeriod(WWDT_Regs *wwdt)
433 {
434  uint32_t period = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_PER_MASK);
435 
436  return (DL_WWDT_TIMER_PERIOD)(period);
437 }
438 
448 __STATIC_INLINE DL_WWDT_CLOCK_DIVIDE DL_WWDT_getClockDivider(WWDT_Regs *wwdt)
449 {
450  uint32_t clockDivider = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_CLKDIV_MASK);
451 
452  return (DL_WWDT_CLOCK_DIVIDE)(clockDivider);
453 }
454 
460 __STATIC_INLINE void DL_WWDT_enableInterrupt(WWDT_Regs *wwdt)
461 {
462  wwdt->CPU_INT.IMASK = WWDT_IMASK_INTTIM_SET;
463 }
464 
470 __STATIC_INLINE void DL_WWDT_disableInterrupt(WWDT_Regs *wwdt)
471 {
472  wwdt->CPU_INT.IMASK = WWDT_IMASK_INTTIM_CLR;
473 }
474 
485 __STATIC_INLINE bool DL_WWDT_isInterruptEnabled(WWDT_Regs *wwdt)
486 {
487  return ((wwdt->CPU_INT.IMASK & WWDT_IMASK_INTTIM_SET) ==
488  WWDT_IMASK_INTTIM_SET);
489 }
490 
505 __STATIC_INLINE bool DL_WWDT_getEnabledInterruptStatus(WWDT_Regs *wwdt)
506 {
507  return ((wwdt->CPU_INT.MIS & WWDT_MIS_INTTIM_SET) == WWDT_MIS_INTTIM_SET);
508 }
509 
523 __STATIC_INLINE uint32_t DL_WWDT_getRawInterruptStatus(WWDT_Regs *wwdt)
524 {
525  return (wwdt->CPU_INT.RIS & WWDT_RIS_INTTIM_SET);
526 }
527 
540 __STATIC_INLINE DL_WWDT_IIDX DL_WWDT_getPendingInterrupt(WWDT_Regs *wwdt)
541 {
542  return (DL_WWDT_IIDX)(wwdt->CPU_INT.IIDX);
543 }
544 
550 __STATIC_INLINE void DL_WWDT_clearInterruptStatus(WWDT_Regs *wwdt)
551 {
552  wwdt->CPU_INT.ICLR = WWDT_ICLR_INTTIM_CLR;
553 }
554 
555 #ifdef __cplusplus
556 }
557 #endif
558 
559 #endif /* __MSPM0_HAS_WWDT__ */
560 
561 #endif /* ti_dl_dl_wwdt__include */
562 
Definition: dl_wwdt.h:72
Definition: dl_wwdt.h:126
__STATIC_INLINE void DL_WWDT_disablePower(WWDT_Regs *wwdt)
Disables power on wwdt module.
Definition: dl_wwdt.h:256
__STATIC_INLINE bool DL_WWDT_getEnabledInterruptStatus(WWDT_Regs *wwdt)
Check interrupt flag of enabled WWDT interrupt.
Definition: dl_wwdt.h:505
Definition: dl_wwdt.h:74
__STATIC_INLINE bool DL_WWDT_isInterruptEnabled(WWDT_Regs *wwdt)
Check if WWDT interrupt is enabled.
Definition: dl_wwdt.h:485
Definition: dl_wwdt.h:108
DL_WWDT_WINDOW_PERIOD
Definition: dl_wwdt.h:98
DL_WWDT_MODE
Definition: dl_wwdt.h:146
Definition: dl_wwdt.h:150
Definition: dl_wwdt.h:130
__STATIC_INLINE void DL_WWDT_initWatchdogMode(WWDT_Regs *wwdt, DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period, DL_WWDT_SLEEP_MODE sleepMode, DL_WWDT_WINDOW_PERIOD window0ClosedPeriod, DL_WWDT_WINDOW_PERIOD window1ClosedPeriod)
Initializes the Window Watchdog Timer in watchdog mode.
Definition: dl_wwdt.h:198
__STATIC_INLINE void DL_WWDT_setActiveWindow(WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
Set the active window being used.
Definition: dl_wwdt.h:344
__STATIC_INLINE DL_WWDT_TIMER_PERIOD DL_WWDT_getTimerPeriod(WWDT_Regs *wwdt)
Get the timer period for the watchdog.
Definition: dl_wwdt.h:432
DL_WWDT_IIDX
Definition: dl_wwdt.h:154
Definition: dl_wwdt.h:80
__STATIC_INLINE void DL_WWDT_initIntervalTimerMode(WWDT_Regs *wwdt, DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period, DL_WWDT_SLEEP_MODE sleepMode)
Initializes the Window Watchdog Timer in interval timer mode.
Definition: dl_wwdt.h:232
__STATIC_INLINE void DL_WWDT_enableInterrupt(WWDT_Regs *wwdt)
Enable WWDT interrupt.
Definition: dl_wwdt.h:460
Definition: dl_wwdt.h:132
Definition: dl_wwdt.h:114
__STATIC_INLINE void DL_WWDT_enablePower(WWDT_Regs *wwdt)
Enables power on WWDT module.
Definition: dl_wwdt.h:246
Definition: dl_wwdt.h:76
Definition: dl_wwdt.h:158
__STATIC_INLINE DL_WWDT_WINDOW_PERIOD DL_WWDT_getWindowPeriod(WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
Get the window closed percentage for a watchdog window.
Definition: dl_wwdt.h:409
__STATIC_INLINE bool DL_WWDT_isPowerEnabled(WWDT_Regs *wwdt)
Returns if power on wwdt module.
Definition: dl_wwdt.h:269
Definition: dl_wwdt.h:122
Definition: dl_wwdt.h:82
DL_WWDT_SLEEP_MODE
Definition: dl_wwdt.h:138
__STATIC_INLINE uint32_t DL_WWDT_getRawInterruptStatus(WWDT_Regs *wwdt)
Check interrupt flag of any WWDT interrupt.
Definition: dl_wwdt.h:523
__STATIC_INLINE bool DL_WWDT_isRunning(WWDT_Regs *wwdt)
Checks if the Window Watchdog Timer is actively running.
Definition: dl_wwdt.h:327
__STATIC_INLINE DL_WWDT_IIDX DL_WWDT_getPendingInterrupt(WWDT_Regs *wwdt)
Get highest priority pending WWDT interrupt.
Definition: dl_wwdt.h:540
__STATIC_INLINE bool DL_WWDT_isReset(WWDT_Regs *wwdt)
Returns if wwdt peripheral was reset.
Definition: dl_wwdt.h:296
Definition: dl_wwdt.h:140
__STATIC_INLINE void DL_WWDT_reset(WWDT_Regs *wwdt)
Resets wwdt peripheral.
Definition: dl_wwdt.h:280
Definition: dl_wwdt.h:124
Definition: dl_wwdt.h:134
__STATIC_INLINE DL_WWDT_SLEEP_MODE DL_WWDT_getSleepMode(WWDT_Regs *wwdt)
Get the sleep mode being used.
Definition: dl_wwdt.h:375
Definition: dl_wwdt.h:84
DL_WWDT_WINDOW
Definition: dl_wwdt.h:90
__STATIC_INLINE DL_WWDT_CLOCK_DIVIDE DL_WWDT_getClockDivider(WWDT_Regs *wwdt)
Get the clock divider for the watchdog.
Definition: dl_wwdt.h:448
Definition: dl_wwdt.h:104
__STATIC_INLINE DL_WWDT_WINDOW DL_WWDT_getActiveWindow(WWDT_Regs *wwdt)
Get the active window being used.
Definition: dl_wwdt.h:359
Definition: dl_wwdt.h:106
Definition: dl_wwdt.h:94
Definition: dl_wwdt.h:120
Definition: dl_wwdt.h:92
Definition: dl_wwdt.h:112
__STATIC_INLINE void DL_WWDT_restart(WWDT_Regs *wwdt)
Restarts the Window Watchdog.
Definition: dl_wwdt.h:312
Definition: dl_wwdt.h:78
__STATIC_INLINE void DL_WWDT_clearInterruptStatus(WWDT_Regs *wwdt)
Clear pending WWDT interrupt.
Definition: dl_wwdt.h:550
Definition: dl_wwdt.h:128
Definition: dl_wwdt.h:100
Definition: dl_wwdt.h:156
__STATIC_INLINE DL_WWDT_MODE DL_WWDT_getMode(WWDT_Regs *wwdt)
Get the mode the watchdog is running in.
Definition: dl_wwdt.h:391
__STATIC_INLINE void DL_WWDT_disableInterrupt(WWDT_Regs *wwdt)
Disable WWDT interrupt.
Definition: dl_wwdt.h:470
DL_WWDT_TIMER_PERIOD
Definition: dl_wwdt.h:118
DL_WWDT_CLOCK_DIVIDE
Definition: dl_wwdt.h:70
Definition: dl_wwdt.h:142
Definition: dl_wwdt.h:110
Definition: dl_wwdt.h:86
Definition: dl_wwdt.h:102
Definition: dl_wwdt.h:148
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale