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 // sfr.c - Driver for the sfr Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 //*****************************************************************************\r
39 //\r
40 //! \addtogroup sfr_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 #ifndef DRIVERLIB_LEGACY_MODE\r
49 \r
50 #ifdef __MSP430_HAS_SFR__\r
51 #include "sfr.h"\r
52 \r
53 #include <assert.h>\r
54 \r
55 //*****************************************************************************\r
56 //\r
57 //! \brief Enables selected SFR interrupt sources.\r
58 //!\r
59 //! This function enables the selected SFR interrupt sources. Only the sources\r
60 //! that are enabled can be reflected to the processor interrupt; disabled\r
61 //! sources have no effect on the processor.\r
62 //!\r
63 //! \param interruptMask is the bit mask of interrupts that will be enabled.\r
64 //! Mask value is the logical OR of any of the following:\r
65 //! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable\r
66 //! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable\r
67 //! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI\r
68 //! function is chosen\r
69 //! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access\r
70 //! interrupt enable\r
71 //! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt\r
72 //! enable\r
73 //! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer\r
74 //! interrupt enable\r
75 //! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash\r
76 //! controller access violation interrupt enable\r
77 //!\r
78 //! \return None\r
79 //\r
80 //*****************************************************************************\r
81 void SFR_enableInterrupt(uint8_t interruptMask)\r
82 {\r
83 HWREG8(SFR_BASE + OFS_SFRIE1_L) |= interruptMask;\r
84 }\r
85 \r
86 //*****************************************************************************\r
87 //\r
88 //! \brief Disables selected SFR interrupt sources.\r
89 //!\r
90 //! This function disables the selected SFR interrupt sources. Only the sources\r
91 //! that are enabled can be reflected to the processor interrupt; disabled\r
92 //! sources have no effect on the processor.\r
93 //!\r
94 //! \param interruptMask is the bit mask of interrupts that will be disabled.\r
95 //! Mask value is the logical OR of any of the following:\r
96 //! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable\r
97 //! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable\r
98 //! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI\r
99 //! function is chosen\r
100 //! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access\r
101 //! interrupt enable\r
102 //! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt\r
103 //! enable\r
104 //! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer\r
105 //! interrupt enable\r
106 //! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash\r
107 //! controller access violation interrupt enable\r
108 //!\r
109 //! \return None\r
110 //\r
111 //*****************************************************************************\r
112 void SFR_disableInterrupt(uint8_t interruptMask)\r
113 {\r
114 HWREG8(SFR_BASE + OFS_SFRIE1_L) &= ~(interruptMask);\r
115 }\r
116 \r
117 //*****************************************************************************\r
118 //\r
119 //! \brief Returns the status of the selected SFR interrupt flags.\r
120 //!\r
121 //! This function returns the status of the selected SFR interrupt flags in a\r
122 //! bit mask format matching that passed into the interruptFlagMask parameter.\r
123 //!\r
124 //! \param interruptFlagMask is the bit mask of interrupt flags that the status\r
125 //! of should be returned.\r
126 //! Mask value is the logical OR of any of the following:\r
127 //! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable\r
128 //! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable\r
129 //! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI\r
130 //! function is chosen\r
131 //! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access\r
132 //! interrupt enable\r
133 //! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt\r
134 //! enable\r
135 //! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer\r
136 //! interrupt enable\r
137 //! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash\r
138 //! controller access violation interrupt enable\r
139 //!\r
140 //! \return Logical OR of any of the following:\r
141 //! - \b SFR_JTAG_OUTBOX_INTERRUPT JTAG outbox interrupt enable\r
142 //! - \b SFR_JTAG_INBOX_INTERRUPT JTAG inbox interrupt enable\r
143 //! - \b SFR_NMI_PIN_INTERRUPT NMI pin interrupt enable, if NMI\r
144 //! function is chosen\r
145 //! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT Vacant memory access\r
146 //! interrupt enable\r
147 //! - \b SFR_OSCILLATOR_FAULT_INTERRUPT Oscillator fault interrupt\r
148 //! enable\r
149 //! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT Watchdog interval timer\r
150 //! interrupt enable\r
151 //! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT Flash\r
152 //! controller access violation interrupt enable\r
153 //! \n indicating the status of the masked interrupts\r
154 //\r
155 //*****************************************************************************\r
156 uint8_t SFR_getInterruptStatus(uint8_t interruptFlagMask)\r
157 {\r
158 return HWREG8(SFR_BASE + OFS_SFRIFG1_L) & interruptFlagMask;\r
159 }\r
160 \r
161 //*****************************************************************************\r
162 //\r
163 //! \brief Clears the selected SFR interrupt flags.\r
164 //!\r
165 //! This function clears the status of the selected SFR interrupt flags.\r
166 //!\r
167 //! \param interruptFlagMask is the bit mask of interrupt flags that should be\r
168 //! cleared\r
169 //! Mask value is the logical OR of any of the following:\r
170 //! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable\r
171 //! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable\r
172 //! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI\r
173 //! function is chosen\r
174 //! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access\r
175 //! interrupt enable\r
176 //! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt\r
177 //! enable\r
178 //! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer\r
179 //! interrupt enable\r
180 //! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash\r
181 //! controller access violation interrupt enable\r
182 //!\r
183 //! \return None\r
184 //\r
185 //*****************************************************************************\r
186 void SFR_clearInterrupt(uint8_t interruptFlagMask)\r
187 {\r
188 HWREG8(SFR_BASE + OFS_SFRIFG1_L) &= ~(interruptFlagMask);\r
189 }\r
190 \r
191 //*****************************************************************************\r
192 //\r
193 //! \brief Sets the pull-up/down resistor on the ~RST/NMI pin.\r
194 //!\r
195 //! This function sets the pull-up/down resistors on the ~RST/NMI pin to the\r
196 //! settings from the pullResistorSetup parameter.\r
197 //!\r
198 //! \param pullResistorSetup is the selection of how the pull-up/down resistor\r
199 //! on the ~RST/NMI pin should be setup or disabled.\r
200 //! Valid values are:\r
201 //! - \b SFR_RESISTORDISABLE\r
202 //! - \b SFR_RESISTORENABLE_PULLUP [Default]\r
203 //! - \b SFR_RESISTORENABLE_PULLDOWN\r
204 //! \n Modified bits are \b SYSRSTUP of \b SFRRPCR register.\r
205 //!\r
206 //! \return None\r
207 //\r
208 //*****************************************************************************\r
209 void SFR_setResetPinPullResistor(uint16_t pullResistorSetup)\r
210 {\r
211 HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSRSTRE + SYSRSTUP);\r
212 HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= pullResistorSetup;\r
213 }\r
214 \r
215 //*****************************************************************************\r
216 //\r
217 //! \brief Sets the edge direction that will assert an NMI from a signal on the\r
218 //! ~RST/NMI pin if NMI function is active.\r
219 //!\r
220 //! This function sets the edge direction that will assert an NMI from a signal\r
221 //! on the ~RST/NMI pin if the NMI function is active. To activate the NMI\r
222 //! function of the ~RST/NMI use the SFR_setResetNMIPinFunction() passing\r
223 //! SFR_RESETPINFUNC_NMI into the resetPinFunction parameter.\r
224 //!\r
225 //! \param edgeDirection is the direction that the signal on the ~RST/NMI pin\r
226 //! should go to signal an interrupt, if enabled.\r
227 //! Valid values are:\r
228 //! - \b SFR_NMI_RISINGEDGE [Default]\r
229 //! - \b SFR_NMI_FALLINGEDGE\r
230 //! \n Modified bits are \b SYSNMIIES of \b SFRRPCR register.\r
231 //!\r
232 //! \return None\r
233 //\r
234 //*****************************************************************************\r
235 void SFR_setNMIEdge(uint16_t edgeDirection)\r
236 {\r
237 HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSNMIIES);\r
238 HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= edgeDirection;\r
239 }\r
240 \r
241 //*****************************************************************************\r
242 //\r
243 //! \brief Sets the function of the ~RST/NMI pin.\r
244 //!\r
245 //! This function sets the functionality of the ~RST/NMI pin, whether in reset\r
246 //! mode which will assert a reset if a low signal is observed on that pin, or\r
247 //! an NMI which will assert an interrupt from an edge of the signal dependent\r
248 //! on the setting of the edgeDirection parameter in SFR_setNMIEdge().\r
249 //!\r
250 //! \param resetPinFunction is the function that the ~RST/NMI pin should take\r
251 //! on.\r
252 //! Valid values are:\r
253 //! - \b SFR_RESETPINFUNC_RESET [Default]\r
254 //! - \b SFR_RESETPINFUNC_NMI\r
255 //! \n Modified bits are \b SYSNMI of \b SFRRPCR register.\r
256 //!\r
257 //! \return None\r
258 //\r
259 //*****************************************************************************\r
260 void SFR_setResetNMIPinFunction(uint8_t resetPinFunction)\r
261 {\r
262 HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSNMI);\r
263 HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= resetPinFunction;\r
264 }\r
265 \r
266 #endif\r
267 #endif\r
268 //*****************************************************************************\r
269 //\r
270 //! Close the doxygen group for sfr_api\r
271 //! @}\r
272 //\r
273 //*****************************************************************************\r