1 /* --COPYRIGHT--,BSD\r
2 * Copyright (c) 2014, Texas Instruments Incorporated\r
3 * All rights reserved.\r
4 *\r
5 * Redistribution and use in source and binary forms, with or without\r
6 * modification, are permitted provided that the following conditions\r
7 * are met:\r
8 *\r
9 * * Redistributions of source code must retain the above copyright\r
10 * notice, this list of conditions and the following disclaimer.\r
11 *\r
12 * * Redistributions in binary form must reproduce the above copyright\r
13 * notice, this list of conditions and the following disclaimer in the\r
14 * documentation and/or other materials provided with the distribution.\r
15 *\r
16 * * Neither the name of Texas Instruments Incorporated nor the names of\r
17 * its contributors may be used to endorse or promote products derived\r
18 * from this software without specific prior written permission.\r
19 *\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 * --/COPYRIGHT--*/\r
32 //*****************************************************************************\r
33 //\r
34 // wdt_a.c - Driver for the wdt_a Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 //*****************************************************************************\r
39 //\r
40 //! \addtogroup wdt_a_api\r
41 //! @{\r
42 //\r
43 //*****************************************************************************\r
44 \r
45 #include "inc/hw_regaccess.h"\r
46 #include "inc/hw_memmap.h"\r
47 \r
48 #ifdef __MSP430_HAS_WDT_A__\r
49 #include "wdt_a.h"\r
50 \r
51 #include <assert.h>\r
52 \r
53 //*****************************************************************************\r
54 //\r
55 //! \brief Holds the Watchdog Timer.\r
56 //!\r
57 //! This function stops the watchdog timer from running, that way no interrupt\r
58 //! or PUC is asserted.\r
59 //!\r
60 //! \param baseAddress is the base address of the WDT_A module.\r
61 //!\r
62 //! \return None\r
63 //\r
64 //*****************************************************************************\r
65 void WDT_A_hold(uint16_t baseAddress)\r
66 {\r
67 // Set Hold bit\r
68 uint8_t newWDTStatus =\r
69 ((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) | WDTHOLD);\r
70 \r
71 HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;\r
72 }\r
73 \r
74 //*****************************************************************************\r
75 //\r
76 //! \brief Starts the Watchdog Timer.\r
77 //!\r
78 //! This function starts the watchdog timer functionality to start counting\r
79 //! again.\r
80 //!\r
81 //! \param baseAddress is the base address of the WDT_A module.\r
82 //!\r
83 //! \return None\r
84 //\r
85 //*****************************************************************************\r
86 void WDT_A_start(uint16_t baseAddress)\r
87 {\r
88 // Reset Hold bit\r
89 uint8_t newWDTStatus =\r
90 ((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) & ~(WDTHOLD));\r
91 \r
92 HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;\r
93 }\r
94 \r
95 //*****************************************************************************\r
96 //\r
97 //! \brief Resets the timer counter of the Watchdog Timer.\r
98 //!\r
99 //! This function resets the watchdog timer to 0x0000h.\r
100 //!\r
101 //! \param baseAddress is the base address of the WDT_A module.\r
102 //!\r
103 //! \return None\r
104 //\r
105 //*****************************************************************************\r
106 void WDT_A_resetTimer(uint16_t baseAddress)\r
107 {\r
108 // Set Counter Clear bit\r
109 uint8_t newWDTStatus =\r
110 ((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) | WDTCNTCL);\r
111 \r
112 HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;\r
113 }\r
114 \r
115 //*****************************************************************************\r
116 //\r
117 //! \brief Sets the clock source for the Watchdog Timer in watchdog mode.\r
118 //!\r
119 //! This function sets the watchdog timer in watchdog mode, which will cause a\r
120 //! PUC when the timer overflows. When in the mode, a PUC can be avoided with a\r
121 //! call to WDT_A_resetTimer() before the timer runs out.\r
122 //!\r
123 //! \param baseAddress is the base address of the WDT_A module.\r
124 //! \param clockSelect is the clock source that the watchdog timer will use.\r
125 //! Valid values are:\r
126 //! - \b WDT_A_CLOCKSOURCE_SMCLK [Default]\r
127 //! - \b WDT_A_CLOCKSOURCE_ACLK\r
128 //! - \b WDT_A_CLOCKSOURCE_VLOCLK\r
129 //! - \b WDT_A_CLOCKSOURCE_XCLK\r
130 //! \n Modified bits are \b WDTSSEL of \b WDTCTL register.\r
131 //! \param clockDivider is the divider of the clock source, in turn setting the\r
132 //! watchdog timer interval.\r
133 //! Valid values are:\r
134 //! - \b WDT_A_CLOCKDIVIDER_2G\r
135 //! - \b WDT_A_CLOCKDIVIDER_128M\r
136 //! - \b WDT_A_CLOCKDIVIDER_8192K\r
137 //! - \b WDT_A_CLOCKDIVIDER_512K\r
138 //! - \b WDT_A_CLOCKDIVIDER_32K [Default]\r
139 //! - \b WDT_A_CLOCKDIVIDER_8192\r
140 //! - \b WDT_A_CLOCKDIVIDER_512\r
141 //! - \b WDT_A_CLOCKDIVIDER_64\r
142 //! \n Modified bits are \b WDTIS and \b WDTHOLD of \b WDTCTL register.\r
143 //!\r
144 //! \return None\r
145 //\r
146 //*****************************************************************************\r
147 void WDT_A_watchdogTimerInit(uint16_t baseAddress,\r
148 uint8_t clockSelect,\r
149 uint8_t clockDivider)\r
150 {\r
151 HWREG16(baseAddress + OFS_WDTCTL) =\r
152 WDTPW + WDTCNTCL + WDTHOLD + clockSelect + clockDivider;\r
153 }\r
154 \r
155 //*****************************************************************************\r
156 //\r
157 //! \brief Sets the clock source for the Watchdog Timer in timer interval mode.\r
158 //!\r
159 //! This function sets the watchdog timer as timer interval mode, which will\r
160 //! assert an interrupt without causing a PUC.\r
161 //!\r
162 //! \param baseAddress is the base address of the WDT_A module.\r
163 //! \param clockSelect is the clock source that the watchdog timer will use.\r
164 //! Valid values are:\r
165 //! - \b WDT_A_CLOCKSOURCE_SMCLK [Default]\r
166 //! - \b WDT_A_CLOCKSOURCE_ACLK\r
167 //! - \b WDT_A_CLOCKSOURCE_VLOCLK\r
168 //! - \b WDT_A_CLOCKSOURCE_XCLK\r
169 //! \n Modified bits are \b WDTSSEL of \b WDTCTL register.\r
170 //! \param clockDivider is the divider of the clock source, in turn setting the\r
171 //! watchdog timer interval.\r
172 //! Valid values are:\r
173 //! - \b WDT_A_CLOCKDIVIDER_2G\r
174 //! - \b WDT_A_CLOCKDIVIDER_128M\r
175 //! - \b WDT_A_CLOCKDIVIDER_8192K\r
176 //! - \b WDT_A_CLOCKDIVIDER_512K\r
177 //! - \b WDT_A_CLOCKDIVIDER_32K [Default]\r
178 //! - \b WDT_A_CLOCKDIVIDER_8192\r
179 //! - \b WDT_A_CLOCKDIVIDER_512\r
180 //! - \b WDT_A_CLOCKDIVIDER_64\r
181 //! \n Modified bits are \b WDTIS and \b WDTHOLD of \b WDTCTL register.\r
182 //!\r
183 //! \return None\r
184 //\r
185 //*****************************************************************************\r
186 void WDT_A_intervalTimerInit(uint16_t baseAddress,\r
187 uint8_t clockSelect,\r
188 uint8_t clockDivider)\r
189 {\r
190 HWREG16(baseAddress + OFS_WDTCTL) =\r
191 WDTPW + WDTCNTCL + WDTHOLD + WDTTMSEL + clockSelect + clockDivider;\r
192 }\r
193 \r
194 #endif\r
195 //*****************************************************************************\r
196 //\r
197 //! Close the doxygen group for wdt_a_api\r
198 //! @}\r
199 //\r
200 //*****************************************************************************\r