MSPM0C1105_C1106 Driver Library  2.05.01.00
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 
162 typedef enum {
164  DL_WWDT_CORE_HALT_STOP = WWDT_PDBGCTL_FREE_STOP,
166  DL_WWDT_CORE_HALT_FREE_RUN = WWDT_PDBGCTL_FREE_RUN,
168 
169 /* clang-format on */
170 
206 __STATIC_INLINE void DL_WWDT_initWatchdogMode(WWDT_Regs *wwdt,
207  DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period,
208  DL_WWDT_SLEEP_MODE sleepMode, DL_WWDT_WINDOW_PERIOD window0ClosedPeriod,
209  DL_WWDT_WINDOW_PERIOD window1ClosedPeriod)
210 {
211  /* Window1 is shifted because the #defines used as an input are shared
212  between window 0 and window 1 */
213  wwdt->WWDTCTL0 =
214  (WWDT_WWDTCTL0_KEY_UNLOCK_W | (uint32_t) divider | (uint32_t) period |
215  (uint32_t) sleepMode | (uint32_t) window0ClosedPeriod |
216  ((uint32_t) window1ClosedPeriod << 4));
217 }
218 
240 __STATIC_INLINE void DL_WWDT_initIntervalTimerMode(WWDT_Regs *wwdt,
241  DL_WWDT_CLOCK_DIVIDE divider, DL_WWDT_TIMER_PERIOD period,
242  DL_WWDT_SLEEP_MODE sleepMode)
243 {
244  wwdt->WWDTCTL0 =
245  (WWDT_WWDTCTL0_KEY_UNLOCK_W | (uint32_t) divider | (uint32_t) period |
246  (uint32_t) sleepMode | WWDT_WWDTCTL0_MODE_INTERVAL);
247 }
248 
258 __STATIC_INLINE void DL_WWDT_enablePower(WWDT_Regs *wwdt)
259 {
260  wwdt->GPRCM.PWREN = (WWDT_PWREN_KEY_UNLOCK_W | WWDT_PWREN_ENABLE_ENABLE);
261 }
262 
273 __STATIC_INLINE void DL_WWDT_disablePower(WWDT_Regs *wwdt)
274 {
275  wwdt->GPRCM.PWREN = (WWDT_PWREN_KEY_UNLOCK_W | WWDT_PWREN_ENABLE_DISABLE);
276 }
277 
294 __STATIC_INLINE bool DL_WWDT_isPowerEnabled(WWDT_Regs *wwdt)
295 {
296  return ((wwdt->GPRCM.PWREN & WWDT_PWREN_ENABLE_MASK) ==
297  WWDT_PWREN_ENABLE_ENABLE);
298 }
299 
305 __STATIC_INLINE void DL_WWDT_reset(WWDT_Regs *wwdt)
306 {
307  wwdt->GPRCM.RSTCTL =
308  (WWDT_RSTCTL_KEY_UNLOCK_W | WWDT_RSTCTL_RESETSTKYCLR_CLR |
309  WWDT_RSTCTL_RESETASSERT_ASSERT);
310 }
311 
321 __STATIC_INLINE bool DL_WWDT_isReset(WWDT_Regs *wwdt)
322 {
323  return ((wwdt->GPRCM.STAT & WWDT_STAT_RESETSTKY_MASK) ==
324  WWDT_STAT_RESETSTKY_RESET);
325 }
326 
337 __STATIC_INLINE void DL_WWDT_restart(WWDT_Regs *wwdt)
338 {
339  wwdt->WWDTCNTRST = 0x00A7;
340 }
341 
352 __STATIC_INLINE bool DL_WWDT_isRunning(WWDT_Regs *wwdt)
353 {
354  return (wwdt->WWDTSTAT == WWDT_WWDTSTAT_RUN_ON);
355 }
356 
369 __STATIC_INLINE void DL_WWDT_setActiveWindow(
370  WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
371 {
372  wwdt->WWDTCTL1 = (WWDT_WWDTCTL1_KEY_UNLOCK_W | (uint32_t) window);
373 }
374 
384 __STATIC_INLINE DL_WWDT_WINDOW DL_WWDT_getActiveWindow(WWDT_Regs *wwdt)
385 {
386  uint32_t window = (wwdt->WWDTCTL1 & WWDT_WWDTCTL1_WINSEL_MASK);
387 
388  return (DL_WWDT_WINDOW)(window);
389 }
390 
400 __STATIC_INLINE DL_WWDT_SLEEP_MODE DL_WWDT_getSleepMode(WWDT_Regs *wwdt)
401 {
402  uint32_t mode = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_STISM_MASK);
403 
404  return (DL_WWDT_SLEEP_MODE)(mode);
405 }
406 
416 __STATIC_INLINE DL_WWDT_MODE DL_WWDT_getMode(WWDT_Regs *wwdt)
417 {
418  uint32_t mode = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_MODE_MASK);
419 
420  return (DL_WWDT_MODE)(mode);
421 }
422 
434 __STATIC_INLINE DL_WWDT_WINDOW_PERIOD DL_WWDT_getWindowPeriod(
435  WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
436 {
437  uint32_t period;
438 
439  if (window == DL_WWDT_WINDOW0) {
440  period = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_WINDOW0_MASK);
441  } else {
442  period = ((wwdt->WWDTCTL0 & WWDT_WWDTCTL0_WINDOW1_MASK) >> 4);
443  }
444 
445  return (DL_WWDT_WINDOW_PERIOD)(period);
446 }
447 
457 __STATIC_INLINE DL_WWDT_TIMER_PERIOD DL_WWDT_getTimerPeriod(WWDT_Regs *wwdt)
458 {
459  uint32_t period = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_PER_MASK);
460 
461  return (DL_WWDT_TIMER_PERIOD)(period);
462 }
463 
473 __STATIC_INLINE DL_WWDT_CLOCK_DIVIDE DL_WWDT_getClockDivider(WWDT_Regs *wwdt)
474 {
475  uint32_t clockDivider = (wwdt->WWDTCTL0 & WWDT_WWDTCTL0_CLKDIV_MASK);
476 
477  return (DL_WWDT_CLOCK_DIVIDE)(clockDivider);
478 }
479 
485 __STATIC_INLINE void DL_WWDT_enableInterrupt(WWDT_Regs *wwdt)
486 {
487  wwdt->CPU_INT.IMASK = WWDT_IMASK_INTTIM_SET;
488 }
489 
495 __STATIC_INLINE void DL_WWDT_disableInterrupt(WWDT_Regs *wwdt)
496 {
497  wwdt->CPU_INT.IMASK = WWDT_IMASK_INTTIM_CLR;
498 }
499 
510 __STATIC_INLINE bool DL_WWDT_isInterruptEnabled(WWDT_Regs *wwdt)
511 {
512  return ((wwdt->CPU_INT.IMASK & WWDT_IMASK_INTTIM_SET) ==
513  WWDT_IMASK_INTTIM_SET);
514 }
515 
530 __STATIC_INLINE bool DL_WWDT_getEnabledInterruptStatus(WWDT_Regs *wwdt)
531 {
532  return ((wwdt->CPU_INT.MIS & WWDT_MIS_INTTIM_SET) == WWDT_MIS_INTTIM_SET);
533 }
534 
548 __STATIC_INLINE uint32_t DL_WWDT_getRawInterruptStatus(WWDT_Regs *wwdt)
549 {
550  return (wwdt->CPU_INT.RIS & WWDT_RIS_INTTIM_SET);
551 }
552 
565 __STATIC_INLINE DL_WWDT_IIDX DL_WWDT_getPendingInterrupt(WWDT_Regs *wwdt)
566 {
567  return (DL_WWDT_IIDX)(wwdt->CPU_INT.IIDX);
568 }
569 
575 __STATIC_INLINE void DL_WWDT_clearInterruptStatus(WWDT_Regs *wwdt)
576 {
577  wwdt->CPU_INT.ICLR = WWDT_ICLR_INTTIM_CLR;
578 }
579 
588 __STATIC_INLINE void DL_WWDT_setCoreHaltBehavior(
589  WWDT_Regs *wwdt, DL_WWDT_CORE_HALT haltMode)
590 {
591  wwdt->PDBGCTL = (uint32_t) haltMode;
592 }
593 
603 __STATIC_INLINE DL_WWDT_CORE_HALT DL_WWDT_getCoreHaltBehavior(WWDT_Regs *wwdt)
604 {
605  uint32_t haltMode = (wwdt->PDBGCTL & WWDT_PDBGCTL_FREE_MASK);
606  return (DL_WWDT_CORE_HALT) haltMode;
607 }
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 
613 #endif /* __MSPM0_HAS_WWDT__ */
614 
615 #endif /* ti_dl_dl_wwdt__include */
616 
Definition: dl_wwdt.h:72
Definition: dl_wwdt.h:126
__STATIC_INLINE void DL_WWDT_disablePower(WWDT_Regs *wwdt)
Disables the Peripheral Write Enable (PWREN) register for the WWDT.
Definition: dl_wwdt.h:273
__STATIC_INLINE bool DL_WWDT_getEnabledInterruptStatus(WWDT_Regs *wwdt)
Check interrupt flag of enabled WWDT interrupt.
Definition: dl_wwdt.h:530
Definition: dl_wwdt.h:74
__STATIC_INLINE bool DL_WWDT_isInterruptEnabled(WWDT_Regs *wwdt)
Check if WWDT interrupt is enabled.
Definition: dl_wwdt.h:510
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:206
__STATIC_INLINE void DL_WWDT_setActiveWindow(WWDT_Regs *wwdt, DL_WWDT_WINDOW window)
Set the active window being used.
Definition: dl_wwdt.h:369
__STATIC_INLINE DL_WWDT_TIMER_PERIOD DL_WWDT_getTimerPeriod(WWDT_Regs *wwdt)
Get the timer period for the watchdog.
Definition: dl_wwdt.h:457
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:240
__STATIC_INLINE void DL_WWDT_enableInterrupt(WWDT_Regs *wwdt)
Enable WWDT interrupt.
Definition: dl_wwdt.h:485
Definition: dl_wwdt.h:132
Definition: dl_wwdt.h:114
__STATIC_INLINE void DL_WWDT_enablePower(WWDT_Regs *wwdt)
Enables the Peripheral Write Enable (PWREN) register for the WWDT.
Definition: dl_wwdt.h:258
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:434
__STATIC_INLINE bool DL_WWDT_isPowerEnabled(WWDT_Regs *wwdt)
Returns if the Peripheral Write Enable (PWREN) register for the WWDT is enabled.
Definition: dl_wwdt.h:294
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:548
__STATIC_INLINE bool DL_WWDT_isRunning(WWDT_Regs *wwdt)
Checks if the Window Watchdog Timer is actively running.
Definition: dl_wwdt.h:352
__STATIC_INLINE DL_WWDT_IIDX DL_WWDT_getPendingInterrupt(WWDT_Regs *wwdt)
Get highest priority pending WWDT interrupt.
Definition: dl_wwdt.h:565
__STATIC_INLINE bool DL_WWDT_isReset(WWDT_Regs *wwdt)
Returns if wwdt peripheral was reset.
Definition: dl_wwdt.h:321
Definition: dl_wwdt.h:140
__STATIC_INLINE void DL_WWDT_reset(WWDT_Regs *wwdt)
Resets wwdt peripheral.
Definition: dl_wwdt.h:305
__STATIC_INLINE void DL_WWDT_setCoreHaltBehavior(WWDT_Regs *wwdt, DL_WWDT_CORE_HALT haltMode)
Configures WWDT behavior when the core is halted.
Definition: dl_wwdt.h:588
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:400
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:473
Definition: dl_wwdt.h:104
Definition: dl_wwdt.h:166
__STATIC_INLINE DL_WWDT_WINDOW DL_WWDT_getActiveWindow(WWDT_Regs *wwdt)
Get the active window being used.
Definition: dl_wwdt.h:384
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:337
Definition: dl_wwdt.h:78
Definition: dl_wwdt.h:164
__STATIC_INLINE void DL_WWDT_clearInterruptStatus(WWDT_Regs *wwdt)
Clear pending WWDT interrupt.
Definition: dl_wwdt.h:575
Definition: dl_wwdt.h:128
Definition: dl_wwdt.h:100
DL_WWDT_CORE_HALT
Definition: dl_wwdt.h:162
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:416
__STATIC_INLINE void DL_WWDT_disableInterrupt(WWDT_Regs *wwdt)
Disable WWDT interrupt.
Definition: dl_wwdt.h:495
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
__STATIC_INLINE DL_WWDT_CORE_HALT DL_WWDT_getCoreHaltBehavior(WWDT_Regs *wwdt)
Get WWDT behavior when the core is halted.
Definition: dl_wwdt.h:603
Definition: dl_wwdt.h:86
Definition: dl_wwdt.h:102
Definition: dl_wwdt.h:148
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale