]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_LM3S811_GCC/hw_include/sysctl.c
Start to create an RX64M demo.
[freertos] / FreeRTOS / Demo / CORTEX_LM3S811_GCC / hw_include / sysctl.c
1 //*****************************************************************************\r
2 //\r
3 // sysctl.c - Driver for the system controller.\r
4 //\r
5 // Copyright (c) 2005,2006 Luminary Micro, Inc.  ALl rights reserved.\r
6 //\r
7 // Software License Agreement\r
8 //\r
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
10 // exclusively on LMI's Stellaris Family of microcontroller products.\r
11 //\r
12 // The software is owned by LMI and/or its suppliers, and is protected under\r
13 // applicable copyright laws.  All rights are reserved.  Any use in violation\r
14 // of the foregoing restrictions may subject the user to criminal sanctions\r
15 // under applicable laws, as well as to civil liability for the breach of the\r
16 // terms and conditions of this license.\r
17 //\r
18 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
23 //\r
24 // This is part of revision 991 of the Stellaris Driver Library.\r
25 //\r
26 //*****************************************************************************\r
27 \r
28 //*****************************************************************************\r
29 //\r
30 //! \addtogroup sysctl_api\r
31 //! @{\r
32 //\r
33 //*****************************************************************************\r
34 \r
35 #include "../hw_ints.h"\r
36 #include "../hw_memmap.h"\r
37 #include "../hw_nvic.h"\r
38 #include "../hw_sysctl.h"\r
39 #include "../hw_types.h"\r
40 #include "cpu.h"\r
41 #include "debug.h"\r
42 #include "interrupt.h"\r
43 #include "sysctl.h"\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // An array that maps the "peripheral set" number (which is stored in the upper\r
48 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL DC? register that\r
49 // contains the peripheral present bit for that peripheral.\r
50 //\r
51 //*****************************************************************************\r
52 #if defined(GROUP_puldcregs) || defined(BUILD_ALL)\r
53 const unsigned long g_pulDCRegs[] =\r
54 {\r
55     SYSCTL_DC1,\r
56     SYSCTL_DC2,\r
57     SYSCTL_DC4,\r
58     SYSCTL_DC1\r
59 };\r
60 #else\r
61 extern const unsigned long g_pulDCRegs[];\r
62 #endif\r
63 \r
64 //*****************************************************************************\r
65 //\r
66 // An array that maps the "peripheral set" number (which is stored in the upper\r
67 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SRCR? register that\r
68 // controls the software reset for that peripheral.\r
69 //\r
70 //*****************************************************************************\r
71 #if defined(GROUP_pulsrcrregs) || defined(BUILD_ALL)\r
72 const unsigned long g_pulSRCRRegs[] =\r
73 {\r
74     SYSCTL_SRCR0,\r
75     SYSCTL_SRCR1,\r
76     SYSCTL_SRCR2\r
77 };\r
78 #else\r
79 extern const unsigned long g_pulSRCRRegs[];\r
80 #endif\r
81 \r
82 //*****************************************************************************\r
83 //\r
84 // An array that maps the "peripheral set" number (which is stored in the upper\r
85 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_RCGC? register that\r
86 // controls the run-mode enable for that peripheral.\r
87 //\r
88 //*****************************************************************************\r
89 #if defined(GROUP_pulrcgcregs) || defined(BUILD_ALL)\r
90 const unsigned long g_pulRCGCRegs[] =\r
91 {\r
92     SYSCTL_RCGC0,\r
93     SYSCTL_RCGC1,\r
94     SYSCTL_RCGC2\r
95 };\r
96 #else\r
97 extern const unsigned long g_pulRCGCRegs[];\r
98 #endif\r
99 \r
100 //*****************************************************************************\r
101 //\r
102 // An array that maps the "peripheral set" number (which is stored in the upper\r
103 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SCGC? register that\r
104 // controls the sleep-mode enable for that peripheral.\r
105 //\r
106 //*****************************************************************************\r
107 #if defined(GROUP_pulscgcregs) || defined(BUILD_ALL)\r
108 const unsigned long g_pulSCGCRegs[] =\r
109 {\r
110     SYSCTL_SCGC0,\r
111     SYSCTL_SCGC1,\r
112     SYSCTL_SCGC2\r
113 };\r
114 #else\r
115 extern const unsigned long g_pulSCGCRegs[];\r
116 #endif\r
117 \r
118 //*****************************************************************************\r
119 //\r
120 // An array that maps the "peripheral set" number (which is stored in the upper\r
121 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_DCGC? register that\r
122 // controls the deep-sleep-mode enable for that peripheral.\r
123 //\r
124 //*****************************************************************************\r
125 #if defined(GROUP_pulDCGCregs) || defined(BUILD_ALL)\r
126 const unsigned long g_pulDCGCRegs[] =\r
127 {\r
128     SYSCTL_DCGC0,\r
129     SYSCTL_DCGC1,\r
130     SYSCTL_DCGC2\r
131 };\r
132 #else\r
133 extern const unsigned long g_pulDCGCRegs[];\r
134 #endif\r
135 \r
136 //*****************************************************************************\r
137 //\r
138 // An array that maps the crystal number in RCC to a frequency.\r
139 //\r
140 //*****************************************************************************\r
141 #if defined(GROUP_pulxtals) || defined(BUILD_ALL)\r
142 const unsigned long g_pulXtals[] =\r
143 {\r
144     3579545,\r
145     3686400,\r
146     4000000,\r
147     4096000,\r
148     4915200,\r
149     5000000,\r
150     5120000,\r
151     6000000,\r
152     6144000,\r
153     7372800,\r
154     8000000,\r
155     8192000\r
156 };\r
157 #else\r
158 extern const unsigned long g_pulXtals[];\r
159 #endif\r
160 \r
161 //*****************************************************************************\r
162 //\r
163 //! Gets the size of the SRAM.\r
164 //!\r
165 //! This function determines the size of the SRAM on the Stellaris device.\r
166 //!\r
167 //! \return The total number of bytes of SRAM.\r
168 //\r
169 //*****************************************************************************\r
170 #if defined(GROUP_sramsizeget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
171 unsigned long\r
172 SysCtlSRAMSizeGet(void)\r
173 {\r
174     //\r
175     // Compute the size of the SRAM.\r
176     //\r
177     return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_SRAMSZ_MASK) >> 8) + 0x100);\r
178 }\r
179 #endif\r
180 \r
181 //*****************************************************************************\r
182 //\r
183 //! Gets the size of the flash.\r
184 //!\r
185 //! This function determines the size of the flash on the Stellaris device.\r
186 //!\r
187 //! \return The total number of bytes of flash.\r
188 //\r
189 //*****************************************************************************\r
190 #if defined(GROUP_flashsizeget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
191 unsigned long\r
192 SysCtlFlashSizeGet(void)\r
193 {\r
194     //\r
195     // Compute the size of the flash.\r
196     //\r
197     return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_FLASHSZ_MASK) << 11) + 0x800);\r
198 }\r
199 #endif\r
200 \r
201 //*****************************************************************************\r
202 //\r
203 //! Determines if a pin is present.\r
204 //!\r
205 //! \param ulPin is the pin in question.\r
206 //!\r
207 //! Determines if a particular pin is present in the device.  The PWM, analog\r
208 //! comparators, ADC, and timers have a varying number of pins across members\r
209 //! of the Stellaris family; this will determine which are present on this\r
210 //! device.\r
211 //!\r
212 //! The \b ulPin argument must be only one of the following values:\r
213 //! \b SYSCTL_PIN_PWM0, \b SYSCTL_PIN_PWM1, \b SYSCTL_PIN_PWM2,\r
214 //! \b SYSCTL_PIN_PWM3, \b SYSCTL_PIN_PWM4, \b SYSCTL_PIN_PWM5,\r
215 //! \b SYSCTL_PIN_C0MINUS, \b SYSCTL_PIN_C0PLUS, \b SYSCTL_PIN_C0O,\r
216 //! \b SYSCTL_PIN_C1MINUS, \b SYSCTL_PIN_C1PLUS, \b SYSCTL_PIN_C1O,\r
217 //! \b SYSCTL_PIN_C2MINUS, \b SYSCTL_PIN_C2PLUS, \b SYSCTL_PIN_C2O,\r
218 //! \b SYSCTL_PIN_ADC0, \b SYSCTL_PIN_ADC1, \b SYSCTL_PIN_ADC2,\r
219 //! \b SYSCTL_PIN_ADC3, \b SYSCTL_PIN_ADC4, \b SYSCTL_PIN_ADC5,\r
220 //! \b SYSCTL_PIN_ADC6, \b SYSCTL_PIN_ADC7, \b SYSCTL_PIN_CCP0,\r
221 //! \b SYSCTL_PIN_CCP1, \b SYSCTL_PIN_CCP2, \b SYSCTL_PIN_CCP3,\r
222 //! \b SYSCTL_PIN_CCP4, \b SYSCTL_PIN_CCP5, or \b SYSCTL_PIN_32KHZ.\r
223 //!\r
224 //! \return Returns \b true if the specified pin is present and \b false if it\r
225 //! is not.\r
226 //\r
227 //*****************************************************************************\r
228 #if defined(GROUP_pinpresent) || defined(BUILD_ALL) || defined(DOXYGEN)\r
229 tBoolean\r
230 SysCtlPinPresent(unsigned long ulPin)\r
231 {\r
232     //\r
233     // Check the arguments.\r
234     //\r
235     ASSERT((ulPin == SYSCTL_PIN_PWM0) ||\r
236            (ulPin == SYSCTL_PIN_PWM1) ||\r
237            (ulPin == SYSCTL_PIN_PWM2) ||\r
238            (ulPin == SYSCTL_PIN_PWM3) ||\r
239            (ulPin == SYSCTL_PIN_PWM4) ||\r
240            (ulPin == SYSCTL_PIN_PWM5) ||\r
241            (ulPin == SYSCTL_PIN_C0MINUS) ||\r
242            (ulPin == SYSCTL_PIN_C0PLUS) ||\r
243            (ulPin == SYSCTL_PIN_C0O) ||\r
244            (ulPin == SYSCTL_PIN_C1MINUS) ||\r
245            (ulPin == SYSCTL_PIN_C1PLUS) ||\r
246            (ulPin == SYSCTL_PIN_C1O) ||\r
247            (ulPin == SYSCTL_PIN_C2MINUS) ||\r
248            (ulPin == SYSCTL_PIN_C2PLUS) ||\r
249            (ulPin == SYSCTL_PIN_C2O) ||\r
250            (ulPin == SYSCTL_PIN_ADC0) ||\r
251            (ulPin == SYSCTL_PIN_ADC1) ||\r
252            (ulPin == SYSCTL_PIN_ADC2) ||\r
253            (ulPin == SYSCTL_PIN_ADC3) ||\r
254            (ulPin == SYSCTL_PIN_ADC4) ||\r
255            (ulPin == SYSCTL_PIN_ADC5) ||\r
256            (ulPin == SYSCTL_PIN_ADC6) ||\r
257            (ulPin == SYSCTL_PIN_ADC7) ||\r
258            (ulPin == SYSCTL_PIN_CCP0) ||\r
259            (ulPin == SYSCTL_PIN_CCP1) ||\r
260            (ulPin == SYSCTL_PIN_CCP2) ||\r
261            (ulPin == SYSCTL_PIN_CCP3) ||\r
262            (ulPin == SYSCTL_PIN_CCP4) ||\r
263            (ulPin == SYSCTL_PIN_CCP5) ||\r
264            (ulPin == SYSCTL_PIN_32KHZ))\r
265 \r
266     //\r
267     // Determine if this pin is present.\r
268     //\r
269     if(HWREG(SYSCTL_DC3) & ulPin)\r
270     {\r
271         return(true);\r
272     }\r
273     else\r
274     {\r
275         return(false);\r
276     }\r
277 }\r
278 #endif\r
279 \r
280 //*****************************************************************************\r
281 //\r
282 //! Determines if a peripheral is present.\r
283 //!\r
284 //! \param ulPeripheral is the peripheral in question.\r
285 //!\r
286 //! Determines if a particular peripheral is present in the device.  Each\r
287 //! member of the Stellaris family has a different peripheral set; this will\r
288 //! determine which are present on this device.\r
289 //!\r
290 //! The \b ulPeripheral argument must be only one of the following values:\r
291 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
292 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
293 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
294 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
295 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
296 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,\r
297 //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_MPU, \b SYSCTL_PERIPH_TEMP, or\r
298 //! \b SYSCTL_PERIPH_PLL.\r
299 //!\r
300 //! \return Returns \b true if the specified peripheral is present and \b false\r
301 //! if it is not.\r
302 //\r
303 //*****************************************************************************\r
304 #if defined(GROUP_peripheralpresent) || defined(BUILD_ALL) || defined(DOXYGEN)\r
305 tBoolean\r
306 SysCtlPeripheralPresent(unsigned long ulPeripheral)\r
307 {\r
308     //\r
309     // Check the arguments.\r
310     //\r
311     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
312            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
313            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
314            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
315            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
316            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
317            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
318            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
319            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
320            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
321            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
322            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
323            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
324            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
325            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
326            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
327            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
328            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
329            (ulPeripheral == SYSCTL_PERIPH_GPIOE) ||\r
330            (ulPeripheral == SYSCTL_PERIPH_MPU) ||\r
331            (ulPeripheral == SYSCTL_PERIPH_TEMP) ||\r
332            (ulPeripheral == SYSCTL_PERIPH_PLL));\r
333 \r
334     //\r
335     // Read the correct DC register and determine if this peripheral exists.\r
336     //\r
337     if(HWREG(g_pulDCRegs[ulPeripheral >> 28]) & ulPeripheral & 0x0fffffff)\r
338     {\r
339         return(true);\r
340     }\r
341     else\r
342     {\r
343         return(false);\r
344     }\r
345 }\r
346 #endif\r
347 \r
348 //*****************************************************************************\r
349 //\r
350 //! Performs a software reset of a peripheral.\r
351 //!\r
352 //! \param ulPeripheral is the peripheral to reset.\r
353 //!\r
354 //! This function performs a software reset of the specified peripheral.  An\r
355 //! individual peripheral reset signal is asserted for a brief period and then\r
356 //! deasserted, leaving the peripheral in a operating state but in its reset\r
357 //! condition.\r
358 //!\r
359 //! The \b ulPeripheral argument must be only one of the following values:\r
360 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
361 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
362 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
363 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
364 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
365 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
366 //! \b SYSCTL_PERIPH_GPIOE.\r
367 //!\r
368 //! \return None.\r
369 //\r
370 //*****************************************************************************\r
371 #if defined(GROUP_peripheralreset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
372 void\r
373 SysCtlPeripheralReset(unsigned long ulPeripheral)\r
374 {\r
375     volatile unsigned long ulDelay;\r
376 \r
377     //\r
378     // Check the arguments.\r
379     //\r
380     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
381            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
382            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
383            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
384            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
385            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
386            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
387            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
388            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
389            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
390            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
391            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
392            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
393            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
394            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
395            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
396            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
397            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
398            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
399 \r
400     //\r
401     // Put the peripheral into the reset state.\r
402     //\r
403     HWREG(g_pulSRCRRegs[ulPeripheral >> 28]) |= ulPeripheral & 0x0fffffff;\r
404     \r
405     //\r
406     // Delay for a little bit.\r
407     //\r
408     for(ulDelay = 0; ulDelay < 16; ulDelay++)\r
409     {\r
410     }\r
411 \r
412     //\r
413     // Take the peripheral out of the reset state.\r
414     //\r
415     HWREG(g_pulSRCRRegs[ulPeripheral >> 28]) &= ~(ulPeripheral);\r
416 }\r
417 #endif\r
418 \r
419 //*****************************************************************************\r
420 //\r
421 //! Enables a peripheral.\r
422 //!\r
423 //! \param ulPeripheral is the peripheral to enable.\r
424 //!\r
425 //! Peripherals are enabled with this function.  At power-up, all peripherals\r
426 //! are disabled; they must be enabled in order to operate or respond to\r
427 //! register reads/writes.\r
428 //!\r
429 //! The \b ulPeripheral argument must be only one of the following values:\r
430 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
431 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
432 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
433 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
434 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
435 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
436 //! \b SYSCTL_PERIPH_GPIOE.\r
437 //!\r
438 //! \return None.\r
439 //\r
440 //*****************************************************************************\r
441 #if defined(GROUP_peripheralenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
442 void\r
443 SysCtlPeripheralEnable(unsigned long ulPeripheral)\r
444 {\r
445     //\r
446     // Check the arguments.\r
447     //\r
448     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
449            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
450            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
451            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
452            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
453            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
454            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
455            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
456            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
457            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
458            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
459            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
460            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
461            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
462            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
463            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
464            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
465            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
466            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
467 \r
468     //\r
469     // Enable this peripheral.\r
470     //\r
471     HWREG(g_pulRCGCRegs[ulPeripheral >> 28]) |= ulPeripheral & 0x0fffffff;\r
472 }\r
473 #endif\r
474 \r
475 //*****************************************************************************\r
476 //\r
477 //! Disables a peripheral.\r
478 //!\r
479 //! \param ulPeripheral is the peripheral to disable.\r
480 //!\r
481 //! Peripherals are disabled with this function.  Once disabled, they will not\r
482 //! operate or respond to register reads/writes.\r
483 //!\r
484 //! The \b ulPeripheral argument must be only one of the following values:\r
485 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
486 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
487 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
488 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
489 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
490 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
491 //! \b SYSCTL_PERIPH_GPIOE.\r
492 //!\r
493 //! \return None.\r
494 //\r
495 //*****************************************************************************\r
496 #if defined(GROUP_peripheraldisable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
497 void\r
498 SysCtlPeripheralDisable(unsigned long ulPeripheral)\r
499 {\r
500     //\r
501     // Check the arguments.\r
502     //\r
503     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
504            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
505            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
506            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
507            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
508            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
509            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
510            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
511            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
512            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
513            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
514            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
515            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
516            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
517            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
518            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
519            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
520            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
521            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
522 \r
523     //\r
524     // Disable this peripheral.\r
525     //\r
526     HWREG(g_pulRCGCRegs[ulPeripheral >> 28]) &= ~(ulPeripheral & 0x0fffffff);\r
527 }\r
528 #endif\r
529 \r
530 //*****************************************************************************\r
531 //\r
532 //! Enables a peripheral in sleep mode.\r
533 //!\r
534 //! \param ulPeripheral is the peripheral to enable in sleep mode.\r
535 //!\r
536 //! This function allows a peripheral to continue operating when the processor\r
537 //! goes into sleep mode.  Since the clocking configuration of the device does\r
538 //! not change, any peripheral can safely continue operating while the\r
539 //! processor is in sleep mode, and can therefore wake the processor from sleep\r
540 //! mode.\r
541 //!\r
542 //! Sleep mode clocking of peripherals must be enabled via\r
543 //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode\r
544 //! configuration is maintained but has no effect when sleep mode is entered.\r
545 //!\r
546 //! The \b ulPeripheral argument must be only one of the following values:\r
547 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
548 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
549 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
550 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
551 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
552 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
553 //! \b SYSCTL_PERIPH_GPIOE.\r
554 //!\r
555 //! \return None.\r
556 //\r
557 //*****************************************************************************\r
558 #if defined(GROUP_peripheralsleepenable) || defined(BUILD_ALL) || \\r
559     defined(DOXYGEN)\r
560 void\r
561 SysCtlPeripheralSleepEnable(unsigned long ulPeripheral)\r
562 {\r
563     //\r
564     // Check the arguments.\r
565     //\r
566     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
567            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
568            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
569            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
570            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
571            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
572            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
573            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
574            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
575            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
576            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
577            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
578            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
579            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
580            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
581            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
582            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
583            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
584            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
585 \r
586     //\r
587     // Enable this peripheral in sleep mode.\r
588     //\r
589     HWREG(g_pulSCGCRegs[ulPeripheral >> 28]) |= ulPeripheral & 0x0fffffff;\r
590 }\r
591 #endif\r
592 \r
593 //*****************************************************************************\r
594 //\r
595 //! Disables a peripheral in sleep mode.\r
596 //!\r
597 //! \param ulPeripheral is the peripheral to disable in sleep mode.\r
598 //!\r
599 //! This function causes a peripheral to stop operating when the processor goes\r
600 //! into sleep mode.  Disabling peripherals while in sleep mode helps to lower\r
601 //! the current draw of the device.  If enabled (via SysCtlPeripheralEnable()),\r
602 //! the peripheral will automatically resume operation when the processor\r
603 //! leaves sleep mode, maintaining its entire state from before sleep mode was\r
604 //! entered.\r
605 //!\r
606 //! Sleep mode clocking of peripherals must be enabled via\r
607 //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode\r
608 //! configuration is maintained but has no effect when sleep mode is entered.\r
609 //!\r
610 //! The \b ulPeripheral argument must be only one of the following values:\r
611 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
612 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
613 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
614 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
615 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
616 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
617 //! \b SYSCTL_PERIPH_GPIOE.\r
618 //!\r
619 //! \return None.\r
620 //\r
621 //*****************************************************************************\r
622 #if defined(GROUP_peripheralsleepdisable) || defined(BUILD_ALL) || \\r
623     defined(DOXYGEN)\r
624 void\r
625 SysCtlPeripheralSleepDisable(unsigned long ulPeripheral)\r
626 {\r
627     //\r
628     // Check the arguments.\r
629     //\r
630     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
631            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
632            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
633            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
634            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
635            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
636            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
637            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
638            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
639            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
640            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
641            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
642            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
643            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
644            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
645            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
646            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
647            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
648            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
649 \r
650     //\r
651     // Disable this peripheral in sleep mode.\r
652     //\r
653     HWREG(g_pulSCGCRegs[ulPeripheral >> 28]) &= ~(ulPeripheral & 0x0fffffff);\r
654 }\r
655 #endif\r
656 \r
657 //*****************************************************************************\r
658 //\r
659 //! Enables a peripheral in deep-sleep mode.\r
660 //!\r
661 //! \param ulPeripheral is the peripheral to enable in deep-sleep mode.\r
662 //!\r
663 //! This function allows a peripheral to continue operating when the processor\r
664 //! goes into deep-sleep mode.  Since the clocking configuration of the device\r
665 //! may change, not all peripherals can safely continue operating while the\r
666 //! processor is in sleep mode.  Those that must run at a particular frequency\r
667 //! (such as a UART) will not work as expected if the clock changes.  It is the\r
668 //! responsibility of the caller to make sensible choices.\r
669 //!\r
670 //! Deep-sleep mode clocking of peripherals must be enabled via\r
671 //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode\r
672 //! configuration is maintained but has no effect when deep-sleep mode is\r
673 //! entered.\r
674 //!\r
675 //! The \b ulPeripheral argument must be one of the following values:\r
676 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
677 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
678 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
679 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
680 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
681 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
682 //! \b SYSCTL_PERIPH_GPIOE.\r
683 //!\r
684 //! \return None.\r
685 //\r
686 //*****************************************************************************\r
687 #if defined(GROUP_peripheraldeepsleepenable) || defined(BUILD_ALL) || \\r
688     defined(DOXYGEN)\r
689 void\r
690 SysCtlPeripheralDeepSleepEnable(unsigned long ulPeripheral)\r
691 {\r
692     //\r
693     // Check the arguments.\r
694     //\r
695     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
696            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
697            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
698            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
699            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
700            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
701            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
702            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
703            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
704            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
705            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
706            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
707            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
708            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
709            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
710            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
711            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
712            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
713            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
714 \r
715     //\r
716     // Enable this peripheral in deep-sleep mode.\r
717     //\r
718     HWREG(g_pulDCGCRegs[ulPeripheral >> 28]) |= ulPeripheral & 0x0fffffff;\r
719 }\r
720 #endif\r
721 \r
722 //*****************************************************************************\r
723 //\r
724 //! Disables a peripheral in deep-sleep mode.\r
725 //!\r
726 //! \param ulPeripheral is the peripheral to disable in deep-sleep mode.\r
727 //!\r
728 //! This function causes a peripheral to stop operating when the processor goes\r
729 //! into deep-sleep mode.  Disabling peripherals while in deep-sleep mode helps\r
730 //! to lower the current draw of the device, and can keep peripherals that\r
731 //! require a particular clock frequency from operating when the clock changes\r
732 //! as a result of entering deep-sleep mode.  If enabled (via\r
733 //! SysCtlPeripheralEnable()), the peripheral will automatically resume\r
734 //! operation when the processor leaves deep-sleep mode, maintaining its entire\r
735 //! state from before deep-sleep mode was entered.\r
736 //!\r
737 //! Deep-sleep mode clocking of peripherals must be enabled via\r
738 //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode\r
739 //! configuration is maintained but has no effect when deep-sleep mode is\r
740 //! entered.\r
741 //!\r
742 //! The \b ulPeripheral argument must be one of the following values:\r
743 //! \b SYSCTL_PERIPH_PWM, \b SYSCTL_PERIPH_ADC, \b SYSCTL_PERIPH_WDOG,\r
744 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_SSI,\r
745 //! \b SYSCTL_PERIPH_QEI, \b SYSCTL_PERIPH_I2C, \b SYSCTL_PERIPH_TIMER0,\r
746 //! \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2, \b SYSCTL_PERIPH_COMP0,\r
747 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_GPIOA,\r
748 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD, or\r
749 //! \b SYSCTL_PERIPH_GPIOE.\r
750 //!\r
751 //! \return None.\r
752 //\r
753 //*****************************************************************************\r
754 #if defined(GROUP_peripheraldeepsleepdisable) || defined(BUILD_ALL) || \\r
755     defined(DOXYGEN)\r
756 void\r
757 SysCtlPeripheralDeepSleepDisable(unsigned long ulPeripheral)\r
758 {\r
759     //\r
760     // Check the arguments.\r
761     //\r
762     ASSERT((ulPeripheral == SYSCTL_PERIPH_PWM) ||\r
763            (ulPeripheral == SYSCTL_PERIPH_ADC) ||\r
764            (ulPeripheral == SYSCTL_PERIPH_WDOG) ||\r
765            (ulPeripheral == SYSCTL_PERIPH_UART0) ||\r
766            (ulPeripheral == SYSCTL_PERIPH_UART1) ||\r
767            (ulPeripheral == SYSCTL_PERIPH_SSI) ||\r
768            (ulPeripheral == SYSCTL_PERIPH_QEI) ||\r
769            (ulPeripheral == SYSCTL_PERIPH_I2C) ||\r
770            (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||\r
771            (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||\r
772            (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||\r
773            (ulPeripheral == SYSCTL_PERIPH_COMP0) ||\r
774            (ulPeripheral == SYSCTL_PERIPH_COMP1) ||\r
775            (ulPeripheral == SYSCTL_PERIPH_COMP2) ||\r
776            (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||\r
777            (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||\r
778            (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||\r
779            (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||\r
780            (ulPeripheral == SYSCTL_PERIPH_GPIOE));\r
781 \r
782     //\r
783     // Disable this peripheral in deep-sleep mode.\r
784     //\r
785     HWREG(g_pulDCGCRegs[ulPeripheral >> 28]) &= ~(ulPeripheral & 0x0fffffff);\r
786 }\r
787 #endif\r
788 \r
789 //*****************************************************************************\r
790 //\r
791 //! Controls peripheral clock gating in sleep and deep-sleep mode.\r
792 //!\r
793 //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep\r
794 //! peripheral configuration should be used and \b false if not.\r
795 //!\r
796 //! This function controls how peripherals are clocked when the processor goes\r
797 //! into sleep or deep-sleep mode.  By default, the peripherals are clocked the\r
798 //! same as in run mode; if peripheral clock gating is enabled they are clocked\r
799 //! according to the configuration set by SysCtlPeripheralSleepEnable(),\r
800 //! SysCtlPeripheralSleepDisable(), SysCtlPeripheralDeepSleepEnable(), and\r
801 //! SysCtlPeripheralDeepSleepDisable().\r
802 //!\r
803 //! \return None.\r
804 //\r
805 //*****************************************************************************\r
806 #if defined(GROUP_peripheralclockgating) || defined(BUILD_ALL) || \\r
807     defined(DOXYGEN)\r
808 void\r
809 SysCtlPeripheralClockGating(tBoolean bEnable)\r
810 {\r
811     //\r
812     // Enable peripheral clock gating as requested.\r
813     //\r
814     if(bEnable)\r
815     {\r
816         HWREG(SYSCTL_RCC) |= SYSCTL_RCC_ACG;\r
817     }\r
818     else\r
819     {\r
820         HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_ACG);\r
821     }\r
822 }\r
823 #endif\r
824 \r
825 //*****************************************************************************\r
826 //\r
827 //! Registers an interrupt handler for the system control interrupt.\r
828 //!\r
829 //! \param pfnHandler is a pointer to the function to be called when the system\r
830 //! control interrupt occurs.\r
831 //!\r
832 //! This sets the handler to be called when a system control interrupt occurs.\r
833 //! This will enable the global interrupt in the interrupt controller; specific\r
834 //! system control interrupts must be enabled via SysCtlIntEnable().  It is the\r
835 //! interrupt handler's responsibility to clear the interrupt source via\r
836 //! SysCtlIntClear().\r
837 //!\r
838 //! System control can generate interrupts when the PLL achieves lock, if the\r
839 //! internal LDO current limit is exceeded, if the internal oscillator fails,\r
840 //! if the main oscillator fails, if the internal LDO output voltage droops too\r
841 //! much, if the external voltage droops too much, or if the PLL fails.\r
842 //!\r
843 //! \sa IntRegister() for important information about registering interrupt\r
844 //! handlers.\r
845 //!\r
846 //! \return None.\r
847 //\r
848 //*****************************************************************************\r
849 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
850 void\r
851 SysCtlIntRegister(void (*pfnHandler)(void))\r
852 {\r
853     //\r
854     // Register the interrupt handler, returning an error if an error occurs.\r
855     //\r
856     IntRegister(INT_SYSCTL, pfnHandler);\r
857 \r
858     //\r
859     // Enable the system control interrupt.\r
860     //\r
861     IntEnable(INT_SYSCTL);\r
862 }\r
863 #endif\r
864 \r
865 //*****************************************************************************\r
866 //\r
867 //! Unregisters the interrupt handler for the system control interrupt.\r
868 //!\r
869 //! This function will clear the handler to be called when a system control\r
870 //! interrupt occurs.  This will also mask off the interrupt in the interrupt\r
871 //! controller so that the interrupt handler no longer is called.\r
872 //!\r
873 //! \sa IntRegister() for important information about registering interrupt\r
874 //! handlers.\r
875 //!\r
876 //! \return None.\r
877 //\r
878 //*****************************************************************************\r
879 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
880 void\r
881 SysCtlIntUnregister(void)\r
882 {\r
883     //\r
884     // Disable the interrupt.\r
885     //\r
886     IntDisable(INT_SYSCTL);\r
887 \r
888     //\r
889     // Unregister the interrupt handler.\r
890     //\r
891     IntUnregister(INT_SYSCTL);\r
892 }\r
893 #endif\r
894 \r
895 //*****************************************************************************\r
896 //\r
897 //! Enables individual system control interrupt sources.\r
898 //!\r
899 //! \param ulInts is a bit mask of the interrupt sources to be enabled.  Must\r
900 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,\r
901 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,\r
902 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.\r
903 //!\r
904 //! Enables the indicated system control interrupt sources.  Only the sources\r
905 //! that are enabled can be reflected to the processor interrupt; disabled\r
906 //! sources have no effect on the processor.\r
907 //!\r
908 //! \return None.\r
909 //\r
910 //*****************************************************************************\r
911 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
912 void\r
913 SysCtlIntEnable(unsigned long ulInts)\r
914 {\r
915     //\r
916     // Enable the specified interrupts.\r
917     //\r
918     HWREG(SYSCTL_IMC) |= ulInts;\r
919 }\r
920 #endif\r
921 \r
922 //*****************************************************************************\r
923 //\r
924 //! Disables individual system control interrupt sources.\r
925 //!\r
926 //! \param ulInts is a bit mask of the interrupt sources to be disabled.  Must\r
927 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,\r
928 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,\r
929 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.\r
930 //!\r
931 //! Disables the indicated system control interrupt sources.  Only the sources\r
932 //! that are enabled can be reflected to the processor interrupt; disabled\r
933 //! sources have no effect on the processor.\r
934 //!\r
935 //! \return None.\r
936 //\r
937 //*****************************************************************************\r
938 #if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
939 void\r
940 SysCtlIntDisable(unsigned long ulInts)\r
941 {\r
942     //\r
943     // Disable the specified interrupts.\r
944     //\r
945     HWREG(SYSCTL_IMC) &= ~(ulInts);\r
946 }\r
947 #endif\r
948 \r
949 //*****************************************************************************\r
950 //\r
951 //! Clears system control interrupt sources.\r
952 //!\r
953 //! \param ulInts is a bit mask of the interrupt sources to be cleared.  Must\r
954 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,\r
955 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,\r
956 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.\r
957 //!\r
958 //! The specified system control interrupt sources are cleared, so that they no\r
959 //! longer assert.  This must be done in the interrupt handler to keep it from\r
960 //! being called again immediately upon exit.\r
961 //!\r
962 //! \return None.\r
963 //\r
964 //*****************************************************************************\r
965 #if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)\r
966 void\r
967 SysCtlIntClear(unsigned long ulInts)\r
968 {\r
969     //\r
970     // Clear the requested interrupt sources.\r
971     //\r
972     HWREG(SYSCTL_MISC) = ulInts;\r
973 }\r
974 #endif\r
975 \r
976 //*****************************************************************************\r
977 //\r
978 //! Gets the current interrupt status.\r
979 //!\r
980 //! \param bMasked is false if the raw interrupt status is required and true if\r
981 //! the masked interrupt status is required.\r
982 //!\r
983 //! This returns the interrupt status for the system controller.  Either the\r
984 //! raw interrupt status or the status of interrupts that are allowed to\r
985 //! reflect to the processor can be returned.\r
986 //!\r
987 //! \return The current interrupt status, enumerated as a bit field of\r
988 //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT, \b SYSCTL_INT_IOSC_FAIL,\r
989 //! \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR, \b SYSCTL_INT_BOR, and\r
990 //! \b SYSCTL_INT_PLL_FAIL.\r
991 //\r
992 //*****************************************************************************\r
993 #if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)\r
994 unsigned long\r
995 SysCtlIntStatus(tBoolean bMasked)\r
996 {\r
997     //\r
998     // Return either the interrupt status or the raw interrupt status as\r
999     // requested.\r
1000     //\r
1001     if(bMasked)\r
1002     {\r
1003         return(HWREG(SYSCTL_MISC));\r
1004     }\r
1005     else\r
1006     {\r
1007         return(HWREG(SYSCTL_RIS));\r
1008     }\r
1009 }\r
1010 #endif\r
1011 \r
1012 //*****************************************************************************\r
1013 //\r
1014 //! Sets the output voltage of the LDO.\r
1015 //!\r
1016 //! \param ulVoltage is the required output voltage from the LDO.  Must be one\r
1017 //! of \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,\r
1018 //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,\r
1019 //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,\r
1020 //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.\r
1021 //!\r
1022 //! This function sets the output voltage of the LDO.  The default voltage is\r
1023 //! 2.5 V; it can be adjusted +/- 10%.\r
1024 //!\r
1025 //! \return None.\r
1026 //\r
1027 //*****************************************************************************\r
1028 #if defined(GROUP_ldoset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1029 void\r
1030 SysCtlLDOSet(unsigned long ulVoltage)\r
1031 {\r
1032     //\r
1033     // Check the arguments.\r
1034     //\r
1035     ASSERT((ulVoltage == SYSCTL_LDO_2_25V) ||\r
1036            (ulVoltage == SYSCTL_LDO_2_30V) ||\r
1037            (ulVoltage == SYSCTL_LDO_2_35V) ||\r
1038            (ulVoltage == SYSCTL_LDO_2_40V) ||\r
1039            (ulVoltage == SYSCTL_LDO_2_45V) ||\r
1040            (ulVoltage == SYSCTL_LDO_2_50V) ||\r
1041            (ulVoltage == SYSCTL_LDO_2_55V) ||\r
1042            (ulVoltage == SYSCTL_LDO_2_60V) ||\r
1043            (ulVoltage == SYSCTL_LDO_2_65V) ||\r
1044            (ulVoltage == SYSCTL_LDO_2_70V) ||\r
1045            (ulVoltage == SYSCTL_LDO_2_75V));\r
1046 \r
1047     //\r
1048     // Set the LDO voltage to the requested value.\r
1049     //\r
1050     HWREG(SYSCTL_LDOPCTL) = ulVoltage;\r
1051 }\r
1052 #endif\r
1053 \r
1054 //*****************************************************************************\r
1055 //\r
1056 //! Gets the output voltage of the LDO.\r
1057 //!\r
1058 //! This function determines the output voltage of the LDO, as specified by the\r
1059 //! control register.\r
1060 //!\r
1061 //! \return Returns the current voltage of the LDO; will be one of\r
1062 //! \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,\r
1063 //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,\r
1064 //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,\r
1065 //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.\r
1066 //\r
1067 //*****************************************************************************\r
1068 #if defined(GROUP_ldoget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1069 unsigned long\r
1070 SysCtlLDOGet(void)\r
1071 {\r
1072     //\r
1073     // Return the LDO voltage setting.\r
1074     //\r
1075     return(HWREG(SYSCTL_LDOPCTL));\r
1076 }\r
1077 #endif\r
1078 \r
1079 //*****************************************************************************\r
1080 //\r
1081 //! Configures the LDO failure control.\r
1082 //!\r
1083 //! \param ulConfig is the required LDO failure control setting; can be either\r
1084 //! \b SYSCTL_LDOCFG_ARST or \b SYSCTL_LDOCFG_NORST.\r
1085 //!\r
1086 //! This function allows the LDO to be configured to cause a processor reset\r
1087 //! when the output voltage becomes unregulated.\r
1088 //!\r
1089 //! \return None.\r
1090 //\r
1091 //*****************************************************************************\r
1092 #if defined(GROUP_ldoconfigset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1093 void\r
1094 SysCtlLDOConfigSet(unsigned long ulConfig)\r
1095 {\r
1096     //\r
1097     // Check hte arguments.\r
1098     //\r
1099     ASSERT((ulConfig == SYSCTL_LDOCFG_ARST) ||\r
1100            (ulConfig == SYSCTL_LDOCFG_NORST));\r
1101 \r
1102     //\r
1103     // Set the reset control as requested.\r
1104     //\r
1105     HWREG(SYSCTL_LDOARST) = ulConfig;\r
1106 }\r
1107 #endif\r
1108 \r
1109 //*****************************************************************************\r
1110 //\r
1111 //! Resets the device.\r
1112 //!\r
1113 //! This function will perform a software reset of the entire device.  The\r
1114 //! processor and all peripherals will be reset and all device registers will\r
1115 //! return to their default values (with the exception of the reset cause\r
1116 //! register, which will maintain its current value but have the software reset\r
1117 //! bit set as well).\r
1118 //!\r
1119 //! \return This function does not return.\r
1120 //\r
1121 //*****************************************************************************\r
1122 #if defined(GROUP_reset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1123 void\r
1124 SysCtlReset(void)\r
1125 {\r
1126     //\r
1127     // Perform a software reset request.  This will cause the device to reset,\r
1128     // no further code will be executed.\r
1129     //\r
1130     HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;\r
1131 \r
1132     //\r
1133     // The device should have reset, so this should never be reached.  Just in\r
1134     // case, loop forever.\r
1135     //\r
1136     while(1)\r
1137     {\r
1138     }\r
1139 }\r
1140 #endif\r
1141 \r
1142 //*****************************************************************************\r
1143 //\r
1144 //! Puts the processor into sleep mode.\r
1145 //!\r
1146 //! This function places the processor into sleep mode; it will not return\r
1147 //! until the processor returns to run mode.  The peripherals that are enabled\r
1148 //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the\r
1149 //! processor (if automatic clock gating is enabled with\r
1150 //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to\r
1151 //! operate).\r
1152 //!\r
1153 //! \return None.\r
1154 //\r
1155 //*****************************************************************************\r
1156 #if defined(GROUP_sleep) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1157 void\r
1158 SysCtlSleep(void)\r
1159 {\r
1160     //\r
1161     // Wait for an interrupt.\r
1162     //\r
1163     CPUwfi();\r
1164 }\r
1165 #endif\r
1166 \r
1167 //*****************************************************************************\r
1168 //\r
1169 //! Puts the processor into deep-sleep mode.\r
1170 //!\r
1171 //! This function places the processor into deep-sleep mode; it will not return\r
1172 //! until the processor returns to run mode.  The peripherals that are enabled\r
1173 //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up\r
1174 //! the processor (if automatic clock gating is enabled with\r
1175 //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to\r
1176 //! operate).\r
1177 //!\r
1178 //! \return None.\r
1179 //\r
1180 //*****************************************************************************\r
1181 #if defined(GROUP_deepsleep) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1182 void\r
1183 SysCtlDeepSleep(void)\r
1184 {\r
1185     //\r
1186     // Enable deep-sleep.\r
1187     //\r
1188     HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;\r
1189 \r
1190     //\r
1191     // Wait for an interrupt.\r
1192     //\r
1193     CPUwfi();\r
1194 \r
1195     //\r
1196     // Disable deep-sleep so that a future sleep will work correctly.\r
1197     //\r
1198     HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);\r
1199 }\r
1200 #endif\r
1201 \r
1202 //*****************************************************************************\r
1203 //\r
1204 //! Gets the reason for a reset.\r
1205 //!\r
1206 //! This function will return the reason(s) for a reset.  Since the reset\r
1207 //! reasons are sticky until either cleared by software or an external reset,\r
1208 //! multiple reset reasons may be returned if multiple resets have occurred.\r
1209 //! The reset reason will be a logical OR of \b SYSCTL_CAUSE_LDO,\r
1210 //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG, \b SYSCTL_CAUSE_BOR,\r
1211 //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.\r
1212 //!\r
1213 //! \return The reason(s) for a reset.\r
1214 //\r
1215 //*****************************************************************************\r
1216 #if defined(GROUP_resetcauseget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1217 unsigned long\r
1218 SysCtlResetCauseGet(void)\r
1219 {\r
1220     //\r
1221     // Return the reset reasons.\r
1222     //\r
1223     return(HWREG(SYSCTL_RESC));\r
1224 }\r
1225 #endif\r
1226 \r
1227 //*****************************************************************************\r
1228 //\r
1229 //! Clears reset reasons.\r
1230 //!\r
1231 //! \param ulCauses are the reset causes to be cleared; must be a logical OR of\r
1232 //! \b SYSCTL_CAUSE_LDO, \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG,\r
1233 //! \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.\r
1234 //!\r
1235 //! This function clears the specified sticky reset reasons.  Once cleared,\r
1236 //! another reset for the same reason can be detected, and a reset for a\r
1237 //! different reason can be distinguished (instead of having two reset causes\r
1238 //! set).  If the reset reason is used by an application, all reset causes\r
1239 //! should be cleared after they are retrieved with SysCtlResetCauseGet().\r
1240 //!\r
1241 //! \return None.\r
1242 //\r
1243 //*****************************************************************************\r
1244 #if defined(GROUP_resetcauseclear) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1245 void\r
1246 SysCtlResetCauseClear(unsigned long ulCauses)\r
1247 {\r
1248     //\r
1249     // Clear the given reset reasons.\r
1250     //\r
1251     HWREG(SYSCTL_RESC) &= ~(ulCauses);\r
1252 }\r
1253 #endif\r
1254 \r
1255 //*****************************************************************************\r
1256 //\r
1257 //! Configures the brown-out control.\r
1258 //!\r
1259 //! \param ulConfig is the desired configuration of the brown-out control.\r
1260 //! Must be the logical OR of \b SYSCTL_BOR_RESET and/or\r
1261 //! \b SYSCTL_BOR_RESAMPLE.\r
1262 //! \param ulDelay is the number of internal oscillator cycles to wait before\r
1263 //! resampling an asserted brown-out signal.  This value only has meaning when\r
1264 //! \b SYSCTL_BOR_RESAMPLE is set and must be less than 8192.\r
1265 //!\r
1266 //! This function configures how the brown-out control operates.  It can detect\r
1267 //! a brown-out by looking at only the brown-out output, or it can wait for it\r
1268 //! to be active for two consecutive samples separated by a configurable time.\r
1269 //! When it detects a brown-out condition, it can either reset the device or\r
1270 //! generate a processor interrupt.\r
1271 //!\r
1272 //! \return None.\r
1273 //\r
1274 //*****************************************************************************\r
1275 #if defined(GROUP_brownoutconfigset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1276 void\r
1277 SysCtlBrownOutConfigSet(unsigned long ulConfig, unsigned long ulDelay)\r
1278 {\r
1279     //\r
1280     // Check the arguments.\r
1281     //\r
1282     ASSERT(!(ulConfig & ~(SYSCTL_BOR_RESET | SYSCTL_BOR_RESAMPLE)));\r
1283     ASSERT(ulDelay < 8192);\r
1284 \r
1285     //\r
1286     // Configure the brown-out reset control.\r
1287     //\r
1288     HWREG(SYSCTL_PBORCTL) = (ulDelay << SYSCTL_PBORCTL_BOR_SH) | ulConfig;\r
1289 }\r
1290 #endif\r
1291 \r
1292 //*****************************************************************************\r
1293 //\r
1294 //! Sets the clocking of the device.\r
1295 //!\r
1296 //! \param ulConfig is the required configuration of the device clocking.\r
1297 //!\r
1298 //! This function configures the clocking of the device.  The input crystal\r
1299 //! frequency, oscillator to be used, use of the PLL, and the system clock\r
1300 //! divider are all configured with this function.\r
1301 //!\r
1302 //! The \b ulConfig parameter is the logical OR of several different values,\r
1303 //! many of which are grouped into sets where only one can be chosen.\r
1304 //!\r
1305 //! The system clock divider is chosen with one of the following values:\r
1306 //! \b SYSCTL_SYSDIV_1, \b SYSCTL_SYSDIV_2, \b SYSCTL_SYSDIV_3,\r
1307 //! \b SYSCTL_SYSDIV_4, \b SYSCTL_SYSDIV_5, \b SYSCTL_SYSDIV_6,\r
1308 //! \b SYSCTL_SYSDIV_7, \b SYSCTL_SYSDIV_8, \b SYSCTL_SYSDIV_9,\r
1309 //! \b SYSCTL_SYSDIV_10, \b SYSCTL_SYSDIV_11, \b SYSCTL_SYSDIV_12,\r
1310 //! \b SYSCTL_SYSDIV_13, \b SYSCTL_SYSDIV_14, \b SYSCTL_SYSDIV_15, or\r
1311 //! \b SYSCTL_SYSDIV_16.\r
1312 //!\r
1313 //! The use of the PLL is chosen with either \b SYSCTL_USE_PLL or\r
1314 //! \b SYSCTL_USE_OSC.\r
1315 //!\r
1316 //! The external crystal frequency is chosen with one of the following values:\r
1317 //! \b SYSCTL_XTAL_3_57MHZ, \b SYSCTL_XTAL_3_68MHZ, \b SYSCTL_XTAL_4MHZ,\r
1318 //! \b SYSCTL_XTAL_4_09MHZ, \b SYSCTL_XTAL_4_91MHZ, \b SYSCTL_XTAL_5MHZ,\r
1319 //! \b SYSCTL_XTAL_5_12MHZ, \b SYSCTL_XTAL_6MHZ, \b SYSCTL_XTAL_6_14MHZ,\r
1320 //! \b SYSCTL_XTAL_7_37MHZ, \b SYSCTL_XTAL_8MHZ, or \b SYSCTL_XTAL_8_19MHZ.\r
1321 //!\r
1322 //! The oscillator source is chosen with one of the following values:\r
1323 //! \b SYSCTL_OSC_MAIN, \b SYSCTL_OSC_INT, or \b SYSCTL_OSC_INT4.\r
1324 //!\r
1325 //! The internal and main oscillators are disabled with the\r
1326 //! \b SYSCTL_INT_OSC_DIS and \b SYSCTL_MAIN_OSC_DIS flags, respectively.\r
1327 //! The external oscillator must be enabled in order to use an external clock\r
1328 //! source.  Note that attempts to disable the oscillator used to clock the\r
1329 //! device will be prevented by the hardware.\r
1330 //!\r
1331 //! To clock the system from an external source (such as an external crystal\r
1332 //! oscillator), use \b SYSCTL_USE_OSC \b | \b SYSCTL_OSC_MAIN.  To clock the\r
1333 //! system from the main oscillator, use \b SYSCTL_USE_OSC \b |\r
1334 //! \b SYSCTL_OSC_MAIN.  To clock the system from the PLL, use\r
1335 //! \b SYSCTL_USE_PLL \b | \b SYSCTL_OSC_MAIN, and select the appropriate\r
1336 //! crystal with one of the \b SYSCTL_XTAL_xxx values.\r
1337 //!\r
1338 //! \note If selecting the PLL as the system clock source (i.e. via\r
1339 //! \b SYSCTL_USE_PLL), this function will poll the PLL lock interrupt to\r
1340 //! determine when the PLL has locked.  If an interrupt handler for the\r
1341 //! system control interrupt is in place, and it responds to and clears the\r
1342 //! PLL lock interrupt, this function will delay until its timeout has occurred\r
1343 //! instead of completing as soon as PLL lock is achieved.\r
1344 //!\r
1345 //! \return None.\r
1346 //\r
1347 //*****************************************************************************\r
1348 #if defined(GROUP_clockset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1349 void\r
1350 SysCtlClockSet(unsigned long ulConfig)\r
1351 {\r
1352     volatile unsigned long ulDelay;\r
1353     unsigned long ulRCC;\r
1354 \r
1355     //\r
1356     // Get the current value of the RCC register.\r
1357     //\r
1358     ulRCC = HWREG(SYSCTL_RCC);\r
1359 \r
1360     //\r
1361     // Bypass the PLL and system clock dividers for now.\r
1362     //\r
1363     ulRCC |= SYSCTL_RCC_BYPASS;\r
1364     ulRCC &= ~(SYSCTL_RCC_USE_SYSDIV);\r
1365 \r
1366     //\r
1367     // Write the new RCC value.\r
1368     //\r
1369     HWREG(SYSCTL_RCC) = ulRCC;\r
1370 \r
1371     //\r
1372     // Make sure that the PLL and system clock dividers are bypassed for now.\r
1373     //\r
1374     ulRCC |= SYSCTL_RCC_BYPASS;\r
1375     ulRCC &= ~(SYSCTL_RCC_USE_SYSDIV);\r
1376 \r
1377     //\r
1378     // Make sure that the required oscillators are enabled.  For now, the\r
1379     // previously enabled oscillators must be enabled along with the newly\r
1380     // requested oscillators.\r
1381     //\r
1382     ulRCC &= (~(SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS) |\r
1383               (ulConfig & (SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS)));\r
1384 \r
1385     //\r
1386     // Set the new crystal value, oscillator source, and PLL configuration.\r
1387     //\r
1388     ulRCC &= ~(SYSCTL_RCC_XTAL_MASK | SYSCTL_RCC_OSCSRC_MASK |\r
1389                SYSCTL_RCC_PWRDN | SYSCTL_RCC_OE);\r
1390     ulRCC |= ulConfig & (SYSCTL_RCC_XTAL_MASK | SYSCTL_RCC_OSCSRC_MASK |\r
1391                          SYSCTL_RCC_PWRDN | SYSCTL_RCC_OE);\r
1392 \r
1393     //\r
1394     // Clear the PLL lock interrupt.\r
1395     //\r
1396     HWREG(SYSCTL_MISC) = SYSCTL_INT_PLL_LOCK;\r
1397 \r
1398     //\r
1399     // Write the new RCC value.\r
1400     //\r
1401     HWREG(SYSCTL_RCC) = ulRCC;\r
1402 \r
1403     //\r
1404     // Wait for a bit so that new crystal value and oscillator source can take\r
1405     // effect.  One of the oscillators may need to be started as well.\r
1406     //\r
1407     for(ulDelay = 0; ulDelay < 16; ulDelay++)\r
1408     {\r
1409     }\r
1410 \r
1411     //\r
1412     // Disable the appropriate oscillators.\r
1413     //\r
1414     ulRCC &= ~(SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);\r
1415     ulRCC |= ulConfig & (SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);\r
1416 \r
1417     //\r
1418     // Write the new RCC value.\r
1419     //\r
1420     HWREG(SYSCTL_RCC) = ulRCC;\r
1421 \r
1422     //\r
1423     // Set the requested system divider.  This will not get written\r
1424     // immediately.\r
1425     //\r
1426     ulRCC &= ~(SYSCTL_RCC_SYSDIV_MASK | SYSCTL_RCC_USE_SYSDIV);\r
1427     ulRCC |= ulConfig & (SYSCTL_RCC_SYSDIV_MASK | SYSCTL_RCC_USE_SYSDIV);\r
1428 \r
1429     //\r
1430     // See if the PLL output is being used to clock the system.\r
1431     //\r
1432     if(!(ulConfig & SYSCTL_RCC_BYPASS))\r
1433     {\r
1434         //\r
1435         // Wait until the PLL has locked.\r
1436         //\r
1437         for(ulDelay = 32768; ulDelay > 0; ulDelay--)\r
1438         {\r
1439             if(HWREG(SYSCTL_RIS) & SYSCTL_INT_PLL_LOCK)\r
1440             {\r
1441                 break;\r
1442             }\r
1443         }\r
1444 \r
1445         //\r
1446         // Enable use of the PLL.\r
1447         //\r
1448         ulRCC &= ~(SYSCTL_RCC_BYPASS);\r
1449     }\r
1450 \r
1451     //\r
1452     // Write the final RCC value.\r
1453     //\r
1454     HWREG(SYSCTL_RCC) = ulRCC;\r
1455 \r
1456     //\r
1457     // Delay for a little bit so that the system divider takes effect.\r
1458     //\r
1459     for(ulDelay = 0; ulDelay < 16; ulDelay++)\r
1460     {\r
1461     }\r
1462 }\r
1463 #endif\r
1464 \r
1465 //*****************************************************************************\r
1466 //\r
1467 //! Gets the processor clock rate.\r
1468 //!\r
1469 //! This function determines the clock rate of the processor clock.  This is\r
1470 //! also the clock rate of all the peripheral modules (with the exception of\r
1471 //! PWM, which has its own clock divider).\r
1472 //!\r
1473 //! \note This will not return accurate results if SysCtlClockSet() has not\r
1474 //! been called to configure the clocking of the device, or if the device is\r
1475 //! directly clocked from a crystal (or a clock source) that is not one of the\r
1476 //! supported crystal frequencies.  In the later case, this function should be\r
1477 //! modified to directly return the correct system clock rate.\r
1478 //!\r
1479 //! \return The processor clock rate.\r
1480 //\r
1481 //*****************************************************************************\r
1482 #if defined(GROUP_clockget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1483 unsigned long\r
1484 SysCtlClockGet(void)\r
1485 {\r
1486     unsigned long ulRCC, ulPLL, ulClk;\r
1487 \r
1488     //\r
1489     // Read RCC.\r
1490     //\r
1491     ulRCC = HWREG(SYSCTL_RCC);\r
1492 \r
1493     //\r
1494     // Get the base clock rate.\r
1495     //\r
1496     switch(ulRCC & SYSCTL_RCC_OSCSRC_MASK)\r
1497     {\r
1498         //\r
1499         // The main oscillator is the clock source.  Determine its rate from\r
1500         // the crystal setting field.\r
1501         //\r
1502         case SYSCTL_RCC_OSCSRC_MAIN:\r
1503         {\r
1504             ulClk = g_pulXtals[((ulRCC & SYSCTL_RCC_XTAL_MASK) >>\r
1505                                 SYSCTL_RCC_XTAL_SHIFT) -\r
1506                                (SYSCTL_RCC_XTAL_3_57MHZ >>\r
1507                                 SYSCTL_RCC_XTAL_SHIFT)];\r
1508             break;\r
1509         }\r
1510 \r
1511         //\r
1512         // The internal oscillator is the source clock.  This is not an\r
1513         // accurate clock (it is +/- 50%); what is used is the nominal.\r
1514         //\r
1515         case SYSCTL_RCC_OSCSRC_INT:\r
1516         {\r
1517             ulClk = 15000000;\r
1518             break;\r
1519         }\r
1520 \r
1521         //\r
1522         // The internal oscillator divided by four is the source clock.  This\r
1523         // is not an accurate clock (it is +/- 50%); what is used is the\r
1524         // nominal.\r
1525         //\r
1526         case SYSCTL_RCC_OSCSRC_INT4:\r
1527         {\r
1528             ulClk = 15000000 / 4;\r
1529             break;\r
1530         }\r
1531 \r
1532         //\r
1533         // An unknown setting, so return a zero clock (i.e. an unknown clock\r
1534         // rate).\r
1535         //\r
1536         default:\r
1537         {\r
1538             return(0);\r
1539         }\r
1540     }\r
1541 \r
1542     //\r
1543     // See if the PLL is being used.\r
1544     //\r
1545     if(!(ulRCC & SYSCTL_RCC_BYPASS))\r
1546     {\r
1547         //\r
1548         // Get the PLL configuration.\r
1549         //\r
1550         ulPLL = HWREG(SYSCTL_PLLCFG);\r
1551 \r
1552         //\r
1553         // Compute the PLL output frequency based on its input frequency.\r
1554         //\r
1555         ulClk = ((ulClk * (((ulPLL & SYSCTL_PLLCFG_F_MASK) >>\r
1556                             SYSCTL_PLLCFG_F_SHIFT) + 2)) /\r
1557                  (((ulPLL & SYSCTL_PLLCFG_R_MASK) >>\r
1558                    SYSCTL_PLLCFG_R_SHIFT) + 2));\r
1559 \r
1560         //\r
1561         // See if the optional output divide by 2 is being used.\r
1562         //\r
1563         if(ulPLL & SYSCTL_PLLCFG_OD_2)\r
1564         {\r
1565             ulClk /= 2;\r
1566         }\r
1567 \r
1568         //\r
1569         // See if the optional output divide by 4 is being used.\r
1570         //\r
1571         if(ulPLL & SYSCTL_PLLCFG_OD_4)\r
1572         {\r
1573             ulClk /= 4;\r
1574         }\r
1575     }\r
1576 \r
1577     //\r
1578     // See if the system divider is being used.\r
1579     //\r
1580     if(ulRCC & SYSCTL_RCC_USE_SYSDIV)\r
1581     {\r
1582         //\r
1583         // Adjust the clock rate by the system clock divider.\r
1584         //\r
1585         ulClk /= ((ulRCC & SYSCTL_RCC_SYSDIV_MASK) >>\r
1586                   SYSCTL_RCC_SYSDIV_SHIFT) + 1;\r
1587     }\r
1588 \r
1589     //\r
1590     // Return the computed clock rate.\r
1591     //\r
1592     return(ulClk);\r
1593 }\r
1594 #endif\r
1595 \r
1596 //*****************************************************************************\r
1597 //\r
1598 //! Sets the PWM clock configuration.\r
1599 //!\r
1600 //! \param ulConfig is the configuration for the PWM clock; it must be one of\r
1601 //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,\r
1602 //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or\r
1603 //! \b SYSCTL_PWMDIV_64.\r
1604 //!\r
1605 //! This function sets the rate of the clock provided to the PWM module as a\r
1606 //! ratio of the processor clock.  This clock is used by the PWM module to\r
1607 //! generate PWM signals; its rate forms the basis for all PWM signals.\r
1608 //!\r
1609 //! \note The clocking of the PWM is dependent upon the system clock rate as\r
1610 //! configured by SysCtlClockSet().\r
1611 //!\r
1612 //! \return None.\r
1613 //\r
1614 //*****************************************************************************\r
1615 #if defined(GROUP_pwmclockset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1616 void\r
1617 SysCtlPWMClockSet(unsigned long ulConfig)\r
1618 {\r
1619     //\r
1620     // Check the arguments.\r
1621     //\r
1622     ASSERT((ulConfig == SYSCTL_PWMDIV_1) ||\r
1623            (ulConfig == SYSCTL_PWMDIV_2) ||\r
1624            (ulConfig == SYSCTL_PWMDIV_4) ||\r
1625            (ulConfig == SYSCTL_PWMDIV_8) ||\r
1626            (ulConfig == SYSCTL_PWMDIV_16) ||\r
1627            (ulConfig == SYSCTL_PWMDIV_32) ||\r
1628            (ulConfig == SYSCTL_PWMDIV_64));\r
1629 \r
1630     //\r
1631     // Check that there is a PWM block on this part.\r
1632     //\r
1633     ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);\r
1634 \r
1635     //\r
1636     // Set the PWM clock configuration into the run-mode clock configuration\r
1637     // register.\r
1638     //\r
1639     HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &\r
1640                           ~(SYSCTL_RCC_USE_PWMDIV | SYSCTL_RCC_PWMDIV_MASK)) |\r
1641                          ulConfig);\r
1642 }\r
1643 #endif\r
1644 \r
1645 //*****************************************************************************\r
1646 //\r
1647 //! Gets the current PWM clock configuration.\r
1648 //!\r
1649 //! This function returns the current PWM clock configuration.\r
1650 //!\r
1651 //! \return The current PWM clock configuration; will be one of\r
1652 //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,\r
1653 //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or\r
1654 //! \b SYSCTL_PWMDIV_64.\r
1655 //\r
1656 //*****************************************************************************\r
1657 #if defined(GROUP_pwmclockget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1658 unsigned long\r
1659 SysCtlPWMClockGet(void)\r
1660 {\r
1661     //\r
1662     // Check that there is a PWM block on this part.\r
1663     //\r
1664     ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);\r
1665 \r
1666     //\r
1667     // Return the current PWM clock configuration.\r
1668     //\r
1669     return(HWREG(SYSCTL_RCC) &\r
1670            (SYSCTL_RCC_USE_PWMDIV | SYSCTL_RCC_PWMDIV_MASK));\r
1671 }\r
1672 #endif\r
1673 \r
1674 //*****************************************************************************\r
1675 //\r
1676 //! Sets the sample rate of the ADC.\r
1677 //!\r
1678 //! \param ulSpeed is the desired sample rate of the ADC; must be one of\r
1679 //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,\r
1680 //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.\r
1681 //!\r
1682 //! This function sets the rate at which the ADC samples are captured by the\r
1683 //! ADC block.  The sampling speed may be limited by the hardware, so the\r
1684 //! sample rate may end up being slower than requested.  SysCtlADCSpeedGet()\r
1685 //! will return the actual speed in use.\r
1686 //!\r
1687 //! \return None.\r
1688 //\r
1689 //*****************************************************************************\r
1690 #if defined(GROUP_adcspeedset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1691 void\r
1692 SysCtlADCSpeedSet(unsigned long ulSpeed)\r
1693 {\r
1694     //\r
1695     // Check the arguments.\r
1696     //\r
1697     ASSERT((ulSpeed == SYSCTL_ADCSPEED_1MSPS) ||\r
1698            (ulSpeed == SYSCTL_ADCSPEED_500KSPS) ||\r
1699            (ulSpeed == SYSCTL_ADCSPEED_250KSPS) ||\r
1700            (ulSpeed == SYSCTL_ADCSPEED_125KSPS));\r
1701 \r
1702     //\r
1703     // Check that there is an ADC block on this part.\r
1704     //\r
1705     ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC);\r
1706 \r
1707     //\r
1708     // Set the ADC speed in run, sleep, and deep-sleep mode.\r
1709     //\r
1710     HWREG(SYSCTL_RCGC0) = ((HWREG(SYSCTL_RCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |\r
1711                            ulSpeed);\r
1712     HWREG(SYSCTL_SCGC0) = ((HWREG(SYSCTL_SCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |\r
1713                            ulSpeed);\r
1714     HWREG(SYSCTL_DCGC0) = ((HWREG(SYSCTL_DCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |\r
1715                            ulSpeed);\r
1716 }\r
1717 #endif\r
1718 \r
1719 //*****************************************************************************\r
1720 //\r
1721 //! Gets the sample rate of the ADC.\r
1722 //!\r
1723 //! This function gets the current sample rate of the ADC.\r
1724 //!\r
1725 //! \return Returns the current ADC sample rate; will be one of\r
1726 //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,\r
1727 //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.\r
1728 //\r
1729 //*****************************************************************************\r
1730 #if defined(GROUP_adcspeedget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1731 unsigned long\r
1732 SysCtlADCSpeedGet(void)\r
1733 {\r
1734     //\r
1735     // Check that there is an ADC block on this part.\r
1736     //\r
1737     ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC);\r
1738 \r
1739     //\r
1740     // Return the current ADC speed.\r
1741     //\r
1742     return(HWREG(SYSCTL_RCGC0) & SYSCTL_SET0_ADCSPD_MASK);\r
1743 }\r
1744 #endif\r
1745 \r
1746 //*****************************************************************************\r
1747 //\r
1748 //! Configures the internal oscillator verification timer.\r
1749 //!\r
1750 //! \param bEnable is a boolean that is \b true if the internal oscillator\r
1751 //! verification timer should be enabled.\r
1752 //!\r
1753 //! This function allows the internal oscillator verification timer to be\r
1754 //! enabled or disabled.  When enabled, an interrupt will be generated if the\r
1755 //! internal oscillator ceases to operate.\r
1756 //!\r
1757 //! \note Both oscillators (main and internal) must be enabled for this\r
1758 //! verification timer to operate as the main oscillator will verify the\r
1759 //! internal oscillator.\r
1760 //!\r
1761 //! \return None.\r
1762 //\r
1763 //*****************************************************************************\r
1764 #if defined(GROUP_boscverificationset) || defined(BUILD_ALL) || \\r
1765     defined(DOXYGEN)\r
1766 void\r
1767 SysCtlIOSCVerificationSet(tBoolean bEnable)\r
1768 {\r
1769     //\r
1770     // Enable or disable the internal oscillator verification timer as\r
1771     // requested.\r
1772     //\r
1773     if(bEnable)\r
1774     {\r
1775         HWREG(SYSCTL_RCC) |= SYSCTL_RCC_IOSCVER;\r
1776     }\r
1777     else\r
1778     {\r
1779         HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_IOSCVER);\r
1780     }\r
1781 }\r
1782 #endif\r
1783 \r
1784 //*****************************************************************************\r
1785 //\r
1786 //! Configures the main oscillator verification timer.\r
1787 //!\r
1788 //! \param bEnable is a boolean that is \b true if the main oscillator\r
1789 //! verification timer should be enabled.\r
1790 //!\r
1791 //! This function allows the main oscillator verification timer to be enabled\r
1792 //! or disabled.  When enabled, an interrupt will be generated if the main\r
1793 //! oscillator ceases to operate.\r
1794 //!\r
1795 //! \note Both oscillators (main and internal) must be enabled for this\r
1796 //! verification timer to operate as the internal oscillator will verify the\r
1797 //! main oscillator.\r
1798 //!\r
1799 //! \return None.\r
1800 //\r
1801 //*****************************************************************************\r
1802 #if defined(GROUP_moscverificationset) || defined(BUILD_ALL) || \\r
1803     defined(DOXYGEN)\r
1804 void\r
1805 SysCtlMOSCVerificationSet(tBoolean bEnable)\r
1806 {\r
1807     //\r
1808     // Enable or disable the main oscillator verification timer as requested.\r
1809     //\r
1810     if(bEnable)\r
1811     {\r
1812         HWREG(SYSCTL_RCC) |= SYSCTL_RCC_MOSCVER;\r
1813     }\r
1814     else\r
1815     {\r
1816         HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCVER);\r
1817     }\r
1818 }\r
1819 #endif\r
1820 \r
1821 //*****************************************************************************\r
1822 //\r
1823 //! Configures the PLL verification timer.\r
1824 //!\r
1825 //! \param bEnable is a boolean that is \b true if the PLL verification timer\r
1826 //! should be enabled.\r
1827 //!\r
1828 //! This function allows the PLL verification timer to be enabled or disabled.\r
1829 //! When enabled, an interrupt will be generated if the PLL ceases to operate.\r
1830 //!\r
1831 //! \note The main oscillator must be enabled for this verification timer to\r
1832 //! operate as it is used to check the PLL.  Also, the verification timer\r
1833 //! should be disabled while the PLL is being reconfigured via\r
1834 //! SysCtlClockSet().\r
1835 //!\r
1836 //! \return None.\r
1837 //\r
1838 //*****************************************************************************\r
1839 #if defined(GROUP_pllverificationset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
1840 void\r
1841 SysCtlPLLVerificationSet(tBoolean bEnable)\r
1842 {\r
1843     //\r
1844     // Enable or disable the PLL verification timer as requested.\r
1845     //\r
1846     if(bEnable)\r
1847     {\r
1848         HWREG(SYSCTL_RCC) |= SYSCTL_RCC_PLLVER;\r
1849     }\r
1850     else\r
1851     {\r
1852         HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_PLLVER);\r
1853     }\r
1854 }\r
1855 #endif\r
1856 \r
1857 //*****************************************************************************\r
1858 //\r
1859 //! Clears the clock verification status.\r
1860 //!\r
1861 //! This function clears the status of the clock verification timers, allowing\r
1862 //! them to assert another failure if detected.\r
1863 //!\r
1864 //! \return None.\r
1865 //\r
1866 //*****************************************************************************\r
1867 #if defined(GROUP_clkverificationclear) || defined(BUILD_ALL) || \\r
1868     defined(DOXYGEN)\r
1869 void\r
1870 SysCtlClkVerificationClear(void)\r
1871 {\r
1872     //\r
1873     // Clear the clock verification.\r
1874     //\r
1875     HWREG(SYSCTL_CLKVCLR) = SYSCTL_CLKVCLR_CLR;\r
1876 \r
1877     //\r
1878     // The bit does not self-reset, so clear it.\r
1879     //\r
1880     HWREG(SYSCTL_CLKVCLR) = 0;\r
1881 }\r
1882 #endif\r
1883 \r
1884 //*****************************************************************************\r
1885 //\r
1886 // Close the Doxygen group.\r
1887 //! @}\r
1888 //\r
1889 //*****************************************************************************\r