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