1 /* --COPYRIGHT--,BSD 2 * Copyright (c) 2017, 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 * --/COPYRIGHT--*/ 32 /* Standard Includes */ 33 #include <stdint.h> 34 35 /* DriverLib Includes */ 36 #include <ti/devices/msp432p4xx/driverlib/wdt_a.h> 37 #include <ti/devices/msp432p4xx/driverlib/interrupt.h> 38 #include <ti/devices/msp432p4xx/driverlib/debug.h> 39 40 #ifdef __MCU_HAS_SYSCTL_A__ 41 #include <ti/devices/msp432p4xx/driverlib/sysctl_a.h> 42 #else 43 #include <ti/devices/msp432p4xx/driverlib/sysctl.h> 44 #endif 45 46 47 void WDT_A_holdTimer(void) 48 { 49 //Set Hold bit 50 uint8_t newWDTStatus = (WDT_A->CTL | WDT_A_CTL_HOLD); 51 52 WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus; 53 } 54 55 void WDT_A_startTimer(void) 56 { 57 //Reset Hold bit 58 uint8_t newWDTStatus = (WDT_A->CTL & ~(WDT_A_CTL_HOLD)); 59 60 WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus; 61 } 62 63 void WDT_A_clearTimer(void) 64 { 65 //Set Counter Clear bit 66 uint8_t newWDTStatus = (WDT_A->CTL | WDT_A_CTL_CNTCL); 67 68 WDT_A->CTL = WDT_A_CTL_PW + newWDTStatus; 69 } 70 71 void WDT_A_initWatchdogTimer(uint_fast8_t clockSelect, 72 uint_fast8_t clockIterations) 73 { 74 WDT_A->CTL = WDT_A_CTL_PW + WDT_A_CTL_CNTCL + WDT_A_CTL_HOLD + 75 clockSelect + clockIterations; 76 } 77 78 void WDT_A_initIntervalTimer(uint_fast8_t clockSelect, 79 uint_fast8_t clockIterations) 80 { 81 82 WDT_A->CTL = WDT_A_CTL_PW + WDT_A_CTL_CNTCL + WDT_A_CTL_HOLD + WDT_A_CTL_TMSEL 83 + clockSelect + clockIterations; 84 } 85 86 void WDT_A_setPasswordViolationReset(uint_fast8_t resetType) 87 { 88 #ifdef __MCU_HAS_SYSCTL_A__ 89 SysCtl_A_setWDTPasswordViolationResetType(resetType); 90 #else 91 SysCtl_setWDTPasswordViolationResetType(resetType); 92 #endif 93 } 94 95 void WDT_A_setTimeoutReset(uint_fast8_t resetType) 96 { 97 #ifdef __MCU_HAS_SYSCTL_A__ 98 SysCtl_A_setWDTTimeoutResetType(resetType); 99 #else 100 SysCtl_setWDTTimeoutResetType(resetType); 101 #endif 102 } 103 104 void WDT_A_registerInterrupt(void (*intHandler)(void)) 105 { 106 // 107 // Register the interrupt handler, returning an error if an error occurs. 108 // 109 Interrupt_registerInterrupt(INT_WDT_A, intHandler); 110 111 // 112 // Enable the system control interrupt. 113 // 114 Interrupt_enableInterrupt (INT_WDT_A); 115 } 116 117 void WDT_A_unregisterInterrupt(void) 118 { 119 // 120 // Disable the interrupt. 121 // 122 Interrupt_disableInterrupt (INT_WDT_A); 123 124 // 125 // Unregister the interrupt handler. 126 // 127 Interrupt_unregisterInterrupt(INT_WDT_A); 128 } 129 130