1*5fd0122aSMatthias Ringwald /* --COPYRIGHT--,BSD
2*5fd0122aSMatthias Ringwald * Copyright (c) 2017, Texas Instruments Incorporated
3*5fd0122aSMatthias Ringwald * All rights reserved.
4*5fd0122aSMatthias Ringwald *
5*5fd0122aSMatthias Ringwald * Redistribution and use in source and binary forms, with or without
6*5fd0122aSMatthias Ringwald * modification, are permitted provided that the following conditions
7*5fd0122aSMatthias Ringwald * are met:
8*5fd0122aSMatthias Ringwald *
9*5fd0122aSMatthias Ringwald * * Redistributions of source code must retain the above copyright
10*5fd0122aSMatthias Ringwald * notice, this list of conditions and the following disclaimer.
11*5fd0122aSMatthias Ringwald *
12*5fd0122aSMatthias Ringwald * * Redistributions in binary form must reproduce the above copyright
13*5fd0122aSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the
14*5fd0122aSMatthias Ringwald * documentation and/or other materials provided with the distribution.
15*5fd0122aSMatthias Ringwald *
16*5fd0122aSMatthias Ringwald * * Neither the name of Texas Instruments Incorporated nor the names of
17*5fd0122aSMatthias Ringwald * its contributors may be used to endorse or promote products derived
18*5fd0122aSMatthias Ringwald * from this software without specific prior written permission.
19*5fd0122aSMatthias Ringwald *
20*5fd0122aSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21*5fd0122aSMatthias Ringwald * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22*5fd0122aSMatthias Ringwald * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*5fd0122aSMatthias Ringwald * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24*5fd0122aSMatthias Ringwald * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25*5fd0122aSMatthias Ringwald * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26*5fd0122aSMatthias Ringwald * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27*5fd0122aSMatthias Ringwald * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28*5fd0122aSMatthias Ringwald * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29*5fd0122aSMatthias Ringwald * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30*5fd0122aSMatthias Ringwald * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*5fd0122aSMatthias Ringwald * --/COPYRIGHT--*/
32*5fd0122aSMatthias Ringwald /* Standard Includes */
33*5fd0122aSMatthias Ringwald #include <stdint.h>
34*5fd0122aSMatthias Ringwald
35*5fd0122aSMatthias Ringwald /* DriverLib Includes */
36*5fd0122aSMatthias Ringwald #include <ti/devices/msp432p4xx/driverlib/wdt_a.h>
37*5fd0122aSMatthias Ringwald #include <ti/devices/msp432p4xx/driverlib/interrupt.h>
38*5fd0122aSMatthias Ringwald #include <ti/devices/msp432p4xx/driverlib/debug.h>
39*5fd0122aSMatthias Ringwald
40*5fd0122aSMatthias Ringwald #ifdef __MCU_HAS_SYSCTL_A__
41*5fd0122aSMatthias Ringwald #include <ti/devices/msp432p4xx/driverlib/sysctl_a.h>
42*5fd0122aSMatthias Ringwald #else
43*5fd0122aSMatthias Ringwald #include <ti/devices/msp432p4xx/driverlib/sysctl.h>
44*5fd0122aSMatthias Ringwald #endif
45*5fd0122aSMatthias Ringwald
46*5fd0122aSMatthias Ringwald
WDT_A_holdTimer(void)47*5fd0122aSMatthias Ringwald void WDT_A_holdTimer(void)
48*5fd0122aSMatthias Ringwald {
49*5fd0122aSMatthias Ringwald //Set Hold bit
50*5fd0122aSMatthias Ringwald uint8_t newWDTStatus = (WDT_A->CTL | WDT_A_CTL_HOLD);
51*5fd0122aSMatthias Ringwald
52*5fd0122aSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus;
53*5fd0122aSMatthias Ringwald }
54*5fd0122aSMatthias Ringwald
WDT_A_startTimer(void)55*5fd0122aSMatthias Ringwald void WDT_A_startTimer(void)
56*5fd0122aSMatthias Ringwald {
57*5fd0122aSMatthias Ringwald //Reset Hold bit
58*5fd0122aSMatthias Ringwald uint8_t newWDTStatus = (WDT_A->CTL & ~(WDT_A_CTL_HOLD));
59*5fd0122aSMatthias Ringwald
60*5fd0122aSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus;
61*5fd0122aSMatthias Ringwald }
62*5fd0122aSMatthias Ringwald
WDT_A_clearTimer(void)63*5fd0122aSMatthias Ringwald void WDT_A_clearTimer(void)
64*5fd0122aSMatthias Ringwald {
65*5fd0122aSMatthias Ringwald //Set Counter Clear bit
66*5fd0122aSMatthias Ringwald uint8_t newWDTStatus = (WDT_A->CTL | WDT_A_CTL_CNTCL);
67*5fd0122aSMatthias Ringwald
68*5fd0122aSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus;
69*5fd0122aSMatthias Ringwald }
70*5fd0122aSMatthias Ringwald
WDT_A_initWatchdogTimer(uint_fast8_t clockSelect,uint_fast8_t clockIterations)71*5fd0122aSMatthias Ringwald void WDT_A_initWatchdogTimer(uint_fast8_t clockSelect,
72*5fd0122aSMatthias Ringwald uint_fast8_t clockIterations)
73*5fd0122aSMatthias Ringwald {
74*5fd0122aSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW + WDT_A_CTL_CNTCL + WDT_A_CTL_HOLD +
75*5fd0122aSMatthias Ringwald clockSelect + clockIterations;
76*5fd0122aSMatthias Ringwald }
77*5fd0122aSMatthias Ringwald
WDT_A_initIntervalTimer(uint_fast8_t clockSelect,uint_fast8_t clockIterations)78*5fd0122aSMatthias Ringwald void WDT_A_initIntervalTimer(uint_fast8_t clockSelect,
79*5fd0122aSMatthias Ringwald uint_fast8_t clockIterations)
80*5fd0122aSMatthias Ringwald {
81*5fd0122aSMatthias Ringwald
82*5fd0122aSMatthias Ringwald WDT_A->CTL = WDT_A_CTL_PW + WDT_A_CTL_CNTCL + WDT_A_CTL_HOLD + WDT_A_CTL_TMSEL
83*5fd0122aSMatthias Ringwald + clockSelect + clockIterations;
84*5fd0122aSMatthias Ringwald }
85*5fd0122aSMatthias Ringwald
WDT_A_setPasswordViolationReset(uint_fast8_t resetType)86*5fd0122aSMatthias Ringwald void WDT_A_setPasswordViolationReset(uint_fast8_t resetType)
87*5fd0122aSMatthias Ringwald {
88*5fd0122aSMatthias Ringwald #ifdef __MCU_HAS_SYSCTL_A__
89*5fd0122aSMatthias Ringwald SysCtl_A_setWDTPasswordViolationResetType(resetType);
90*5fd0122aSMatthias Ringwald #else
91*5fd0122aSMatthias Ringwald SysCtl_setWDTPasswordViolationResetType(resetType);
92*5fd0122aSMatthias Ringwald #endif
93*5fd0122aSMatthias Ringwald }
94*5fd0122aSMatthias Ringwald
WDT_A_setTimeoutReset(uint_fast8_t resetType)95*5fd0122aSMatthias Ringwald void WDT_A_setTimeoutReset(uint_fast8_t resetType)
96*5fd0122aSMatthias Ringwald {
97*5fd0122aSMatthias Ringwald #ifdef __MCU_HAS_SYSCTL_A__
98*5fd0122aSMatthias Ringwald SysCtl_A_setWDTTimeoutResetType(resetType);
99*5fd0122aSMatthias Ringwald #else
100*5fd0122aSMatthias Ringwald SysCtl_setWDTTimeoutResetType(resetType);
101*5fd0122aSMatthias Ringwald #endif
102*5fd0122aSMatthias Ringwald }
103*5fd0122aSMatthias Ringwald
WDT_A_registerInterrupt(void (* intHandler)(void))104*5fd0122aSMatthias Ringwald void WDT_A_registerInterrupt(void (*intHandler)(void))
105*5fd0122aSMatthias Ringwald {
106*5fd0122aSMatthias Ringwald //
107*5fd0122aSMatthias Ringwald // Register the interrupt handler, returning an error if an error occurs.
108*5fd0122aSMatthias Ringwald //
109*5fd0122aSMatthias Ringwald Interrupt_registerInterrupt(INT_WDT_A, intHandler);
110*5fd0122aSMatthias Ringwald
111*5fd0122aSMatthias Ringwald //
112*5fd0122aSMatthias Ringwald // Enable the system control interrupt.
113*5fd0122aSMatthias Ringwald //
114*5fd0122aSMatthias Ringwald Interrupt_enableInterrupt (INT_WDT_A);
115*5fd0122aSMatthias Ringwald }
116*5fd0122aSMatthias Ringwald
WDT_A_unregisterInterrupt(void)117*5fd0122aSMatthias Ringwald void WDT_A_unregisterInterrupt(void)
118*5fd0122aSMatthias Ringwald {
119*5fd0122aSMatthias Ringwald //
120*5fd0122aSMatthias Ringwald // Disable the interrupt.
121*5fd0122aSMatthias Ringwald //
122*5fd0122aSMatthias Ringwald Interrupt_disableInterrupt (INT_WDT_A);
123*5fd0122aSMatthias Ringwald
124*5fd0122aSMatthias Ringwald //
125*5fd0122aSMatthias Ringwald // Unregister the interrupt handler.
126*5fd0122aSMatthias Ringwald //
127*5fd0122aSMatthias Ringwald Interrupt_unregisterInterrupt(INT_WDT_A);
128*5fd0122aSMatthias Ringwald }
129*5fd0122aSMatthias Ringwald
130