1 //*****************************************************************************
2 //
3 // sysctl.c - Driver for the system controller.
4 //
5 // Copyright (c) 2005-2012 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39
40 //*****************************************************************************
41 //
42 //! \addtogroup sysctl_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include "inc/hw_ints.h"
48 #include "inc/hw_nvic.h"
49 #include "inc/hw_sysctl.h"
50 #include "inc/hw_types.h"
51 #include "driverlib/cpu.h"
52 #include "driverlib/debug.h"
53 #include "driverlib/interrupt.h"
54 #include "driverlib/sysctl.h"
55
56 //*****************************************************************************
57 //
58 // A macro used to determine whether the target part uses the new SysCtl
59 // register layout.
60 //
61 //*****************************************************************************
62
63 //*****************************************************************************
64 //
65 // This macro extracts the array index out of the peripheral number.
66 //
67 //*****************************************************************************
68 #define SYSCTL_PERIPH_INDEX(a) (((a) >> 28) & 0xf)
69
70 //*****************************************************************************
71 //
72 // This macro constructs the peripheral bit mask from the peripheral number.
73 //
74 //*****************************************************************************
75 #define SYSCTL_PERIPH_MASK(a) (((a) & 0xffff) << (((a) & 0x001f0000) >> 16))
76
77 //*****************************************************************************
78 //
79 // An array that maps the "peripheral set" number (which is stored in the upper
80 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL DC? register that
81 // contains the peripheral present bit for that peripheral.
82 //
83 //*****************************************************************************
84 static const unsigned long g_pulDCRegs[] =
85 {
86 SYSCTL_DC1,
87 SYSCTL_DC2,
88 SYSCTL_DC4,
89 SYSCTL_DC1
90 };
91
92 //*****************************************************************************
93 //
94 // An array that maps the "peripheral set" number (which is stored in the upper
95 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SRCR? register that
96 // controls the software reset for that peripheral.
97 //
98 //*****************************************************************************
99 static const unsigned long g_pulSRCRRegs[] =
100 {
101 SYSCTL_SRCR0,
102 SYSCTL_SRCR1,
103 SYSCTL_SRCR2
104 };
105
106 //*****************************************************************************
107 //
108 // An array that maps the "peripheral set" number (which is stored in the upper
109 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_RCGC? register that
110 // controls the run-mode enable for that peripheral.
111 //
112 //*****************************************************************************
113 static const unsigned long g_pulRCGCRegs[] =
114 {
115 SYSCTL_RCGC0,
116 SYSCTL_RCGC1,
117 SYSCTL_RCGC2
118 };
119
120 //*****************************************************************************
121 //
122 // An array that maps the "peripheral set" number (which is stored in the upper
123 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_SCGC? register that
124 // controls the sleep-mode enable for that peripheral.
125 //
126 //*****************************************************************************
127 static const unsigned long g_pulSCGCRegs[] =
128 {
129 SYSCTL_SCGC0,
130 SYSCTL_SCGC1,
131 SYSCTL_SCGC2
132 };
133
134 //*****************************************************************************
135 //
136 // An array that maps the "peripheral set" number (which is stored in the upper
137 // nibble of the SYSCTL_PERIPH_* defines) to the SYSCTL_DCGC? register that
138 // controls the deep-sleep-mode enable for that peripheral.
139 //
140 //*****************************************************************************
141 static const unsigned long g_pulDCGCRegs[] =
142 {
143 SYSCTL_DCGC0,
144 SYSCTL_DCGC1,
145 SYSCTL_DCGC2
146 };
147
148 //*****************************************************************************
149 //
150 // An array that maps the crystal number in RCC to a frequency.
151 //
152 //*****************************************************************************
153 static const unsigned long g_pulXtals[] =
154 {
155 1000000,
156 1843200,
157 2000000,
158 2457600,
159 3579545,
160 3686400,
161 4000000,
162 4096000,
163 4915200,
164 5000000,
165 5120000,
166 6000000,
167 6144000,
168 7372800,
169 8000000,
170 8192000,
171 10000000,
172 12000000,
173 12288000,
174 13560000,
175 14318180,
176 16000000,
177 16384000,
178 18000000,
179 20000000,
180 24000000,
181 25000000
182 };
183
184 //*****************************************************************************
185 //
186 // The base addresses of the various peripheral control registers.
187 //
188 //*****************************************************************************
189 #define SYSCTL_PPBASE 0x400fe300
190 #define SYSCTL_SRBASE 0x400fe500
191 #define SYSCTL_RCGCBASE 0x400fe600
192 #define SYSCTL_SCGCBASE 0x400fe700
193 #define SYSCTL_DCGCBASE 0x400fe800
194 #define SYSCTL_PCBASE 0x400fe900
195 #define SYSCTL_PRBASE 0x400fea00
196
197 //*****************************************************************************
198 //
199 //! \internal
200 //! Checks a peripheral identifier.
201 //!
202 //! \param ulPeripheral is the peripheral identifier.
203 //!
204 //! This function determines if a peripheral identifier is valid.
205 //!
206 //! \return Returns \b true if the peripheral identifier is valid and \b false
207 //! otherwise.
208 //
209 //*****************************************************************************
210 #ifdef DEBUG
211 static tBoolean
SysCtlPeripheralValid(unsigned long ulPeripheral)212 SysCtlPeripheralValid(unsigned long ulPeripheral)
213 {
214 return((ulPeripheral == SYSCTL_PERIPH_ADC0) ||
215 (ulPeripheral == SYSCTL_PERIPH_ADC1) ||
216 (ulPeripheral == SYSCTL_PERIPH_CAN0) ||
217 (ulPeripheral == SYSCTL_PERIPH_CAN1) ||
218 (ulPeripheral == SYSCTL_PERIPH_CAN2) ||
219 (ulPeripheral == SYSCTL_PERIPH_COMP0) ||
220 (ulPeripheral == SYSCTL_PERIPH_COMP1) ||
221 (ulPeripheral == SYSCTL_PERIPH_COMP2) ||
222 (ulPeripheral == SYSCTL_PERIPH_EEPROM0) ||
223 (ulPeripheral == SYSCTL_PERIPH_EPI0) ||
224 (ulPeripheral == SYSCTL_PERIPH_ETH) ||
225 (ulPeripheral == SYSCTL_PERIPH_FAN0) ||
226 (ulPeripheral == SYSCTL_PERIPH_GPIOA) ||
227 (ulPeripheral == SYSCTL_PERIPH_GPIOB) ||
228 (ulPeripheral == SYSCTL_PERIPH_GPIOC) ||
229 (ulPeripheral == SYSCTL_PERIPH_GPIOD) ||
230 (ulPeripheral == SYSCTL_PERIPH_GPIOE) ||
231 (ulPeripheral == SYSCTL_PERIPH_GPIOF) ||
232 (ulPeripheral == SYSCTL_PERIPH_GPIOG) ||
233 (ulPeripheral == SYSCTL_PERIPH_GPIOH) ||
234 (ulPeripheral == SYSCTL_PERIPH_GPIOJ) ||
235 (ulPeripheral == SYSCTL_PERIPH_GPIOK) ||
236 (ulPeripheral == SYSCTL_PERIPH_GPIOL) ||
237 (ulPeripheral == SYSCTL_PERIPH_GPIOM) ||
238 (ulPeripheral == SYSCTL_PERIPH_GPION) ||
239 (ulPeripheral == SYSCTL_PERIPH_GPIOP) ||
240 (ulPeripheral == SYSCTL_PERIPH_GPIOQ) ||
241 (ulPeripheral == SYSCTL_PERIPH_GPIOR) ||
242 (ulPeripheral == SYSCTL_PERIPH_GPIOS) ||
243 (ulPeripheral == SYSCTL_PERIPH_HIBERNATE) ||
244 (ulPeripheral == SYSCTL_PERIPH_I2C0) ||
245 (ulPeripheral == SYSCTL_PERIPH_I2C1) ||
246 (ulPeripheral == SYSCTL_PERIPH_I2C2) ||
247 (ulPeripheral == SYSCTL_PERIPH_I2C3) ||
248 (ulPeripheral == SYSCTL_PERIPH_I2C4) ||
249 (ulPeripheral == SYSCTL_PERIPH_I2C5) ||
250 (ulPeripheral == SYSCTL_PERIPH_I2S0) ||
251 (ulPeripheral == SYSCTL_PERIPH_IEEE1588) ||
252 (ulPeripheral == SYSCTL_PERIPH_LPC0) ||
253 (ulPeripheral == SYSCTL_PERIPH_MPU) ||
254 (ulPeripheral == SYSCTL_PERIPH_PECI0) ||
255 (ulPeripheral == SYSCTL_PERIPH_PLL) ||
256 (ulPeripheral == SYSCTL_PERIPH_PWM0) ||
257 (ulPeripheral == SYSCTL_PERIPH_PWM1) ||
258 (ulPeripheral == SYSCTL_PERIPH_QEI0) ||
259 (ulPeripheral == SYSCTL_PERIPH_QEI1) ||
260 (ulPeripheral == SYSCTL_PERIPH_SSI0) ||
261 (ulPeripheral == SYSCTL_PERIPH_SSI1) ||
262 (ulPeripheral == SYSCTL_PERIPH_SSI2) ||
263 (ulPeripheral == SYSCTL_PERIPH_SSI3) ||
264 (ulPeripheral == SYSCTL_PERIPH_TEMP) ||
265 (ulPeripheral == SYSCTL_PERIPH_TIMER0) ||
266 (ulPeripheral == SYSCTL_PERIPH_TIMER1) ||
267 (ulPeripheral == SYSCTL_PERIPH_TIMER2) ||
268 (ulPeripheral == SYSCTL_PERIPH_TIMER3) ||
269 (ulPeripheral == SYSCTL_PERIPH_TIMER4) ||
270 (ulPeripheral == SYSCTL_PERIPH_TIMER5) ||
271 (ulPeripheral == SYSCTL_PERIPH_UART0) ||
272 (ulPeripheral == SYSCTL_PERIPH_UART1) ||
273 (ulPeripheral == SYSCTL_PERIPH_UART2) ||
274 (ulPeripheral == SYSCTL_PERIPH_UART3) ||
275 (ulPeripheral == SYSCTL_PERIPH_UART4) ||
276 (ulPeripheral == SYSCTL_PERIPH_UART5) ||
277 (ulPeripheral == SYSCTL_PERIPH_UART6) ||
278 (ulPeripheral == SYSCTL_PERIPH_UART7) ||
279 (ulPeripheral == SYSCTL_PERIPH_UDMA) ||
280 (ulPeripheral == SYSCTL_PERIPH_USB0) ||
281 (ulPeripheral == SYSCTL_PERIPH_WDOG0) ||
282 (ulPeripheral == SYSCTL_PERIPH_WDOG1) ||
283 (ulPeripheral == SYSCTL_PERIPH_WTIMER0) ||
284 (ulPeripheral == SYSCTL_PERIPH_WTIMER1) ||
285 (ulPeripheral == SYSCTL_PERIPH_WTIMER2) ||
286 (ulPeripheral == SYSCTL_PERIPH_WTIMER3) ||
287 (ulPeripheral == SYSCTL_PERIPH_WTIMER4) ||
288 (ulPeripheral == SYSCTL_PERIPH_WTIMER5));
289 }
290 #endif
291
292 //*****************************************************************************
293 //
294 // A map of old peripheral defines to new peripheral defines. Note that the
295 // new peripheral defines do not work on parts that precede Blizzard class.
296 //
297 //*****************************************************************************
298 static const unsigned long g_ppulPeripheralMap[][2] =
299 {
300 { SYSCTL_PERIPH_ADC0, SYSCTL_PERIPH2_ADC0 },
301 { SYSCTL_PERIPH_ADC1, SYSCTL_PERIPH2_ADC1 },
302 { SYSCTL_PERIPH_CAN0, SYSCTL_PERIPH2_CAN0 },
303 { SYSCTL_PERIPH_CAN1, SYSCTL_PERIPH2_CAN1 },
304 { SYSCTL_PERIPH_CAN2, SYSCTL_PERIPH2_CAN2 },
305 { SYSCTL_PERIPH_COMP0, SYSCTL_PERIPH2_COMP0 },
306 { SYSCTL_PERIPH_COMP1, SYSCTL_PERIPH2_COMP0 },
307 { SYSCTL_PERIPH_COMP2, SYSCTL_PERIPH2_COMP0 },
308 { SYSCTL_PERIPH_GPIOA, SYSCTL_PERIPH2_GPIOA },
309 { SYSCTL_PERIPH_GPIOB, SYSCTL_PERIPH2_GPIOB },
310 { SYSCTL_PERIPH_GPIOC, SYSCTL_PERIPH2_GPIOC },
311 { SYSCTL_PERIPH_GPIOD, SYSCTL_PERIPH2_GPIOD },
312 { SYSCTL_PERIPH_GPIOE, SYSCTL_PERIPH2_GPIOE },
313 { SYSCTL_PERIPH_GPIOF, SYSCTL_PERIPH2_GPIOF },
314 { SYSCTL_PERIPH_GPIOG, SYSCTL_PERIPH2_GPIOG },
315 { SYSCTL_PERIPH_GPIOH, SYSCTL_PERIPH2_GPIOH },
316 { SYSCTL_PERIPH_GPIOJ, SYSCTL_PERIPH2_GPIOJ },
317 { SYSCTL_PERIPH_HIBERNATE, SYSCTL_PERIPH2_HIBERNATE },
318 { SYSCTL_PERIPH_I2C0, SYSCTL_PERIPH2_I2C0 },
319 { SYSCTL_PERIPH_I2C1, SYSCTL_PERIPH2_I2C1 },
320 { SYSCTL_PERIPH_PWM0, SYSCTL_PERIPH2_PWM0 },
321 { SYSCTL_PERIPH_QEI0, SYSCTL_PERIPH2_QEI0 },
322 { SYSCTL_PERIPH_QEI1, SYSCTL_PERIPH2_QEI1 },
323 { SYSCTL_PERIPH_SSI0, SYSCTL_PERIPH2_SSI0 },
324 { SYSCTL_PERIPH_SSI1, SYSCTL_PERIPH2_SSI1 },
325 { SYSCTL_PERIPH_TIMER0, SYSCTL_PERIPH2_TIMER0 },
326 { SYSCTL_PERIPH_TIMER1, SYSCTL_PERIPH2_TIMER1 },
327 { SYSCTL_PERIPH_TIMER2, SYSCTL_PERIPH2_TIMER2 },
328 { SYSCTL_PERIPH_TIMER3, SYSCTL_PERIPH2_TIMER3 },
329 { SYSCTL_PERIPH_UART0, SYSCTL_PERIPH2_UART0 },
330 { SYSCTL_PERIPH_UART1, SYSCTL_PERIPH2_UART1 },
331 { SYSCTL_PERIPH_UART2, SYSCTL_PERIPH2_UART2 },
332 { SYSCTL_PERIPH_UDMA, SYSCTL_PERIPH2_UDMA },
333 { SYSCTL_PERIPH_USB0, SYSCTL_PERIPH2_USB0 },
334 { SYSCTL_PERIPH_WDOG0, SYSCTL_PERIPH2_WDOG0 },
335 { SYSCTL_PERIPH_WDOG1, SYSCTL_PERIPH2_WDOG1 },
336 };
337
338 //*****************************************************************************
339 //
340 // Maps a SYSCTL_PERIPH_foo identifier into its new-style SYSCTL_PERIPH2_foo
341 // identifier.
342 //
343 //*****************************************************************************
344 static unsigned long
SysCtlPeripheralMapToNew(unsigned long ulPeripheral)345 SysCtlPeripheralMapToNew(unsigned long ulPeripheral)
346 {
347 unsigned long ulIndex;
348
349 //
350 // Loop through the table of old-style identifiers.
351 //
352 for(ulIndex = 0; ulIndex < (sizeof(g_ppulPeripheralMap) /
353 sizeof(g_ppulPeripheralMap[0])); ulIndex++)
354 {
355 //
356 // See if this peripheral matches the old-style identifier.
357 //
358 if(g_ppulPeripheralMap[ulIndex][0] == ulPeripheral)
359 {
360 //
361 // Return the new-style identifier that corresponds to this
362 // peripheral.
363 //
364 return(g_ppulPeripheralMap[ulIndex][1]);
365 }
366 }
367
368 //
369 // No old-style identifier was found, so return the identifier unchanged
370 // (on the assumption that it is already a new-style identifier).
371 //
372 return(ulPeripheral);
373 }
374
375 //*****************************************************************************
376 //
377 //! Gets the size of the SRAM.
378 //!
379 //! This function determines the size of the SRAM on the Stellaris device.
380 //!
381 //! \return The total number of bytes of SRAM.
382 //
383 //*****************************************************************************
384 unsigned long
SysCtlSRAMSizeGet(void)385 SysCtlSRAMSizeGet(void)
386 {
387 //
388 // Compute the size of the SRAM.
389 //
390 return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_SRAMSZ_M) >> 8) + 0x100);
391 }
392
393 //*****************************************************************************
394 //
395 //! Gets the size of the flash.
396 //!
397 //! This function determines the size of the flash on the Stellaris device.
398 //!
399 //! \return The total number of bytes of flash.
400 //
401 //*****************************************************************************
402 unsigned long
SysCtlFlashSizeGet(void)403 SysCtlFlashSizeGet(void)
404 {
405 //
406 // Compute the size of the flash.
407 //
408 return(((HWREG(SYSCTL_DC0) & SYSCTL_DC0_FLASHSZ_M) << 11) + 0x800);
409 }
410
411 //*****************************************************************************
412 //
413 //! Determines if a pin is present.
414 //!
415 //! \param ulPin is the pin in question.
416 //!
417 //! This function determines if a particular pin is present in the device. The
418 //! PWM, analog comparators, ADC, and timers have a varying number of pins
419 //! across members of the Stellaris family; this function determines which pins
420 //! are present on this device.
421 //!
422 //! The \e ulPin argument must be only one of the following values:
423 //! \b SYSCTL_PIN_PWM0, \b SYSCTL_PIN_PWM1, \b SYSCTL_PIN_PWM2,
424 //! \b SYSCTL_PIN_PWM3, \b SYSCTL_PIN_PWM4, \b SYSCTL_PIN_PWM5,
425 //! \b SYSCTL_PIN_C0MINUS, \b SYSCTL_PIN_C0PLUS, \b SYSCTL_PIN_C0O,
426 //! \b SYSCTL_PIN_C1MINUS, \b SYSCTL_PIN_C1PLUS, \b SYSCTL_PIN_C1O,
427 //! \b SYSCTL_PIN_C2MINUS, \b SYSCTL_PIN_C2PLUS, \b SYSCTL_PIN_C2O,
428 //! \b SYSCTL_PIN_ADC0, \b SYSCTL_PIN_ADC1, \b SYSCTL_PIN_ADC2,
429 //! \b SYSCTL_PIN_ADC3, \b SYSCTL_PIN_ADC4, \b SYSCTL_PIN_ADC5,
430 //! \b SYSCTL_PIN_ADC6, \b SYSCTL_PIN_ADC7, \b SYSCTL_PIN_CCP0,
431 //! \b SYSCTL_PIN_CCP1, \b SYSCTL_PIN_CCP2, \b SYSCTL_PIN_CCP3,
432 //! \b SYSCTL_PIN_CCP4, \b SYSCTL_PIN_CCP5, \b SYSCTL_PIN_CCP6,
433 //! \b SYSCTL_PIN_CCP7, \b SYSCTL_PIN_32KHZ, or \b SYSCTL_PIN_MC_FAULT0.
434 //!
435 //! \return Returns \b true if the specified pin is present and \b false if it
436 //! is not.
437 //
438 //*****************************************************************************
439 tBoolean
SysCtlPinPresent(unsigned long ulPin)440 SysCtlPinPresent(unsigned long ulPin)
441 {
442 //
443 // Check the arguments.
444 //
445 ASSERT((ulPin == SYSCTL_PIN_PWM0) ||
446 (ulPin == SYSCTL_PIN_PWM1) ||
447 (ulPin == SYSCTL_PIN_PWM2) ||
448 (ulPin == SYSCTL_PIN_PWM3) ||
449 (ulPin == SYSCTL_PIN_PWM4) ||
450 (ulPin == SYSCTL_PIN_PWM5) ||
451 (ulPin == SYSCTL_PIN_C0MINUS) ||
452 (ulPin == SYSCTL_PIN_C0PLUS) ||
453 (ulPin == SYSCTL_PIN_C0O) ||
454 (ulPin == SYSCTL_PIN_C1MINUS) ||
455 (ulPin == SYSCTL_PIN_C1PLUS) ||
456 (ulPin == SYSCTL_PIN_C1O) ||
457 (ulPin == SYSCTL_PIN_C2MINUS) ||
458 (ulPin == SYSCTL_PIN_C2PLUS) ||
459 (ulPin == SYSCTL_PIN_C2O) ||
460 (ulPin == SYSCTL_PIN_MC_FAULT0) ||
461 (ulPin == SYSCTL_PIN_ADC0) ||
462 (ulPin == SYSCTL_PIN_ADC1) ||
463 (ulPin == SYSCTL_PIN_ADC2) ||
464 (ulPin == SYSCTL_PIN_ADC3) ||
465 (ulPin == SYSCTL_PIN_ADC4) ||
466 (ulPin == SYSCTL_PIN_ADC5) ||
467 (ulPin == SYSCTL_PIN_ADC6) ||
468 (ulPin == SYSCTL_PIN_ADC7) ||
469 (ulPin == SYSCTL_PIN_CCP0) ||
470 (ulPin == SYSCTL_PIN_CCP1) ||
471 (ulPin == SYSCTL_PIN_CCP2) ||
472 (ulPin == SYSCTL_PIN_CCP3) ||
473 (ulPin == SYSCTL_PIN_CCP4) ||
474 (ulPin == SYSCTL_PIN_CCP5) ||
475 (ulPin == SYSCTL_PIN_32KHZ));
476
477 //
478 // Determine if this pin is present.
479 //
480 if(HWREG(SYSCTL_DC3) & ulPin)
481 {
482 return(true);
483 }
484 else
485 {
486 return(false);
487 }
488 }
489
490 //*****************************************************************************
491 //
492 //! Determines if a peripheral is present.
493 //!
494 //! \param ulPeripheral is the peripheral in question.
495 //!
496 //! This function determines if a particular peripheral is present in the
497 //! device. Each member of the Stellaris family has a different peripheral
498 //! set; this function determines which peripherals are present on this device.
499 //!
500 //! The \e ulPeripheral parameter must be only one of the following values:
501 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
502 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
503 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EPI0,
504 //! \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0, \b SYSCTL_PERIPH_GPIOA,
505 //! \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC, \b SYSCTL_PERIPH_GPIOD,
506 //! \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF, \b SYSCTL_PERIPH_GPIOG,
507 //! \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ, \b SYSCTL_PERIPH_GPIOK,
508 //! \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM, \b SYSCTL_PERIPH_GPION,
509 //! \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ, \b SYSCTL_PERIPH_HIBERNATE,
510 //! \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1, \b SYSCTL_PERIPH_I2C2,
511 //! \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4, \b SYSCTL_PERIPH_I2C5,
512 //! \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_IEEE1588, \b SYSCTL_PERIPH_LPC0,
513 //! \b SYSCTL_PERIPH_MPU, \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PLL,
514 //! \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1, \b SYSCTL_PERIPH_QEI0,
515 //! \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0, \b SYSCTL_PERIPH_SSI1,
516 //! \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3, \b SYSCTL_PERIPH_TEMP,
517 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
518 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
519 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
520 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
521 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
522 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
523 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
524 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
525 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5,
526 //!
527 //! \return Returns \b true if the specified peripheral is present and \b false
528 //! if it is not.
529 //
530 //*****************************************************************************
531 tBoolean
SysCtlPeripheralPresent(unsigned long ulPeripheral)532 SysCtlPeripheralPresent(unsigned long ulPeripheral)
533 {
534 //
535 // Check the arguments.
536 //
537 ASSERT(SysCtlPeripheralValid(ulPeripheral));
538
539 //
540 // See if the peripheral index is 15, indicating a peripheral that is
541 // accessed via the SYSCTL_PPperiph registers.
542 //
543 if((ulPeripheral & 0xf0000000) == 0xf0000000)
544 {
545 //
546 // See if this peripheral is present.
547 //
548 return(HWREGBITW(SYSCTL_PPBASE + ((ulPeripheral & 0xff00) >> 8),
549 ulPeripheral & 0xff));
550 }
551 else if(ulPeripheral == SYSCTL_PERIPH_USB0)
552 {
553 //
554 // USB is a special case because the DC bit is missing for USB0.
555 //
556 if(HWREG(SYSCTL_DC6) & SYSCTL_DC6_USB0_M)
557 {
558 return(true);
559 }
560 else
561 {
562 return(false);
563 }
564 }
565 else if(HWREG(g_pulDCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &
566 SYSCTL_PERIPH_MASK(ulPeripheral))
567 {
568 return(true);
569 }
570 else
571 {
572 return(false);
573 }
574 }
575
576 //*****************************************************************************
577 //
578 //! Determines if a peripheral is ready.
579 //!
580 //! \param ulPeripheral is the peripheral in question.
581 //!
582 //! This function determines if a particular peripheral is ready to be
583 //! accessed. The peripheral may be in a non-ready state if it is not enabled,
584 //! is being held in reset, or is in the process of becoming ready after being
585 //! enabled or taken out of reset.
586 //!
587 //! The \e ulPeripheral parameter must be only one of the following values:
588 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
589 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
590 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
591 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
592 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
593 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
594 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
595 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
596 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
597 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
598 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
599 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
600 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
601 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
602 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
603 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
604 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
605 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
606 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
607 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
608 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
609 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
610 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
611 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
612 //!
613 //! \note The ability to check for a peripheral being ready varies based on the
614 //! Stellaris part in use. Please consult the data sheet for the part you are
615 //! using to determine if this feature is available.
616 //!
617 //! \return Returns \b true if the specified peripheral is ready and \b false
618 //! if it is not.
619 //
620 //*****************************************************************************
621 tBoolean
SysCtlPeripheralReady(unsigned long ulPeripheral)622 SysCtlPeripheralReady(unsigned long ulPeripheral)
623 {
624 //
625 // Check the arguments.
626 //
627 ASSERT(SysCtlPeripheralValid(ulPeripheral));
628
629 //
630 // Map the peripheral identifier to the new style identifiers. If it is
631 // already a new style identifier, this is a NOP.
632 //
633 ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
634
635 //
636 // See if this peripheral is ready.
637 //
638 return(HWREGBITW(SYSCTL_PRBASE + ((ulPeripheral & 0xff00) >> 8),
639 ulPeripheral & 0xff));
640 }
641
642 //*****************************************************************************
643 //
644 //! Powers on a peripheral.
645 //!
646 //! \param ulPeripheral is the peripheral to be powered on.
647 //!
648 //! This function turns on the power to a peripheral. The peripheral continues
649 //! to receive power even when its clock is not enabled.
650 //!
651 //! The \e ulPeripheral parameter must be only one of the following values:
652 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
653 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
654 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
655 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
656 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
657 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
658 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
659 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
660 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
661 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
662 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
663 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
664 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
665 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
666 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
667 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
668 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
669 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
670 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
671 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
672 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
673 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
674 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
675 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
676 //!
677 //! \note The ability to power off a peripheral varies based on the Stellaris
678 //! part in use. Please consult the data sheet for the part you are using to
679 //! determine if this feature is available.
680 //!
681 //! \return None.
682 //
683 //*****************************************************************************
684 void
SysCtlPeripheralPowerOn(unsigned long ulPeripheral)685 SysCtlPeripheralPowerOn(unsigned long ulPeripheral)
686 {
687 //
688 // Check the arguments.
689 //
690 ASSERT(SysCtlPeripheralValid(ulPeripheral));
691
692 //
693 // Map the peripheral identifier to the new style identifiers. If it is
694 // already a new style identifier, this is a NOP.
695 //
696 ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
697
698 //
699 // Power on this peripheral.
700 //
701 HWREGBITW(SYSCTL_PCBASE + ((ulPeripheral & 0xff00) >> 8),
702 ulPeripheral & 0xff) = 1;
703 }
704
705 //*****************************************************************************
706 //
707 //! Powers off a peripheral.
708 //!
709 //! \param ulPeripheral is the peripheral to be powered off.
710 //!
711 //! This function allows the power to a peripheral to be turned off. The
712 //! peripheral continues to receive power when its clock is enabled, but
713 //! the power is removed when its clock is disabled.
714 //!
715 //! The \e ulPeripheral parameter must be only one of the following values:
716 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
717 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
718 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
719 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
720 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
721 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
722 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
723 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
724 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
725 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
726 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
727 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
728 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
729 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
730 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
731 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
732 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
733 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
734 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
735 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
736 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
737 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
738 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
739 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
740 //!
741 //! \note The ability to power off a peripheral varies based on the Stellaris
742 //! part in use. Please consult the data sheet for the part you are using to
743 //! determine if this feature is available.
744 //!
745 //! \return None.
746 //
747 //*****************************************************************************
748 void
SysCtlPeripheralPowerOff(unsigned long ulPeripheral)749 SysCtlPeripheralPowerOff(unsigned long ulPeripheral)
750 {
751 //
752 // Check the arguments.
753 //
754 ASSERT(SysCtlPeripheralValid(ulPeripheral));
755
756 //
757 // Map the peripheral identifier to the new style identifiers. If it is
758 // already a new style identifier, this is a NOP.
759 //
760 ulPeripheral = SysCtlPeripheralMapToNew(ulPeripheral);
761
762 //
763 // Power off this peripheral.
764 //
765 HWREGBITW(SYSCTL_PCBASE + ((ulPeripheral & 0xff00) >> 8),
766 ulPeripheral & 0xff) = 0;
767 }
768
769 //*****************************************************************************
770 //
771 //! Performs a software reset of a peripheral.
772 //!
773 //! \param ulPeripheral is the peripheral to reset.
774 //!
775 //! This function performs a software reset of the specified peripheral. An
776 //! individual peripheral reset signal is asserted for a brief period and then
777 //! de-asserted, returning the internal state of the peripheral to its reset
778 //! condition.
779 //!
780 //! The \e ulPeripheral parameter must be only one of the following values:
781 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
782 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
783 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
784 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
785 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
786 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
787 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
788 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
789 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
790 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
791 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
792 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
793 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
794 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
795 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
796 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
797 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
798 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
799 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
800 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
801 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
802 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
803 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
804 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
805 //!
806 //! \return None.
807 //
808 //*****************************************************************************
809 void
SysCtlPeripheralReset(unsigned long ulPeripheral)810 SysCtlPeripheralReset(unsigned long ulPeripheral)
811 {
812 volatile unsigned long ulDelay;
813
814 //
815 // Check the arguments.
816 //
817 ASSERT(SysCtlPeripheralValid(ulPeripheral));
818
819 //
820 // See if the peripheral index is 15, indicating a peripheral that is
821 // accessed via the SYSCTL_SRperiph registers.
822 //
823 if((ulPeripheral & 0xf0000000) == 0xf0000000)
824 {
825 //
826 // Put the peripheral into the reset state.
827 //
828 HWREGBITW(SYSCTL_SRBASE + ((ulPeripheral & 0xff00) >> 8),
829 ulPeripheral & 0xff) = 1;
830
831 //
832 // Delay for a little bit.
833 //
834 for(ulDelay = 0; ulDelay < 16; ulDelay++)
835 {
836 }
837
838 //
839 // Take the peripheral out of the reset state.
840 //
841 HWREGBITW(SYSCTL_SRBASE + ((ulPeripheral & 0xff00) >> 8),
842 ulPeripheral & 0xff) = 0;
843 }
844 else
845 {
846 //
847 // Put the peripheral into the reset state.
848 //
849 HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
850 SYSCTL_PERIPH_MASK(ulPeripheral);
851
852 //
853 // Delay for a little bit.
854 //
855 for(ulDelay = 0; ulDelay < 16; ulDelay++)
856 {
857 }
858
859 //
860 // Take the peripheral out of the reset state.
861 //
862 HWREG(g_pulSRCRRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
863 ~SYSCTL_PERIPH_MASK(ulPeripheral);
864 }
865 }
866
867 //*****************************************************************************
868 //
869 //! Enables a peripheral.
870 //!
871 //! \param ulPeripheral is the peripheral to enable.
872 //!
873 //! This function enables peripherals. At power-up, all peripherals
874 //! are disabled; they must be enabled in order to operate or respond to
875 //! register reads/writes.
876 //!
877 //! The \e ulPeripheral parameter must be only one of the following values:
878 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
879 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
880 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
881 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
882 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
883 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
884 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
885 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
886 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
887 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
888 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
889 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
890 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
891 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
892 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
893 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
894 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
895 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
896 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
897 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
898 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
899 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
900 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
901 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
902 //!
903 //! \note It takes five clock cycles after the write to enable a peripheral
904 //! before the the peripheral is actually enabled. During this time, attempts
905 //! to access the peripheral result in a bus fault. Care should be taken
906 //! to ensure that the peripheral is not accessed during this brief time
907 //! period.
908 //!
909 //! \return None.
910 //
911 //*****************************************************************************
912 void
SysCtlPeripheralEnable(unsigned long ulPeripheral)913 SysCtlPeripheralEnable(unsigned long ulPeripheral)
914 {
915 //
916 // Check the arguments.
917 //
918 ASSERT(SysCtlPeripheralValid(ulPeripheral));
919
920 //
921 // See if the peripheral index is 15, indicating a peripheral that is
922 // accessed via the SYSCTL_RCGCperiph registers.
923 //
924 if((ulPeripheral & 0xf0000000) == 0xf0000000)
925 {
926 //
927 // Enable this peripheral.
928 //
929 HWREGBITW(SYSCTL_RCGCBASE + ((ulPeripheral & 0xff00) >> 8),
930 ulPeripheral & 0xff) = 1;
931 }
932 else
933 {
934 //
935 // Enable this peripheral.
936 //
937 HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
938 SYSCTL_PERIPH_MASK(ulPeripheral);
939 }
940 }
941
942 //*****************************************************************************
943 //
944 //! Disables a peripheral.
945 //!
946 //! \param ulPeripheral is the peripheral to disable.
947 //!
948 //! This function disables peripherals are disabled with this function. Once
949 //! disabled, they do not operate or respond to register reads/writes.
950 //!
951 //! The \e ulPeripheral parameter must be only one of the following values:
952 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
953 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
954 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
955 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
956 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
957 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
958 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
959 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
960 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
961 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
962 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
963 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
964 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
965 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
966 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
967 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
968 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
969 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
970 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
971 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
972 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
973 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
974 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
975 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
976 //!
977 //! \return None.
978 //
979 //*****************************************************************************
980 void
SysCtlPeripheralDisable(unsigned long ulPeripheral)981 SysCtlPeripheralDisable(unsigned long ulPeripheral)
982 {
983 //
984 // Check the arguments.
985 //
986 ASSERT(SysCtlPeripheralValid(ulPeripheral));
987
988 //
989 // See if the peripheral index is 15, indicating a peripheral that is
990 // accessed via the SYSCTL_RCGCperiph registers.
991 //
992 if((ulPeripheral & 0xf0000000) == 0xf0000000)
993 {
994 //
995 // Disable this peripheral.
996 //
997 HWREGBITW(SYSCTL_RCGCBASE + ((ulPeripheral & 0xff00) >> 8),
998 ulPeripheral & 0xff) = 0;
999 }
1000 else
1001 {
1002 //
1003 // Disable this peripheral.
1004 //
1005 HWREG(g_pulRCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
1006 ~SYSCTL_PERIPH_MASK(ulPeripheral);
1007 }
1008 }
1009
1010 //*****************************************************************************
1011 //
1012 //! Enables a peripheral in sleep mode.
1013 //!
1014 //! \param ulPeripheral is the peripheral to enable in sleep mode.
1015 //!
1016 //! This function allows a peripheral to continue operating when the processor
1017 //! goes into sleep mode. Because the clocking configuration of the device
1018 //! does not change, any peripheral can safely continue operating while the
1019 //! processor is in sleep mode and can therefore wake the processor from sleep
1020 //! mode.
1021 //!
1022 //! Sleep mode clocking of peripherals must be enabled via
1023 //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
1024 //! configuration is maintained but has no effect when sleep mode is entered.
1025 //!
1026 //! The \e ulPeripheral parameter must be only one of the following values:
1027 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
1028 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
1029 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
1030 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
1031 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
1032 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
1033 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
1034 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
1035 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
1036 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
1037 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
1038 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
1039 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
1040 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
1041 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
1042 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
1043 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
1044 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
1045 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
1046 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
1047 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
1048 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
1049 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
1050 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
1051 //!
1052 //! \return None.
1053 //
1054 //*****************************************************************************
1055 void
SysCtlPeripheralSleepEnable(unsigned long ulPeripheral)1056 SysCtlPeripheralSleepEnable(unsigned long ulPeripheral)
1057 {
1058 //
1059 // Check the arguments.
1060 //
1061 ASSERT(SysCtlPeripheralValid(ulPeripheral));
1062
1063 //
1064 // See if the peripheral index is 15, indicating a peripheral that is
1065 // accessed via the SYSCTL_SCGCperiph registers.
1066 //
1067 if((ulPeripheral & 0xf0000000) == 0xf0000000)
1068 {
1069 //
1070 // Enable this peripheral in sleep mode.
1071 //
1072 HWREGBITW(SYSCTL_SCGCBASE + ((ulPeripheral & 0xff00) >> 8),
1073 ulPeripheral & 0xff) = 1;
1074 }
1075 else
1076 {
1077 //
1078 // Enable this peripheral in sleep mode.
1079 //
1080 HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
1081 SYSCTL_PERIPH_MASK(ulPeripheral);
1082 }
1083 }
1084
1085 //*****************************************************************************
1086 //
1087 //! Disables a peripheral in sleep mode.
1088 //!
1089 //! \param ulPeripheral is the peripheral to disable in sleep mode.
1090 //!
1091 //! This function causes a peripheral to stop operating when the processor goes
1092 //! into sleep mode. Disabling peripherals while in sleep mode helps to lower
1093 //! the current draw of the device. If enabled (via SysCtlPeripheralEnable()),
1094 //! the peripheral automatically resumes operation when the processor
1095 //! leaves sleep mode, maintaining its entire state from before sleep mode was
1096 //! entered.
1097 //!
1098 //! Sleep mode clocking of peripherals must be enabled via
1099 //! SysCtlPeripheralClockGating(); if disabled, the peripheral sleep mode
1100 //! configuration is maintained but has no effect when sleep mode is entered.
1101 //!
1102 //! The \e ulPeripheral parameter must be only one of the following values:
1103 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
1104 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
1105 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
1106 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
1107 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
1108 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
1109 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
1110 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
1111 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
1112 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
1113 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
1114 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
1115 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
1116 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
1117 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
1118 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
1119 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
1120 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
1121 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
1122 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
1123 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
1124 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
1125 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
1126 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
1127 //!
1128 //! \return None.
1129 //
1130 //*****************************************************************************
1131 void
SysCtlPeripheralSleepDisable(unsigned long ulPeripheral)1132 SysCtlPeripheralSleepDisable(unsigned long ulPeripheral)
1133 {
1134 //
1135 // Check the arguments.
1136 //
1137 ASSERT(SysCtlPeripheralValid(ulPeripheral));
1138
1139 //
1140 // See if the peripheral index is 15, indicating a peripheral that is
1141 // accessed via the SYSCTL_SCGCperiph registers.
1142 //
1143 if((ulPeripheral & 0xf0000000) == 0xf0000000)
1144 {
1145 //
1146 // Disable this peripheral in sleep mode.
1147 //
1148 HWREGBITW(SYSCTL_SCGCBASE + ((ulPeripheral & 0xff00) >> 8),
1149 ulPeripheral & 0xff) = 0;
1150 }
1151 else
1152 {
1153 //
1154 // Disable this peripheral in sleep mode.
1155 //
1156 HWREG(g_pulSCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
1157 ~SYSCTL_PERIPH_MASK(ulPeripheral);
1158 }
1159 }
1160
1161 //*****************************************************************************
1162 //
1163 //! Enables a peripheral in deep-sleep mode.
1164 //!
1165 //! \param ulPeripheral is the peripheral to enable in deep-sleep mode.
1166 //!
1167 //! This function allows a peripheral to continue operating when the processor
1168 //! goes into deep-sleep mode. Because the clocking configuration of the
1169 //! device may change, not all peripherals can safely continue operating while
1170 //! the processor is in sleep mode. Those that must run at a particular
1171 //! frequency (such as a UART) do not work as expected if the clock changes.
1172 //! It is the responsibility of the caller to make sensible choices.
1173 //!
1174 //! Deep-sleep mode clocking of peripherals must be enabled via
1175 //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
1176 //! configuration is maintained but has no effect when deep-sleep mode is
1177 //! entered.
1178 //!
1179 //! The \e ulPeripheral parameter must be only one of the following values:
1180 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
1181 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
1182 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
1183 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
1184 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
1185 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
1186 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
1187 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
1188 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
1189 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
1190 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
1191 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
1192 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
1193 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
1194 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
1195 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
1196 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
1197 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
1198 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
1199 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
1200 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
1201 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
1202 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
1203 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
1204 //!
1205 //! \return None.
1206 //
1207 //*****************************************************************************
1208 void
SysCtlPeripheralDeepSleepEnable(unsigned long ulPeripheral)1209 SysCtlPeripheralDeepSleepEnable(unsigned long ulPeripheral)
1210 {
1211 //
1212 // Check the arguments.
1213 //
1214 ASSERT(SysCtlPeripheralValid(ulPeripheral));
1215
1216 //
1217 // See if the peripheral index is 15, indicating a peripheral that is
1218 // accessed via the SYSCTL_DCGCperiph registers.
1219 //
1220 if((ulPeripheral & 0xf0000000) == 0xf0000000)
1221 {
1222 //
1223 // Enable this peripheral in deep-sleep mode.
1224 //
1225 HWREGBITW(SYSCTL_DCGCBASE + ((ulPeripheral & 0xff00) >> 8),
1226 ulPeripheral & 0xff) = 1;
1227 }
1228 else
1229 {
1230 //
1231 // Enable this peripheral in deep-sleep mode.
1232 //
1233 HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) |=
1234 SYSCTL_PERIPH_MASK(ulPeripheral);
1235 }
1236 }
1237
1238 //*****************************************************************************
1239 //
1240 //! Disables a peripheral in deep-sleep mode.
1241 //!
1242 //! \param ulPeripheral is the peripheral to disable in deep-sleep mode.
1243 //!
1244 //! This function causes a peripheral to stop operating when the processor goes
1245 //! into deep-sleep mode. Disabling peripherals while in deep-sleep mode helps
1246 //! to lower the current draw of the device, and can keep peripherals that
1247 //! require a particular clock frequency from operating when the clock changes
1248 //! as a result of entering deep-sleep mode. If enabled (via
1249 //! SysCtlPeripheralEnable()), the peripheral automatically resumes
1250 //! operation when the processor leaves deep-sleep mode, maintaining its entire
1251 //! state from before deep-sleep mode was entered.
1252 //!
1253 //! Deep-sleep mode clocking of peripherals must be enabled via
1254 //! SysCtlPeripheralClockGating(); if disabled, the peripheral deep-sleep mode
1255 //! configuration is maintained but has no effect when deep-sleep mode is
1256 //! entered.
1257 //!
1258 //! The \e ulPeripheral parameter must be only one of the following values:
1259 //! \b SYSCTL_PERIPH_ADC0, \b SYSCTL_PERIPH_ADC1, \b SYSCTL_PERIPH_CAN0,
1260 //! \b SYSCTL_PERIPH_CAN1, \b SYSCTL_PERIPH_CAN2, \b SYSCTL_PERIPH_COMP0,
1261 //! \b SYSCTL_PERIPH_COMP1, \b SYSCTL_PERIPH_COMP2, \b SYSCTL_PERIPH_EEPROM0,
1262 //! \b SYSCTL_PERIPH_EPI0, \b SYSCTL_PERIPH_ETH, \b SYSCTL_PERIPH_FAN0,
1263 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
1264 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
1265 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, \b SYSCTL_PERIPH_GPIOJ,
1266 //! \b SYSCTL_PERIPH_GPIOK, \b SYSCTL_PERIPH_GPIOL, \b SYSCTL_PERIPH_GPIOM,
1267 //! \b SYSCTL_PERIPH_GPION, \b SYSCTL_PERIPH_GPIOP, \b SYSCTL_PERIPH_GPIOQ,
1268 //! \b SYSCTL_PERIPH_HIBERNATE, \b SYSCTL_PERIPH_I2C0, \b SYSCTL_PERIPH_I2C1,
1269 //! \b SYSCTL_PERIPH_I2C2, \b SYSCTL_PERIPH_I2C3, \b SYSCTL_PERIPH_I2C4,
1270 //! \b SYSCTL_PERIPH_I2C5, \b SYSCTL_PERIPH_I2S0, \b SYSCTL_PERIPH_LPC0,
1271 //! \b SYSCTL_PERIPH_PECI0, \b SYSCTL_PERIPH_PWM0, \b SYSCTL_PERIPH_PWM1,
1272 //! \b SYSCTL_PERIPH_QEI0, \b SYSCTL_PERIPH_QEI1, \b SYSCTL_PERIPH_SSI0,
1273 //! \b SYSCTL_PERIPH_SSI1, \b SYSCTL_PERIPH_SSI2, \b SYSCTL_PERIPH_SSI3,
1274 //! \b SYSCTL_PERIPH_TIMER0, \b SYSCTL_PERIPH_TIMER1, \b SYSCTL_PERIPH_TIMER2,
1275 //! \b SYSCTL_PERIPH_TIMER3, \b SYSCTL_PERIPH_TIMER4, \b SYSCTL_PERIPH_TIMER5,
1276 //! \b SYSCTL_PERIPH_UART0, \b SYSCTL_PERIPH_UART1, \b SYSCTL_PERIPH_UART2,
1277 //! \b SYSCTL_PERIPH_UART3, \b SYSCTL_PERIPH_UART4, \b SYSCTL_PERIPH_UART5,
1278 //! \b SYSCTL_PERIPH_UART6, \b SYSCTL_PERIPH_UART7, \b SYSCTL_PERIPH_UDMA,
1279 //! \b SYSCTL_PERIPH_USB0, \b SYSCTL_PERIPH_WDOG0, \b SYSCTL_PERIPH_WDOG1,
1280 //! \b SYSCTL_PERIPH_WTIMER0, \b SYSCTL_PERIPH_WTIMER1,
1281 //! \b SYSCTL_PERIPH_WTIMER2, \b SYSCTL_PERIPH_WTIMER3,
1282 //! \b SYSCTL_PERIPH_WTIMER4, or \b SYSCTL_PERIPH_WTIMER5.
1283 //!
1284 //! \return None.
1285 //
1286 //*****************************************************************************
1287 void
SysCtlPeripheralDeepSleepDisable(unsigned long ulPeripheral)1288 SysCtlPeripheralDeepSleepDisable(unsigned long ulPeripheral)
1289 {
1290 //
1291 // Check the arguments.
1292 //
1293 ASSERT(SysCtlPeripheralValid(ulPeripheral));
1294
1295 //
1296 // See if the peripheral index is 15, indicating a peripheral that is
1297 // accessed via the SYSCTL_DCGCperiph registers.
1298 //
1299 if((ulPeripheral & 0xf0000000) == 0xf0000000)
1300 {
1301 //
1302 // Disable this peripheral in deep-sleep mode.
1303 //
1304 HWREGBITW(SYSCTL_DCGCBASE + ((ulPeripheral & 0xff00) >> 8),
1305 ulPeripheral & 0xff) = 0;
1306 }
1307 else
1308 {
1309 //
1310 // Disable this peripheral in deep-sleep mode.
1311 //
1312 HWREG(g_pulDCGCRegs[SYSCTL_PERIPH_INDEX(ulPeripheral)]) &=
1313 ~SYSCTL_PERIPH_MASK(ulPeripheral);
1314 }
1315 }
1316
1317 //*****************************************************************************
1318 //
1319 //! Controls peripheral clock gating in sleep and deep-sleep mode.
1320 //!
1321 //! \param bEnable is a boolean that is \b true if the sleep and deep-sleep
1322 //! peripheral configuration should be used and \b false if not.
1323 //!
1324 //! This function controls how peripherals are clocked when the processor goes
1325 //! into sleep or deep-sleep mode. By default, the peripherals are clocked the
1326 //! same as in run mode; if peripheral clock gating is enabled, they are
1327 //! clocked according to the configuration set by
1328 //! SysCtlPeripheralSleepEnable(), SysCtlPeripheralSleepDisable(),
1329 //! SysCtlPeripheralDeepSleepEnable(), and SysCtlPeripheralDeepSleepDisable().
1330 //!
1331 //! \return None.
1332 //
1333 //*****************************************************************************
1334 void
SysCtlPeripheralClockGating(tBoolean bEnable)1335 SysCtlPeripheralClockGating(tBoolean bEnable)
1336 {
1337 //
1338 // Enable peripheral clock gating as requested.
1339 //
1340 if(bEnable)
1341 {
1342 HWREG(SYSCTL_RCC) |= SYSCTL_RCC_ACG;
1343 }
1344 else
1345 {
1346 HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_ACG);
1347 }
1348 }
1349
1350 //*****************************************************************************
1351 //
1352 //! Registers an interrupt handler for the system control interrupt.
1353 //!
1354 //! \param pfnHandler is a pointer to the function to be called when the system
1355 //! control interrupt occurs.
1356 //!
1357 //! This function registers the handler to be called when a system control
1358 //! interrupt occurs. This function enables the global interrupt in the
1359 //! interrupt controller; specific system control interrupts must be enabled
1360 //! via SysCtlIntEnable(). It is the interrupt handler's responsibility to
1361 //! clear the interrupt source via SysCtlIntClear().
1362 //!
1363 //! System control can generate interrupts when the PLL achieves lock, if the
1364 //! internal LDO current limit is exceeded, if the internal oscillator fails,
1365 //! if the main oscillator fails, if the internal LDO output voltage droops too
1366 //! much, if the external voltage droops too much, or if the PLL fails.
1367 //!
1368 //! \sa IntRegister() for important information about registering interrupt
1369 //! handlers.
1370 //!
1371 //! \note The events that cause system control interrupts vary based on the
1372 //! Stellaris part in use. Please consult the data sheet for the part you are
1373 //! using to determine which interrupt sources are available.
1374 //!
1375 //! \return None.
1376 //
1377 //*****************************************************************************
1378 void
SysCtlIntRegister(void (* pfnHandler)(void))1379 SysCtlIntRegister(void (*pfnHandler)(void))
1380 {
1381 //
1382 // Register the interrupt handler, returning an error if an error occurs.
1383 //
1384 IntRegister(INT_SYSCTL, pfnHandler);
1385
1386 //
1387 // Enable the system control interrupt.
1388 //
1389 IntEnable(INT_SYSCTL);
1390 }
1391
1392 //*****************************************************************************
1393 //
1394 //! Unregisters the interrupt handler for the system control interrupt.
1395 //!
1396 //! This function unregisters the handler to be called when a system control
1397 //! interrupt occurs. This function also masks off the interrupt in the
1398 //! interrupt controller so that the interrupt handler no longer is called.
1399 //!
1400 //! \sa IntRegister() for important information about registering interrupt
1401 //! handlers.
1402 //!
1403 //! \return None.
1404 //
1405 //*****************************************************************************
1406 void
SysCtlIntUnregister(void)1407 SysCtlIntUnregister(void)
1408 {
1409 //
1410 // Disable the interrupt.
1411 //
1412 IntDisable(INT_SYSCTL);
1413
1414 //
1415 // Unregister the interrupt handler.
1416 //
1417 IntUnregister(INT_SYSCTL);
1418 }
1419
1420 //*****************************************************************************
1421 //
1422 //! Enables individual system control interrupt sources.
1423 //!
1424 //! \param ulInts is a bit mask of the interrupt sources to be enabled. Must
1425 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
1426 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
1427 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
1428 //!
1429 //! This function enables the indicated system control interrupt sources. Only
1430 //! the sources that are enabled can be reflected to the processor interrupt;
1431 //! disabled sources have no effect on the processor.
1432 //!
1433 //! \note The interrupt sources vary based on the Stellaris part in use.
1434 //! Please consult the data sheet for the part you are using to determine
1435 //! which interrupt sources are available.
1436 //!
1437 //! \return None.
1438 //
1439 //*****************************************************************************
1440 void
SysCtlIntEnable(unsigned long ulInts)1441 SysCtlIntEnable(unsigned long ulInts)
1442 {
1443 //
1444 // Enable the specified interrupts.
1445 //
1446 HWREG(SYSCTL_IMC) |= ulInts;
1447 }
1448
1449 //*****************************************************************************
1450 //
1451 //! Disables individual system control interrupt sources.
1452 //!
1453 //! \param ulInts is a bit mask of the interrupt sources to be disabled. Must
1454 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
1455 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
1456 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
1457 //!
1458 //! This function disables the indicated system control interrupt sources.
1459 //! Only the sources that are enabled can be reflected to the processor
1460 //! interrupt; disabled sources have no effect on the processor.
1461 //!
1462 //! \note The interrupt sources vary based on the Stellaris part in use.
1463 //! Please consult the data sheet for the part you are using to determine
1464 //! which interrupt sources are available.
1465 //!
1466 //! \return None.
1467 //
1468 //*****************************************************************************
1469 void
SysCtlIntDisable(unsigned long ulInts)1470 SysCtlIntDisable(unsigned long ulInts)
1471 {
1472 //
1473 // Disable the specified interrupts.
1474 //
1475 HWREG(SYSCTL_IMC) &= ~(ulInts);
1476 }
1477
1478 //*****************************************************************************
1479 //
1480 //! Clears system control interrupt sources.
1481 //!
1482 //! \param ulInts is a bit mask of the interrupt sources to be cleared. Must
1483 //! be a logical OR of \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT,
1484 //! \b SYSCTL_INT_IOSC_FAIL, \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR,
1485 //! \b SYSCTL_INT_BOR, and/or \b SYSCTL_INT_PLL_FAIL.
1486 //!
1487 //! The specified system control interrupt sources are cleared, so that they no
1488 //! longer assert. This function must be called in the interrupt handler to
1489 //! keep it from being called again immediately upon exit.
1490 //!
1491 //! \note Because there is a write buffer in the Cortex-M processor, it may
1492 //! take several clock cycles before the interrupt source is actually cleared.
1493 //! Therefore, it is recommended that the interrupt source be cleared early in
1494 //! the interrupt handler (as opposed to the very last action) to avoid
1495 //! returning from the interrupt handler before the interrupt source is
1496 //! actually cleared. Failure to do so may result in the interrupt handler
1497 //! being immediately reentered (because the interrupt controller still sees
1498 //! the interrupt source asserted).
1499 //!
1500 //! \note The interrupt sources vary based on the Stellaris part in use.
1501 //! Please consult the data sheet for the part you are using to determine
1502 //! which interrupt sources are available.
1503 //!
1504 //! \return None.
1505 //
1506 //*****************************************************************************
1507 void
SysCtlIntClear(unsigned long ulInts)1508 SysCtlIntClear(unsigned long ulInts)
1509 {
1510 //
1511 // Clear the requested interrupt sources.
1512 //
1513 HWREG(SYSCTL_MISC) = ulInts;
1514 }
1515
1516 //*****************************************************************************
1517 //
1518 //! Gets the current interrupt status.
1519 //!
1520 //! \param bMasked is false if the raw interrupt status is required and true if
1521 //! the masked interrupt status is required.
1522 //!
1523 //! This function returns the interrupt status for the system controller.
1524 //! Either the raw interrupt status or the status of interrupts that are
1525 //! allowed to reflect to the processor can be returned.
1526 //!
1527 //! \return The current interrupt status, enumerated as a bit field of
1528 //! \b SYSCTL_INT_PLL_LOCK, \b SYSCTL_INT_CUR_LIMIT, \b SYSCTL_INT_IOSC_FAIL,
1529 //! \b SYSCTL_INT_MOSC_FAIL, \b SYSCTL_INT_POR, \b SYSCTL_INT_BOR, and
1530 //! \b SYSCTL_INT_PLL_FAIL.
1531 //!
1532 //! \note The interrupt sources vary based on the Stellaris part in use.
1533 //! Please consult the data sheet for the part you are using to determine
1534 //! which interrupt sources are available.
1535 //
1536 //*****************************************************************************
1537 unsigned long
SysCtlIntStatus(tBoolean bMasked)1538 SysCtlIntStatus(tBoolean bMasked)
1539 {
1540 //
1541 // Return either the interrupt status or the raw interrupt status as
1542 // requested.
1543 //
1544 if(bMasked)
1545 {
1546 return(HWREG(SYSCTL_MISC));
1547 }
1548 else
1549 {
1550 return(HWREG(SYSCTL_RIS));
1551 }
1552 }
1553
1554 //*****************************************************************************
1555 //
1556 //! Sets the output voltage of the LDO.
1557 //!
1558 //! \param ulVoltage is the required output voltage from the LDO.
1559 //!
1560 //! This function sets the output voltage of the LDO. The \e ulVoltage
1561 //! parameter specifies the LDO voltage and must be one of the following
1562 //! values:
1563 //! \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
1564 //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
1565 //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
1566 //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
1567 //!
1568 //! \note The default LDO voltage and the adjustment range varies with the
1569 //! Stellaris part in use. Please consult the data sheet for the part you are
1570 //! using to determine the default voltage and range available.
1571 //!
1572 //! \return None.
1573 //
1574 //*****************************************************************************
1575 void
SysCtlLDOSet(unsigned long ulVoltage)1576 SysCtlLDOSet(unsigned long ulVoltage)
1577 {
1578 //
1579 // Check the arguments.
1580 //
1581 ASSERT((ulVoltage == SYSCTL_LDO_2_25V) ||
1582 (ulVoltage == SYSCTL_LDO_2_30V) ||
1583 (ulVoltage == SYSCTL_LDO_2_35V) ||
1584 (ulVoltage == SYSCTL_LDO_2_40V) ||
1585 (ulVoltage == SYSCTL_LDO_2_45V) ||
1586 (ulVoltage == SYSCTL_LDO_2_50V) ||
1587 (ulVoltage == SYSCTL_LDO_2_55V) ||
1588 (ulVoltage == SYSCTL_LDO_2_60V) ||
1589 (ulVoltage == SYSCTL_LDO_2_65V) ||
1590 (ulVoltage == SYSCTL_LDO_2_70V) ||
1591 (ulVoltage == SYSCTL_LDO_2_75V));
1592
1593 //
1594 // Set the LDO voltage to the requested value.
1595 //
1596 HWREG(SYSCTL_LDOPCTL) = ulVoltage;
1597 }
1598
1599 //*****************************************************************************
1600 //
1601 //! Gets the output voltage of the LDO.
1602 //!
1603 //! This function determines the output voltage of the LDO, as specified by the
1604 //! control register.
1605 //!
1606 //! \return Returns the current voltage of the LDO and is one of:
1607 //! \b SYSCTL_LDO_2_25V, \b SYSCTL_LDO_2_30V, \b SYSCTL_LDO_2_35V,
1608 //! \b SYSCTL_LDO_2_40V, \b SYSCTL_LDO_2_45V, \b SYSCTL_LDO_2_50V,
1609 //! \b SYSCTL_LDO_2_55V, \b SYSCTL_LDO_2_60V, \b SYSCTL_LDO_2_65V,
1610 //! \b SYSCTL_LDO_2_70V, or \b SYSCTL_LDO_2_75V.
1611 //
1612 //*****************************************************************************
1613 unsigned long
SysCtlLDOGet(void)1614 SysCtlLDOGet(void)
1615 {
1616 //
1617 // Return the LDO voltage setting.
1618 //
1619 return(HWREG(SYSCTL_LDOPCTL));
1620 }
1621
1622 //*****************************************************************************
1623 //
1624 //! Configures the LDO failure control.
1625 //!
1626 //! \param ulConfig is the required LDO failure control setting; can be either
1627 //! \b SYSCTL_LDOCFG_ARST or \b SYSCTL_LDOCFG_NORST.
1628 //!
1629 //! This function allows the LDO to be configured to cause a processor reset
1630 //! when the output voltage becomes unregulated.
1631 //!
1632 //! The LDO failure control is only available on Sandstorm-class devices.
1633 //!
1634 //! \return None.
1635 //
1636 //*****************************************************************************
1637 void
SysCtlLDOConfigSet(unsigned long ulConfig)1638 SysCtlLDOConfigSet(unsigned long ulConfig)
1639 {
1640 //
1641 // Check the arguments.
1642 //
1643 ASSERT((ulConfig == SYSCTL_LDOCFG_ARST) ||
1644 (ulConfig == SYSCTL_LDOCFG_NORST));
1645
1646 //
1647 // Set the reset control as requested.
1648 //
1649 HWREG(SYSCTL_LDOARST) = ulConfig;
1650 }
1651
1652 //*****************************************************************************
1653 //
1654 //! Resets the device.
1655 //!
1656 //! This function performs a software reset of the entire device. The
1657 //! processor and all peripherals are reset and all device registers are
1658 //! returned to their default values (with the exception of the reset cause
1659 //! register, which maintains its current value but has the software reset
1660 //! bit set as well).
1661 //!
1662 //! \return This function does not return.
1663 //
1664 //*****************************************************************************
1665 void
SysCtlReset(void)1666 SysCtlReset(void)
1667 {
1668 //
1669 // Perform a software reset request. This request causes the device to
1670 // reset, no further code is executed.
1671 //
1672 HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ;
1673
1674 //
1675 // The device should have reset, so this should never be reached. Just in
1676 // case, loop forever.
1677 //
1678 while(1)
1679 {
1680 }
1681 }
1682
1683 //*****************************************************************************
1684 //
1685 //! Puts the processor into sleep mode.
1686 //!
1687 //! This function places the processor into sleep mode; it does not return
1688 //! until the processor returns to run mode. The peripherals that are enabled
1689 //! via SysCtlPeripheralSleepEnable() continue to operate and can wake up the
1690 //! processor (if automatic clock gating is enabled with
1691 //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
1692 //! operate).
1693 //!
1694 //! \return None.
1695 //
1696 //*****************************************************************************
1697 void
SysCtlSleep(void)1698 SysCtlSleep(void)
1699 {
1700 //
1701 // Wait for an interrupt.
1702 //
1703 CPUwfi();
1704 }
1705
1706 //*****************************************************************************
1707 //
1708 //! Puts the processor into deep-sleep mode.
1709 //!
1710 //! This function places the processor into deep-sleep mode; it does not return
1711 //! until the processor returns to run mode. The peripherals that are enabled
1712 //! via SysCtlPeripheralDeepSleepEnable() continue to operate and can wake up
1713 //! the processor (if automatic clock gating is enabled with
1714 //! SysCtlPeripheralClockGating(), otherwise all peripherals continue to
1715 //! operate).
1716 //!
1717 //! \return None.
1718 //
1719 //*****************************************************************************
1720 void
SysCtlDeepSleep(void)1721 SysCtlDeepSleep(void)
1722 {
1723 //
1724 // Enable deep-sleep.
1725 //
1726 HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
1727
1728 //
1729 // Wait for an interrupt.
1730 //
1731 CPUwfi();
1732
1733 //
1734 // Disable deep-sleep so that a future sleep works correctly.
1735 //
1736 HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
1737 }
1738
1739 //*****************************************************************************
1740 //
1741 //! Gets the reason for a reset.
1742 //!
1743 //! This function returns the reason(s) for a reset. Because the reset
1744 //! reasons are sticky until either cleared by software or an external reset
1745 //! (for Sandstorm-class devices) or a power-on reset (for all other classes),
1746 //! multiple reset reasons may be returned if multiple resets have occurred.
1747 //! The reset reason is a logical OR of \b SYSCTL_CAUSE_LDO,
1748 //! \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG, \b SYSCTL_CAUSE_BOR,
1749 //! \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
1750 //!
1751 //! \return Returns the reason(s) for a reset.
1752 //
1753 //*****************************************************************************
1754 unsigned long
SysCtlResetCauseGet(void)1755 SysCtlResetCauseGet(void)
1756 {
1757 //
1758 // Return the reset reasons.
1759 //
1760 return(HWREG(SYSCTL_RESC));
1761 }
1762
1763 //*****************************************************************************
1764 //
1765 //! Clears reset reasons.
1766 //!
1767 //! \param ulCauses are the reset causes to be cleared; must be a logical OR of
1768 //! \b SYSCTL_CAUSE_LDO, \b SYSCTL_CAUSE_SW, \b SYSCTL_CAUSE_WDOG,
1769 //! \b SYSCTL_CAUSE_BOR, \b SYSCTL_CAUSE_POR, and/or \b SYSCTL_CAUSE_EXT.
1770 //!
1771 //! This function clears the specified sticky reset reasons. Once cleared,
1772 //! another reset for the same reason can be detected, and a reset for a
1773 //! different reason can be distinguished (instead of having two reset causes
1774 //! set). If the reset reason is used by an application, all reset causes
1775 //! should be cleared after they are retrieved with SysCtlResetCauseGet().
1776 //!
1777 //! \return None.
1778 //
1779 //*****************************************************************************
1780 void
SysCtlResetCauseClear(unsigned long ulCauses)1781 SysCtlResetCauseClear(unsigned long ulCauses)
1782 {
1783 //
1784 // Clear the given reset reasons.
1785 //
1786 HWREG(SYSCTL_RESC) &= ~(ulCauses);
1787 }
1788
1789 //*****************************************************************************
1790 //
1791 //! Configures the brown-out control.
1792 //!
1793 //! \param ulConfig is the desired configuration of the brown-out control.
1794 //! Must be the logical OR of \b SYSCTL_BOR_RESET and/or
1795 //! \b SYSCTL_BOR_RESAMPLE.
1796 //! \param ulDelay is the number of internal oscillator cycles to wait before
1797 //! resampling an asserted brown-out signal. This value only has meaning when
1798 //! \b SYSCTL_BOR_RESAMPLE is set and must be less than 8192.
1799 //!
1800 //! This function configures how the brown-out control operates. It can detect
1801 //! a brown-out by looking at only the brown-out output, or it can wait for it
1802 //! to be active for two consecutive samples separated by a configurable time.
1803 //! When it detects a brown-out condition, it can either reset the device or
1804 //! generate a processor interrupt.
1805 //!
1806 //! \note The availability of the resample feature is only available on
1807 //! Sandstorm-class devices. Please consult the data sheet for the part you
1808 //! are using to determine whether this feature is available.
1809 //!
1810 //! \return None.
1811 //
1812 //*****************************************************************************
1813 void
SysCtlBrownOutConfigSet(unsigned long ulConfig,unsigned long ulDelay)1814 SysCtlBrownOutConfigSet(unsigned long ulConfig, unsigned long ulDelay)
1815 {
1816 //
1817 // Check the arguments.
1818 //
1819 ASSERT(!(ulConfig & ~(SYSCTL_BOR_RESET | SYSCTL_BOR_RESAMPLE)));
1820 ASSERT(ulDelay < 8192);
1821
1822 //
1823 // Configure the brown-out reset control.
1824 //
1825 HWREG(SYSCTL_PBORCTL) = (ulDelay << SYSCTL_PBORCTL_BORTIM_S) | ulConfig;
1826 }
1827
1828 //*****************************************************************************
1829 //
1830 //! Provides a small delay.
1831 //!
1832 //! \param ulCount is the number of delay loop iterations to perform.
1833 //!
1834 //! This function provides a means of generating a constant length delay. It
1835 //! is written in assembly to keep the delay consistent across tool chains,
1836 //! avoiding the need to tune the delay based on the tool chain in use.
1837 //!
1838 //! The loop takes 3 cycles/loop.
1839 //!
1840 //! \return None.
1841 //
1842 //*****************************************************************************
1843 #if defined(ewarm) || defined(DOXYGEN)
1844 void
SysCtlDelay(unsigned long ulCount)1845 SysCtlDelay(unsigned long ulCount)
1846 {
1847 __asm(" subs r0, #1\n"
1848 " bne.n SysCtlDelay\n"
1849 " bx lr");
1850 }
1851 #endif
1852 #if defined(codered) || defined(gcc) || defined(sourcerygxx)
1853 void __attribute__((naked))
SysCtlDelay(unsigned long ulCount)1854 SysCtlDelay(unsigned long ulCount)
1855 {
1856 __asm(" subs r0, #1\n"
1857 " bne SysCtlDelay\n"
1858 " bx lr");
1859 }
1860 #endif
1861 #if defined(rvmdk) || defined(__ARMCC_VERSION)
1862 __asm void
SysCtlDelay(unsigned long ulCount)1863 SysCtlDelay(unsigned long ulCount)
1864 {
1865 subs r0, #1;
1866 bne SysCtlDelay;
1867 bx lr;
1868 }
1869 #endif
1870 //
1871 // For CCS implement this function in pure assembly. This prevents the TI
1872 // compiler from doing funny things with the optimizer.
1873 //
1874 #if defined(ccs)
1875 __asm(" .sect \".text:SysCtlDelay\"\n"
1876 " .clink\n"
1877 " .thumbfunc SysCtlDelay\n"
1878 " .thumb\n"
1879 " .global SysCtlDelay\n"
1880 "SysCtlDelay:\n"
1881 " subs r0, #1\n"
1882 " bne.n SysCtlDelay\n"
1883 " bx lr\n");
1884 #endif
1885
1886 //*****************************************************************************
1887 //
1888 //! Sets the configuration of the main oscillator (MOSC) control.
1889 //!
1890 //! \param ulConfig is the required configuration of the MOSC control.
1891 //!
1892 //! This function configures the control of the main oscillator. The
1893 //! \e ulConfig is specified as follows:
1894 //!
1895 //! - \b SYSCTL_MOSC_VALIDATE enables the MOSC verification circuit that
1896 //! detects a failure of the main oscillator (such as a loss of the clock).
1897 //! - \b SYSCTL_MOSC_INTERRUPT indicates that a MOSC failure should generate an
1898 //! interrupt instead of resetting the processor.
1899 //! - \b SYSCTL_MOSC_NO_XTAL indicates that there is no crystal connected to
1900 //! the OSC0/OSC1 pins, allowing power consumption to be reduced.
1901 //!
1902 //! \note The availability of MOSC control varies based on the Stellaris part
1903 //! in use. Please consult the data sheet for the part you are using to
1904 //! determine whether this support is available. In addition, the capability
1905 //! of MOSC control varies based on the Stellaris part in use.
1906 //!
1907 //! \return None.
1908 //
1909 //*****************************************************************************
1910 void
SysCtlMOSCConfigSet(unsigned long ulConfig)1911 SysCtlMOSCConfigSet(unsigned long ulConfig)
1912 {
1913 //
1914 // Configure the MOSC control.
1915 //
1916 HWREG(SYSCTL_MOSCCTL) = ulConfig;
1917 }
1918
1919 //*****************************************************************************
1920 //
1921 //! Calibrates the precision internal oscillator.
1922 //!
1923 //! \param ulType is the type of calibration to perform.
1924 //!
1925 //! This function performs a calibration of the PIOSC. There are three types
1926 //! of calibration available; the desired calibration type as specified in
1927 //! \e ulType is one of:
1928 //!
1929 //! - \b SYSCTL_PIOSC_CAL_AUTO to perform automatic calibration using the
1930 //! 32-kHz clock from the hibernate module as a reference. This type is
1931 //! only possible on parts that have a hibernate module, and then only if
1932 //! it is enabled and the hibernate module's RTC is also enabled.
1933 //!
1934 //! - \b SYSCTL_PIOSC_CAL_FACT to reset the PIOSC calibration to the factory
1935 //! provided calibration.
1936 //!
1937 //! - \b SYSCTL_PIOSC_CAL_USER to set the PIOSC calibration to a user-supplied
1938 //! value. The value to be used is ORed into the lower 7-bits of this value,
1939 //! with 0x40 being the ``nominal'' value (in other words, if everything were
1940 //! perfect, 0x40 provides exactly 16 MHz). Values larger than 0x40
1941 //! slow down PIOSC, and values smaller than 0x40 speed up PIOSC.
1942 //!
1943 //! \return Returns 1 if the calibration was successful and 0 if it failed.
1944 //
1945 //*****************************************************************************
1946 unsigned long
SysCtlPIOSCCalibrate(unsigned long ulType)1947 SysCtlPIOSCCalibrate(unsigned long ulType)
1948 {
1949 //
1950 // Perform the requested calibration. If performing user calibration, the
1951 // UTEN bit must be set with one write, then the UT field in a second
1952 // write, and the UPDATE bit in a final write. For other calibration
1953 // types, a single write to set UPDATE or CAL is all that is required.
1954 //
1955 if(ulType & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UPDATE))
1956 {
1957 HWREG(SYSCTL_PIOSCCAL) = ulType & SYSCTL_PIOSCCAL_UTEN;
1958 HWREG(SYSCTL_PIOSCCAL) =
1959 ulType & (SYSCTL_PIOSCCAL_UTEN | SYSCTL_PIOSCCAL_UT_M);
1960 }
1961 HWREG(SYSCTL_PIOSCCAL) = ulType;
1962
1963 //
1964 // See if an automatic calibration was requested.
1965 //
1966 if(ulType & SYSCTL_PIOSCCAL_CAL)
1967 {
1968 //
1969 // Wait for the automatic calibration to complete.
1970 //
1971 while((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) == 0)
1972 {
1973 }
1974
1975 //
1976 // If the automatic calibration failed, return an error.
1977 //
1978 if((HWREG(SYSCTL_PIOSCSTAT) & SYSCTL_PIOSCSTAT_CR_M) !=
1979 SYSCTL_PIOSCSTAT_CRPASS)
1980 {
1981 return(0);
1982 }
1983 }
1984
1985 //
1986 // The calibration was successful.
1987 //
1988 return(1);
1989 }
1990 unsigned long ulSysDiv, ulOsc, ulOscSelect;
1991 tBoolean bNewPLL;
1992
1993
1994 //*****************************************************************************
1995 //
1996 //! Sets the clocking of the device.
1997 //!
1998 //! \param ulConfig is the required configuration of the device clocking.
1999 //!
2000 //! This function configures the clocking of the device. The input crystal
2001 //! frequency, oscillator to be used, use of the PLL, and the system clock
2002 //! divider are all configured with this function.
2003 //!
2004 //! The \e ulConfig parameter is the logical OR of several different values,
2005 //! many of which are grouped into sets where only one can be chosen.
2006 //!
2007 //! The system clock divider is chosen with one of the following values:
2008 //! \b SYSCTL_SYSDIV_1, \b SYSCTL_SYSDIV_2, \b SYSCTL_SYSDIV_3, ...
2009 //! \b SYSCTL_SYSDIV_64. Only \b SYSCTL_SYSDIV_1 through \b SYSCTL_SYSDIV_16
2010 //! are valid on Sandstorm-class devices. Half-dividers, such as
2011 //! \b SYSCTL_SYSDIV_2_5 and \b SYSCTL_SYSDIV_3_5. are available on Tempest-,
2012 //! Firestorm-, and Blizzard-class devices.
2013 //!
2014 //! The use of the PLL is chosen with either \b SYSCTL_USE_PLL or
2015 //! \b SYSCTL_USE_OSC.
2016 //!
2017 //! The external crystal frequency is chosen with one of the following values:
2018 //! \b SYSCTL_XTAL_1MHZ, \b SYSCTL_XTAL_1_84MHZ, \b SYSCTL_XTAL_2MHZ,
2019 //! \b SYSCTL_XTAL_2_45MHZ, \b SYSCTL_XTAL_3_57MHZ, \b SYSCTL_XTAL_3_68MHZ,
2020 //! \b SYSCTL_XTAL_4MHZ, \b SYSCTL_XTAL_4_09MHZ, \b SYSCTL_XTAL_4_91MHZ,
2021 //! \b SYSCTL_XTAL_5MHZ, \b SYSCTL_XTAL_5_12MHZ, \b SYSCTL_XTAL_6MHZ,
2022 //! \b SYSCTL_XTAL_6_14MHZ, \b SYSCTL_XTAL_7_37MHZ, \b SYSCTL_XTAL_8MHZ,
2023 //! \b SYSCTL_XTAL_8_19MHZ, \b SYSCTL_XTAL_10MHZ, \b SYSCTL_XTAL_12MHZ,
2024 //! \b SYSCTL_XTAL_12_2MHZ, \b SYSCTL_XTAL_13_5MHZ, \b SYSCTL_XTAL_14_3MHZ,
2025 //! \b SYSCTL_XTAL_16MHZ, \b SYSCTL_XTAL_16_3MHZ, \b SYSCTL_XTAL_18MHZ,
2026 //! \b SYSCTL_XTAL_20MHZ, \b SYSCTL_XTAL_24MHZ, or \b SYSCTL_XTAL_25MHz.
2027 //! Values below \b SYSCTL_XTAL_3_57MHZ are not valid when the PLL is in
2028 //! operation on Sandstorm-, Fury-, Dustdevil-, Tempest-, and Firestorm-class.
2029 //! devices. Values below \b SYSCTL_XTAL_5MHZ are not valid when the PLL is in
2030 //! operation on Blizzard-class devices. Values below \b SYSCTL_XTAL_4MHZ
2031 //! are never valid on Blizzard-class devices. On Sandstorm- and Fury-class
2032 //! devices, values above \b SYSCTL_XTAL_8_19MHZ are not valid. On Dustdevil-,
2033 //! Tempest-, and Firestorm-class devices, values above \b SYSCTL_XTAL_16_3MHZ
2034 //! are not valid.
2035 //!
2036 //! The oscillator source is chosen with one of the following values:
2037 //! \b SYSCTL_OSC_MAIN, \b SYSCTL_OSC_INT, \b SYSCTL_OSC_INT4,
2038 //! \b SYSCTL_OSC_INT30, or \b SYSCTL_OSC_EXT32. On Sandstorm-class devices,
2039 //! \b SYSCTL_OSC_INT30 and \b SYSCTL_OSC_EXT32 are not valid.
2040 //! \b SYSCTL_OSC_EXT32 is only available on devices with the hibernate module,
2041 //! and then only when the hibernate module has been enabled.
2042 //!
2043 //! The internal and main oscillators are disabled with the
2044 //! \b SYSCTL_INT_OSC_DIS and \b SYSCTL_MAIN_OSC_DIS flags, respectively.
2045 //! The external oscillator must be enabled in order to use an external clock
2046 //! source. Note that attempts to disable the oscillator used to clock the
2047 //! device is prevented by the hardware.
2048 //!
2049 //! To clock the system from an external source (such as an external crystal
2050 //! oscillator), use \b SYSCTL_USE_OSC \b | \b SYSCTL_OSC_MAIN. To clock the
2051 //! system from the main oscillator, use \b SYSCTL_USE_OSC \b |
2052 //! \b SYSCTL_OSC_MAIN. To clock the system from the PLL, use
2053 //! \b SYSCTL_USE_PLL \b | \b SYSCTL_OSC_MAIN, and select the appropriate
2054 //! crystal with one of the \b SYSCTL_XTAL_xxx values.
2055 //!
2056 //! \note If selecting the PLL as the system clock source (that is, via
2057 //! \b SYSCTL_USE_PLL), this function polls the PLL lock interrupt to
2058 //! determine when the PLL has locked. If an interrupt handler for the
2059 //! system control interrupt is in place, and it responds to and clears the
2060 //! PLL lock interrupt, this function delays until its timeout has occurred
2061 //! instead of completing as soon as PLL lock is achieved.
2062 //!
2063 //! \return None.
2064 //
2065 //*****************************************************************************
2066 void
SysCtlClockSet(unsigned long ulConfig)2067 SysCtlClockSet(unsigned long ulConfig)
2068 {
2069 unsigned long ulDelay, ulRCC, ulRCC2;
2070
2071 //
2072 // See if this is a Sandstorm-class device and clocking features from newer
2073 // devices were requested.
2074 //
2075 if(CLASS_IS_SANDSTORM && (ulConfig & SYSCTL_RCC2_USERCC2))
2076 {
2077 //
2078 // Return without changing the clocking because the requested
2079 // configuration can not be achieved.
2080 //
2081 return;
2082 }
2083
2084 //
2085 // Get the current value of the RCC and RCC2 registers. If using a
2086 // Sandstorm-class device, the RCC2 register reads back as zero and the
2087 // writes to it from within this function are ignored.
2088 //
2089 ulRCC = HWREG(SYSCTL_RCC);
2090 ulRCC2 = HWREG(SYSCTL_RCC2);
2091
2092 //
2093 // Bypass the PLL and system clock dividers for now.
2094 //
2095 ulRCC |= SYSCTL_RCC_BYPASS;
2096 ulRCC &= ~(SYSCTL_RCC_USESYSDIV);
2097 ulRCC2 |= SYSCTL_RCC2_BYPASS2;
2098
2099 //
2100 // Write the new RCC value.
2101 //
2102 HWREG(SYSCTL_RCC) = ulRCC;
2103 HWREG(SYSCTL_RCC2) = ulRCC2;
2104
2105 //
2106 // See if either oscillator needs to be enabled.
2107 //
2108 if(((ulRCC & SYSCTL_RCC_IOSCDIS) && !(ulConfig & SYSCTL_RCC_IOSCDIS)) ||
2109 ((ulRCC & SYSCTL_RCC_MOSCDIS) && !(ulConfig & SYSCTL_RCC_MOSCDIS)))
2110 {
2111 //
2112 // Make sure that the required oscillators are enabled. For now, the
2113 // previously enabled oscillators must be enabled along with the newly
2114 // requested oscillators.
2115 //
2116 ulRCC &= (~(SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS) |
2117 (ulConfig & (SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS)));
2118
2119 //
2120 // Write the new RCC value.
2121 //
2122 HWREG(SYSCTL_RCC) = ulRCC;
2123
2124 //
2125 // Wait for a bit, giving the oscillator time to stabilize. The number
2126 // of iterations is adjusted based on the current clock source; a
2127 // smaller number of iterations is required for slower clock rates.
2128 //
2129 if(((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
2130 (((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_30) ||
2131 ((ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) == SYSCTL_RCC2_OSCSRC2_32))) ||
2132 (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
2133 ((ulRCC & SYSCTL_RCC_OSCSRC_M) == SYSCTL_RCC_OSCSRC_30)))
2134 {
2135 //
2136 // Delay for 4096 iterations.
2137 //
2138 SysCtlDelay(4096);
2139 }
2140 else
2141 {
2142 //
2143 // Delay for 524,288 iterations.
2144 //
2145 SysCtlDelay(524288);
2146 }
2147 }
2148
2149 //
2150 // Set the new crystal value and oscillator source. Because the OSCSRC2
2151 // field in RCC2 overlaps the XTAL field in RCC, the OSCSRC field has a
2152 // special encoding within ulConfig to avoid the overlap.
2153 //
2154 ulRCC &= ~(SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
2155 ulRCC |= ulConfig & (SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M);
2156 ulRCC2 &= ~(SYSCTL_RCC2_USERCC2 | SYSCTL_RCC2_OSCSRC2_M);
2157 ulRCC2 |= ulConfig & (SYSCTL_RCC2_USERCC2 | SYSCTL_RCC_OSCSRC_M);
2158 ulRCC2 |= (ulConfig & 0x00000008) << 3;
2159
2160 //
2161 // Write the new RCC value.
2162 //
2163 HWREG(SYSCTL_RCC) = ulRCC;
2164 HWREG(SYSCTL_RCC2) = ulRCC2;
2165
2166 //
2167 // Wait for a bit so that new crystal value and oscillator source can take
2168 // effect.
2169 //
2170 SysCtlDelay(16);
2171
2172 //
2173 // Set the PLL configuration.
2174 //
2175 ulRCC &= ~(SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
2176 ulRCC |= ulConfig & (SYSCTL_RCC_PWRDN | SYSCTL_RCC_OEN);
2177 ulRCC2 &= ~(SYSCTL_RCC2_PWRDN2);
2178 ulRCC2 |= ulConfig & SYSCTL_RCC2_PWRDN2;
2179
2180 //
2181 // Clear the PLL lock interrupt.
2182 //
2183 HWREG(SYSCTL_MISC) = SYSCTL_INT_PLL_LOCK;
2184
2185 //
2186 // Write the new RCC value.
2187 //
2188 if(ulRCC2 & SYSCTL_RCC2_USERCC2)
2189 {
2190 HWREG(SYSCTL_RCC2) = ulRCC2;
2191 HWREG(SYSCTL_RCC) = ulRCC;
2192 }
2193 else
2194 {
2195 HWREG(SYSCTL_RCC) = ulRCC;
2196 HWREG(SYSCTL_RCC2) = ulRCC2;
2197 }
2198
2199 //
2200 // Set the requested system divider and disable the appropriate
2201 // oscillators. This value is not written immediately.
2202 //
2203 ulRCC &= ~(SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
2204 SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
2205 ulRCC |= ulConfig & (SYSCTL_RCC_SYSDIV_M | SYSCTL_RCC_USESYSDIV |
2206 SYSCTL_RCC_IOSCDIS | SYSCTL_RCC_MOSCDIS);
2207 ulRCC2 &= ~(SYSCTL_RCC2_SYSDIV2_M);
2208 ulRCC2 |= ulConfig & SYSCTL_RCC2_SYSDIV2_M;
2209 if(ulConfig & SYSCTL_RCC2_DIV400)
2210 {
2211 ulRCC |= SYSCTL_RCC_USESYSDIV;
2212 ulRCC2 &= ~(SYSCTL_RCC_USESYSDIV);
2213 ulRCC2 |= ulConfig & (SYSCTL_RCC2_DIV400 | SYSCTL_RCC2_SYSDIV2LSB);
2214 }
2215 else
2216 {
2217 ulRCC2 &= ~(SYSCTL_RCC2_DIV400);
2218 }
2219
2220 //
2221 // See if the PLL output is being used to clock the system.
2222 //
2223 if(!(ulConfig & SYSCTL_RCC_BYPASS))
2224 {
2225 //
2226 // Wait until the PLL has locked.
2227 //
2228 for(ulDelay = 32768; ulDelay > 0; ulDelay--)
2229 {
2230 if(HWREG(SYSCTL_RIS) & SYSCTL_INT_PLL_LOCK)
2231 {
2232 break;
2233 }
2234 }
2235
2236 //
2237 // Enable use of the PLL.
2238 //
2239 ulRCC &= ~(SYSCTL_RCC_BYPASS);
2240 ulRCC2 &= ~(SYSCTL_RCC2_BYPASS2);
2241 }
2242
2243 //
2244 // Write the final RCC value.
2245 //
2246 HWREG(SYSCTL_RCC) = ulRCC;
2247 HWREG(SYSCTL_RCC2) = ulRCC2;
2248
2249 //
2250 // Delay for a little bit so that the system divider takes effect.
2251 //
2252 SysCtlDelay(16);
2253 }
2254
2255 //*****************************************************************************
2256 //
2257 //! Gets the processor clock rate.
2258 //!
2259 //! This function determines the clock rate of the processor clock, which is
2260 //! also the clock rate of the peripheral modules (with the exception of
2261 //! PWM, which has its own clock divider; other peripherals may have different
2262 //! clocking, see the device data sheet for details).
2263 //!
2264 //! \note This cannot return accurate results if SysCtlClockSet() has not
2265 //! been called to configure the clocking of the device, or if the device is
2266 //! directly clocked from a crystal (or a clock source) that is not one of the
2267 //! supported crystal frequencies. In the latter case, this function should be
2268 //! modified to directly return the correct system clock rate.
2269 //!
2270 //! \return The processor clock rate.
2271 //
2272 //*****************************************************************************
2273 unsigned long
SysCtlClockGet(void)2274 SysCtlClockGet(void)
2275 {
2276 unsigned long ulRCC, ulRCC2, ulPLL, ulClk;
2277 unsigned long ulPLL1;
2278
2279 //
2280 // Read RCC and RCC2. For Sandstorm-class devices (which do not have
2281 // RCC2), the RCC2 read returns 0, indicating that RCC2 is
2282 // disabled (because the SYSCTL_RCC2_USERCC2 bit is clear).
2283 //
2284 ulRCC = HWREG(SYSCTL_RCC);
2285 ulRCC2 = HWREG(SYSCTL_RCC2);
2286
2287 //
2288 // Get the base clock rate.
2289 //
2290 switch((ulRCC2 & SYSCTL_RCC2_USERCC2) ?
2291 (ulRCC2 & SYSCTL_RCC2_OSCSRC2_M) :
2292 (ulRCC & SYSCTL_RCC_OSCSRC_M))
2293 {
2294 //
2295 // The main oscillator is the clock source. Determine its rate from
2296 // the crystal setting field.
2297 //
2298 case SYSCTL_RCC_OSCSRC_MAIN:
2299 {
2300 ulClk = g_pulXtals[(ulRCC & SYSCTL_RCC_XTAL_M) >>
2301 SYSCTL_RCC_XTAL_S];
2302 break;
2303 }
2304
2305 //
2306 // The internal oscillator is the source clock.
2307 //
2308 case SYSCTL_RCC_OSCSRC_INT:
2309 {
2310 //
2311 // See if this is a Sandstorm-class or Fury-class device.
2312 //
2313 if(CLASS_IS_SANDSTORM)
2314 {
2315 //
2316 // The internal oscillator on a Sandstorm-class device is
2317 // 15 MHz +/- 50%.
2318 //
2319 ulClk = 15000000;
2320 }
2321 else if((CLASS_IS_FURY && REVISION_IS_A2) ||
2322 (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
2323 {
2324 //
2325 // The internal oscillator on a rev A2 Fury-class device and a
2326 // Dustdevil-class device is 12 MHz +/- 30%.
2327 //
2328 ulClk = 12000000;
2329 }
2330 else
2331 {
2332 //
2333 // The internal oscillator on all other devices is 16 MHz.
2334 //
2335 ulClk = 16000000;
2336 }
2337 break;
2338 }
2339
2340 //
2341 // The internal oscillator divided by four is the source clock.
2342 //
2343 case SYSCTL_RCC_OSCSRC_INT4:
2344 {
2345 //
2346 // See if this is a Sandstorm-class or Fury-class device.
2347 //
2348 if(CLASS_IS_SANDSTORM)
2349 {
2350 //
2351 // The internal oscillator on a Sandstorm-class device is
2352 // 15 MHz +/- 50%.
2353 //
2354 ulClk = 15000000 / 4;
2355 }
2356 else if((CLASS_IS_FURY && REVISION_IS_A2) ||
2357 (CLASS_IS_DUSTDEVIL && REVISION_IS_A0))
2358 {
2359 //
2360 // The internal oscillator on a rev A2 Fury-class device and a
2361 // Dustdevil-class device is 12 MHz +/- 30%.
2362 //
2363 ulClk = 12000000 / 4;
2364 }
2365 else
2366 {
2367 //
2368 // The internal oscillator on a Tempest-class device is 16 MHz.
2369 //
2370 ulClk = 16000000 / 4;
2371 }
2372 break;
2373 }
2374
2375 //
2376 // The internal 30-KHz oscillator is the source clock.
2377 //
2378 case SYSCTL_RCC_OSCSRC_30:
2379 {
2380 //
2381 // The internal 30-KHz oscillator has an accuracy of +/- 30%.
2382 //
2383 ulClk = 30000;
2384 break;
2385 }
2386
2387 //
2388 // The 4.194304-MHz clock from the hibernate module is the clock
2389 // source.
2390 //
2391 case SYSCTL_RCC2_OSCSRC2_419:
2392 {
2393 ulClk = 4194304;
2394 break;
2395 }
2396
2397 //
2398 // The 32.768-KHz clock from the hibernate module is the source clock.
2399 //
2400 case SYSCTL_RCC2_OSCSRC2_32:
2401 {
2402 ulClk = 32768;
2403 break;
2404 }
2405
2406 //
2407 // An unknown setting, so return a zero clock (that is, an unknown
2408 // clock rate).
2409 //
2410 default:
2411 {
2412 return(0);
2413 }
2414 }
2415
2416 //
2417 // See if the PLL is being used.
2418 //
2419 if(((ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
2420 (!(ulRCC2 & SYSCTL_RCC2_USERCC2) && !(ulRCC & SYSCTL_RCC_BYPASS)))
2421 {
2422 //
2423 // See if this is a Blizzard-class device.
2424 //
2425 if(CLASS_IS_BLIZZARD)
2426 {
2427 //
2428 // Read the two PLL frequency registers. The formula for a
2429 // Blizzard-class device is "(xtal * m) / ((q + 1) * (n + 1))".
2430 //
2431 ulPLL = HWREG(SYSCTL_PLLFREQ0);
2432 ulPLL1 = HWREG(SYSCTL_PLLFREQ1);
2433
2434 //
2435 // Divide the input clock by the dividers.
2436 //
2437 ulClk /= ((((ulPLL1 & SYSCTL_PLLFREQ1_Q_M) >>
2438 SYSCTL_PLLFREQ1_Q_S) + 1) *
2439 (((ulPLL1 & SYSCTL_PLLFREQ1_N_M) >>
2440 SYSCTL_PLLFREQ1_N_S) + 1) * 2);
2441
2442 //
2443 // Multiply the clock by the multiplier, which is split into an
2444 // integer part and a fractional part.
2445 //
2446 ulClk = ((ulClk * ((ulPLL & SYSCTL_PLLFREQ0_MINT_M) >>
2447 SYSCTL_PLLFREQ0_MINT_S)) +
2448 ((ulClk * ((ulPLL & SYSCTL_PLLFREQ0_MFRAC_M) >>
2449 SYSCTL_PLLFREQ0_MFRAC_S)) >> 10));
2450 }
2451
2452 //
2453 // Older device classes used a different PLL.
2454 //
2455 else
2456 {
2457 //
2458 // Get the PLL configuration.
2459 //
2460 ulPLL = HWREG(SYSCTL_PLLCFG);
2461
2462 //
2463 // See if this is a Sandstorm-class or Fury-class device.
2464 //
2465 if(CLASS_IS_SANDSTORM)
2466 {
2467 //
2468 // Compute the PLL output frequency based on its input
2469 // frequency. The formula for a Sandstorm-class devices is
2470 // "(xtal * (f + 2)) / (r + 2)".
2471 //
2472 ulClk = ((ulClk * (((ulPLL & SYSCTL_PLLCFG_F_M) >>
2473 SYSCTL_PLLCFG_F_S) + 2)) /
2474 (((ulPLL & SYSCTL_PLLCFG_R_M) >>
2475 SYSCTL_PLLCFG_R_S) + 2));
2476 }
2477 else
2478 {
2479 //
2480 // Compute the PLL output frequency based on its input
2481 // frequency. The formula for a Fury-class device is
2482 // "(xtal * f) / ((r + 1) * 2)".
2483 //
2484 ulClk = ((ulClk * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
2485 SYSCTL_PLLCFG_F_S)) /
2486 ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
2487 SYSCTL_PLLCFG_R_S) + 1) * 2));
2488 }
2489
2490 //
2491 // See if the optional output divide by 2 is being used.
2492 //
2493 if(ulPLL & SYSCTL_PLLCFG_OD_2)
2494 {
2495 ulClk /= 2;
2496 }
2497
2498 //
2499 // See if the optional output divide by 4 is being used.
2500 //
2501 if(ulPLL & SYSCTL_PLLCFG_OD_4)
2502 {
2503 ulClk /= 4;
2504 }
2505 }
2506
2507 //
2508 // Force the system divider to be enabled. It is always used when
2509 // using the PLL, but in some cases it does not read as being enabled.
2510 //
2511 ulRCC |= SYSCTL_RCC_USESYSDIV;
2512 }
2513
2514 //
2515 // See if the system divider is being used.
2516 //
2517 if(ulRCC & SYSCTL_RCC_USESYSDIV)
2518 {
2519 //
2520 // Adjust the clock rate by the system clock divider.
2521 //
2522 if(ulRCC2 & SYSCTL_RCC2_USERCC2)
2523 {
2524 if((ulRCC2 & SYSCTL_RCC2_DIV400) &&
2525 (((ulRCC2 & SYSCTL_RCC2_USERCC2) &&
2526 !(ulRCC2 & SYSCTL_RCC2_BYPASS2)) ||
2527 (!(ulRCC2 & SYSCTL_RCC2_USERCC2) &&
2528 !(ulRCC & SYSCTL_RCC_BYPASS))))
2529
2530 {
2531 ulClk = ((ulClk * 2) / (((ulRCC2 & (SYSCTL_RCC2_SYSDIV2_M |
2532 SYSCTL_RCC2_SYSDIV2LSB)) >>
2533 (SYSCTL_RCC2_SYSDIV2_S - 1)) + 1));
2534 }
2535 else
2536 {
2537 ulClk /= (((ulRCC2 & SYSCTL_RCC2_SYSDIV2_M) >>
2538 SYSCTL_RCC2_SYSDIV2_S) + 1);
2539 }
2540 }
2541 else
2542 {
2543 ulClk /= (((ulRCC & SYSCTL_RCC_SYSDIV_M) >> SYSCTL_RCC_SYSDIV_S) +
2544 1);
2545 }
2546 }
2547
2548 //
2549 // Return the computed clock rate.
2550 //
2551 return(ulClk);
2552 }
2553
2554 //*****************************************************************************
2555 //
2556 //! Sets the clocking of the device while in deep-sleep mode.
2557 //!
2558 //! \param ulConfig is the required configuration of the device clocking while
2559 //! in deep-sleep mode.
2560 //!
2561 //! This function configures the clocking of the device while in deep-sleep
2562 //! mode. The oscillator to be used and the system clock divider are
2563 //! configured with this function.
2564 //!
2565 //! The \e ulConfig parameter is the logical OR of the following values:
2566 //!
2567 //! The system clock divider is chosen from one of the following values:
2568 //! \b SYSCTL_DSLP_DIV_1, \b SYSCTL_DSLP_DIV_2, \b SYSCTL_DSLP_DIV_3, ...
2569 //! \b SYSCTL_DSLP_DIV_64.
2570 //!
2571 //! The oscillator source is chosen from one of the following values:
2572 //! \b SYSCTL_DSLP_OSC_MAIN, \b SYSCTL_DSLP_OSC_INT, \b SYSCTL_DSLP_OSC_INT30,
2573 //! or \b SYSCTL_DSLP_OSC_EXT32. \b SYSCTL_OSC_EXT32 is only available on
2574 //! devices with the hibernation module, and then only when the hibernation
2575 //! module has been enabled.
2576 //!
2577 //! The precision internal oscillator can be powered down in deep-sleep mode by
2578 //! specifying \b SYSCTL_DSLP_PIOSC_PD. The precision internal oscillator is
2579 //! not powered down if it is required for operation while in deep-sleep
2580 //! (based on other configuration settings.)
2581 //!
2582 //! \note The availability of deep-sleep clocking configuration varies with the
2583 //! Stellaris part in use. Please consult the data sheet for the part you are
2584 //! using to determine whether this support is available.
2585 //!
2586 //! \return None.
2587 //
2588 //*****************************************************************************
2589 void
SysCtlDeepSleepClockSet(unsigned long ulConfig)2590 SysCtlDeepSleepClockSet(unsigned long ulConfig)
2591 {
2592 //
2593 // Set the deep-sleep clock configuration.
2594 //
2595 HWREG(SYSCTL_DSLPCLKCFG) = ulConfig;
2596 }
2597
2598 //*****************************************************************************
2599 //
2600 //! Sets the PWM clock configuration.
2601 //!
2602 //! \param ulConfig is the configuration for the PWM clock; it must be one of
2603 //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
2604 //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
2605 //! \b SYSCTL_PWMDIV_64.
2606 //!
2607 //! This function configures the rate of the clock provided to the PWM module
2608 //! as a ratio of the processor clock. This clock is used by the PWM module to
2609 //! generate PWM signals; its rate forms the basis for all PWM signals.
2610 //!
2611 //! \note The clocking of the PWM is dependent upon the system clock rate as
2612 //! configured by SysCtlClockSet().
2613 //!
2614 //! \return None.
2615 //
2616 //*****************************************************************************
2617 void
SysCtlPWMClockSet(unsigned long ulConfig)2618 SysCtlPWMClockSet(unsigned long ulConfig)
2619 {
2620 //
2621 // Check the arguments.
2622 //
2623 ASSERT((ulConfig == SYSCTL_PWMDIV_1) ||
2624 (ulConfig == SYSCTL_PWMDIV_2) ||
2625 (ulConfig == SYSCTL_PWMDIV_4) ||
2626 (ulConfig == SYSCTL_PWMDIV_8) ||
2627 (ulConfig == SYSCTL_PWMDIV_16) ||
2628 (ulConfig == SYSCTL_PWMDIV_32) ||
2629 (ulConfig == SYSCTL_PWMDIV_64));
2630
2631 //
2632 // Check that there is a PWM block on this part.
2633 //
2634 ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM0);
2635
2636 //
2637 // Set the PWM clock configuration into the run-mode clock configuration
2638 // register.
2639 //
2640 HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
2641 ~(SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M)) |
2642 ulConfig);
2643 }
2644
2645 //*****************************************************************************
2646 //
2647 //! Gets the current PWM clock configuration.
2648 //!
2649 //! This function returns the current PWM clock configuration.
2650 //!
2651 //! \return Returns the current PWM clock configuration; is one of
2652 //! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
2653 //! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
2654 //! \b SYSCTL_PWMDIV_64.
2655 //
2656 //*****************************************************************************
2657 unsigned long
SysCtlPWMClockGet(void)2658 SysCtlPWMClockGet(void)
2659 {
2660 //
2661 // Check that there is a PWM block on this part.
2662 //
2663 ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM0);
2664
2665 //
2666 // Return the current PWM clock configuration. Make sure that
2667 // SYSCTL_PWMDIV_1 is returned in all cases where the divider is disabled.
2668 //
2669 if(!(HWREG(SYSCTL_RCC) & SYSCTL_RCC_USEPWMDIV))
2670 {
2671 //
2672 // The divider is not active so reflect this in the value we return.
2673 //
2674 return(SYSCTL_PWMDIV_1);
2675 }
2676 else
2677 {
2678 //
2679 // The divider is active so directly return the masked register value.
2680 //
2681 return(HWREG(SYSCTL_RCC) &
2682 (SYSCTL_RCC_USEPWMDIV | SYSCTL_RCC_PWMDIV_M));
2683 }
2684 }
2685
2686 //*****************************************************************************
2687 //
2688 //! Sets the sample rate of the ADC.
2689 //!
2690 //! \param ulSpeed is the desired sample rate of the ADC; must be one of
2691 //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
2692 //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
2693 //!
2694 //! This function configures the rate at which the ADC samples are captured by
2695 //! the ADC block. The sampling speed may be limited by the hardware, so the
2696 //! sample rate may end up being slower than requested. SysCtlADCSpeedGet()
2697 //! returns the actual speed in use.
2698 //!
2699 //! \return None.
2700 //
2701 //*****************************************************************************
2702 void
SysCtlADCSpeedSet(unsigned long ulSpeed)2703 SysCtlADCSpeedSet(unsigned long ulSpeed)
2704 {
2705 //
2706 // Check the arguments.
2707 //
2708 ASSERT((ulSpeed == SYSCTL_ADCSPEED_1MSPS) ||
2709 (ulSpeed == SYSCTL_ADCSPEED_500KSPS) ||
2710 (ulSpeed == SYSCTL_ADCSPEED_250KSPS) ||
2711 (ulSpeed == SYSCTL_ADCSPEED_125KSPS));
2712
2713 //
2714 // Set the ADC speed in run and sleep mode.
2715 //
2716 HWREG(SYSCTL_RCGC0) = ((HWREG(SYSCTL_RCGC0) & ~(SYSCTL_RCGC0_ADCSPD_M)) |
2717 ulSpeed);
2718 HWREG(SYSCTL_SCGC0) = ((HWREG(SYSCTL_SCGC0) & ~(SYSCTL_SCGC0_ADCSPD_M)) |
2719 ulSpeed);
2720 }
2721
2722 //*****************************************************************************
2723 //
2724 //! Gets the sample rate of the ADC.
2725 //!
2726 //! This function gets the current sample rate of the ADC.
2727 //!
2728 //! \return Returns the current ADC sample rate; is one of
2729 //! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
2730 //! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
2731 //
2732 //*****************************************************************************
2733 unsigned long
SysCtlADCSpeedGet(void)2734 SysCtlADCSpeedGet(void)
2735 {
2736 //
2737 // Return the current ADC speed.
2738 //
2739 return(HWREG(SYSCTL_RCGC0) & SYSCTL_RCGC0_ADCSPD_M);
2740 }
2741
2742 //*****************************************************************************
2743 //
2744 //! Configures the internal oscillator verification timer.
2745 //!
2746 //! \param bEnable is a boolean that is \b true if the internal oscillator
2747 //! verification timer should be enabled.
2748 //!
2749 //! This function allows the internal oscillator verification timer to be
2750 //! enabled or disabled. When enabled, an interrupt is generated if the
2751 //! internal oscillator ceases to operate.
2752 //!
2753 //! The internal oscillator verification timer is only available on
2754 //! Sandstorm-class devices.
2755 //!
2756 //! \note Both oscillators (main and internal) must be enabled for this
2757 //! verification timer to operate as the main oscillator verifies the
2758 //! internal oscillator.
2759 //!
2760 //! \return None.
2761 //
2762 //*****************************************************************************
2763 void
SysCtlIOSCVerificationSet(tBoolean bEnable)2764 SysCtlIOSCVerificationSet(tBoolean bEnable)
2765 {
2766 //
2767 // Enable or disable the internal oscillator verification timer as
2768 // requested.
2769 //
2770 if(bEnable)
2771 {
2772 HWREG(SYSCTL_RCC) |= SYSCTL_RCC_IOSCVER;
2773 }
2774 else
2775 {
2776 HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_IOSCVER);
2777 }
2778 }
2779
2780 //*****************************************************************************
2781 //
2782 //! Configures the main oscillator verification timer.
2783 //!
2784 //! \param bEnable is a boolean that is \b true if the main oscillator
2785 //! verification timer should be enabled.
2786 //!
2787 //! This function allows the main oscillator verification timer to be enabled
2788 //! or disabled. When enabled, an interrupt is generated if the main
2789 //! oscillator ceases to operate.
2790 //!
2791 //! The main oscillator verification timer is only available on
2792 //! Sandstorm-class devices.
2793 //!
2794 //! \note Both oscillators (main and internal) must be enabled for this
2795 //! verification timer to operate as the internal oscillator verifies the
2796 //! main oscillator.
2797 //!
2798 //! \return None.
2799 //
2800 //*****************************************************************************
2801 void
SysCtlMOSCVerificationSet(tBoolean bEnable)2802 SysCtlMOSCVerificationSet(tBoolean bEnable)
2803 {
2804 //
2805 // Enable or disable the main oscillator verification timer as requested.
2806 //
2807 if(bEnable)
2808 {
2809 HWREG(SYSCTL_RCC) |= SYSCTL_RCC_MOSCVER;
2810 }
2811 else
2812 {
2813 HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCVER);
2814 }
2815 }
2816
2817 //*****************************************************************************
2818 //
2819 //! Configures the PLL verification timer.
2820 //!
2821 //! \param bEnable is a boolean that is \b true if the PLL verification timer
2822 //! should be enabled.
2823 //!
2824 //! This function allows the PLL verification timer to be enabled or disabled.
2825 //! When enabled, an interrupt is generated if the PLL ceases to operate.
2826 //!
2827 //! The PLL verification timer is only available on Sandstorm-class devices.
2828 //!
2829 //! \note The main oscillator must be enabled for this verification timer to
2830 //! operate as it is used to check the PLL. Also, the verification timer
2831 //! should be disabled while the PLL is being reconfigured via
2832 //! SysCtlClockSet().
2833 //!
2834 //! \return None.
2835 //
2836 //*****************************************************************************
2837 void
SysCtlPLLVerificationSet(tBoolean bEnable)2838 SysCtlPLLVerificationSet(tBoolean bEnable)
2839 {
2840 //
2841 // Enable or disable the PLL verification timer as requested.
2842 //
2843 if(bEnable)
2844 {
2845 HWREG(SYSCTL_RCC) |= SYSCTL_RCC_PLLVER;
2846 }
2847 else
2848 {
2849 HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_PLLVER);
2850 }
2851 }
2852
2853 //*****************************************************************************
2854 //
2855 //! Clears the clock verification status.
2856 //!
2857 //! This function clears the status of the clock verification timers, allowing
2858 //! them to assert another failure if detected.
2859 //!
2860 //! The clock verification timers are only available on Sandstorm-class
2861 //! devices.
2862 //!
2863 //! \return None.
2864 //
2865 //*****************************************************************************
2866 void
SysCtlClkVerificationClear(void)2867 SysCtlClkVerificationClear(void)
2868 {
2869 //
2870 // Clear the clock verification.
2871 //
2872 HWREG(SYSCTL_CLKVCLR) = SYSCTL_CLKVCLR_VERCLR;
2873
2874 //
2875 // The bit does not self-reset, so clear it.
2876 //
2877 HWREG(SYSCTL_CLKVCLR) = 0;
2878 }
2879
2880 //*****************************************************************************
2881 //
2882 //! Enables a GPIO peripheral for access from the AHB.
2883 //!
2884 //! \param ulGPIOPeripheral is the GPIO peripheral to enable.
2885 //!
2886 //! This function is used to enable the specified GPIO peripheral to be
2887 //! accessed from the Advanced Host Bus (AHB) instead of the legacy Advanced
2888 //! Peripheral Bus (APB). When a GPIO peripheral is enabled for AHB access,
2889 //! the \b _AHB_BASE form of the base address should be used for GPIO
2890 //! functions. For example, instead of using \b GPIO_PORTA_BASE as the base
2891 //! address for GPIO functions, use \b GPIO_PORTA_AHB_BASE instead.
2892 //!
2893 //! The \e ulGPIOPeripheral argument must be only one of the following values:
2894 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
2895 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
2896 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
2897 //!
2898 //! \return None.
2899 //
2900 //*****************************************************************************
2901 void
SysCtlGPIOAHBEnable(unsigned long ulGPIOPeripheral)2902 SysCtlGPIOAHBEnable(unsigned long ulGPIOPeripheral)
2903 {
2904 //
2905 // Check the arguments.
2906 //
2907 ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
2908 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
2909 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
2910 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
2911 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
2912 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
2913 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
2914 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
2915 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
2916
2917 //
2918 // Enable this GPIO for AHB access.
2919 //
2920 HWREG(SYSCTL_GPIOHBCTL) |= ulGPIOPeripheral & 0xFFFF;
2921 }
2922
2923 //*****************************************************************************
2924 //
2925 //! Disables a GPIO peripheral for access from the AHB.
2926 //!
2927 //! \param ulGPIOPeripheral is the GPIO peripheral to disable.
2928 //!
2929 //! This function disables the specified GPIO peripheral for access from the
2930 //! Advanced Host Bus (AHB). Once disabled, the GPIO peripheral is accessed
2931 //! from the legacy Advanced Peripheral Bus (APB).
2932 //!
2933 //! The \b ulGPIOPeripheral argument must be only one of the following values:
2934 //! \b SYSCTL_PERIPH_GPIOA, \b SYSCTL_PERIPH_GPIOB, \b SYSCTL_PERIPH_GPIOC,
2935 //! \b SYSCTL_PERIPH_GPIOD, \b SYSCTL_PERIPH_GPIOE, \b SYSCTL_PERIPH_GPIOF,
2936 //! \b SYSCTL_PERIPH_GPIOG, \b SYSCTL_PERIPH_GPIOH, or \b SYSCTL_PERIPH_GPIOJ.
2937 //!
2938 //! \return None.
2939 //
2940 //*****************************************************************************
2941 void
SysCtlGPIOAHBDisable(unsigned long ulGPIOPeripheral)2942 SysCtlGPIOAHBDisable(unsigned long ulGPIOPeripheral)
2943 {
2944 //
2945 // Check the arguments.
2946 //
2947 ASSERT((ulGPIOPeripheral == SYSCTL_PERIPH_GPIOA) ||
2948 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOB) ||
2949 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOC) ||
2950 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOD) ||
2951 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOE) ||
2952 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOF) ||
2953 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOG) ||
2954 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOH) ||
2955 (ulGPIOPeripheral == SYSCTL_PERIPH_GPIOJ));
2956
2957 //
2958 // Disable this GPIO for AHB access.
2959 //
2960 HWREG(SYSCTL_GPIOHBCTL) &= ~(ulGPIOPeripheral & 0xFFFF);
2961 }
2962
2963 //*****************************************************************************
2964 //
2965 //! Powers up the USB PLL.
2966 //!
2967 //! This function enables the USB controller's PLL, which is used by it's
2968 //! physical layer. This call is necessary before connecting to any external
2969 //! devices.
2970 //!
2971 //! \return None.
2972 //
2973 //*****************************************************************************
2974 void
SysCtlUSBPLLEnable(void)2975 SysCtlUSBPLLEnable(void)
2976 {
2977 //
2978 // Turn on the USB PLL.
2979 //
2980 HWREG(SYSCTL_RCC2) &= ~SYSCTL_RCC2_USBPWRDN;
2981 }
2982
2983 //*****************************************************************************
2984 //
2985 //! Powers down the USB PLL.
2986 //!
2987 //! This function disables the USB controller's PLL, which is used by it's
2988 //! physical layer. The USB registers are still accessible, but the physical
2989 //! layer no longer functions.
2990 //!
2991 //! \return None.
2992 //
2993 //*****************************************************************************
2994 void
SysCtlUSBPLLDisable(void)2995 SysCtlUSBPLLDisable(void)
2996 {
2997 //
2998 // Turn off the USB PLL.
2999 //
3000 HWREG(SYSCTL_RCC2) |= SYSCTL_RCC2_USBPWRDN;
3001 }
3002
3003 //*****************************************************************************
3004 //
3005 //! Sets the MCLK frequency provided to the I2S module.
3006 //!
3007 //! \param ulInputClock is the input clock to the MCLK divider. If this value
3008 //! is zero, the value is computed from the current PLL configuration.
3009 //! \param ulMClk is the desired MCLK frequency. If this value is zero, MCLK
3010 //! output is disabled.
3011 //!
3012 //! This function configures the dividers to provide MCLK to the I2S module. A
3013 //! MCLK divider is chosen that produces the MCLK frequency that is the closest
3014 //! possible to the requested frequency, which may be above or below the
3015 //! requested frequency.
3016 //!
3017 //! The actual MCLK frequency is returned. It is the responsibility of the
3018 //! application to determine if the selected MCLK is acceptable; in general the
3019 //! human ear can not discern the frequency difference if it is within 0.3% of
3020 //! the desired frequency (although there is a very small percentage of the
3021 //! population that can discern lower frequency deviations).
3022 //!
3023 //! \return Returns the actual MCLK frequency.
3024 //
3025 //*****************************************************************************
3026 unsigned long
SysCtlI2SMClkSet(unsigned long ulInputClock,unsigned long ulMClk)3027 SysCtlI2SMClkSet(unsigned long ulInputClock, unsigned long ulMClk)
3028 {
3029 unsigned long ulDivInt, ulDivFrac, ulPLL;
3030
3031 //
3032 // See if the I2S MCLK should be disabled.
3033 //
3034 if(ulMClk == 0)
3035 {
3036 //
3037 // Disable the I2S MCLK and return.
3038 //
3039 HWREG(SYSCTL_I2SMCLKCFG) = 0;
3040 return(0);
3041 }
3042
3043 //
3044 // See if the input clock was specified.
3045 //
3046 if(ulInputClock == 0)
3047 {
3048 //
3049 // The input clock was not specified, so compute the output frequency
3050 // of the PLL. Get the current PLL configuration.
3051 //
3052 ulPLL = HWREG(SYSCTL_PLLCFG);
3053
3054 //
3055 // Get the frequency of the crystal in use.
3056 //
3057 ulInputClock = g_pulXtals[(HWREG(SYSCTL_RCC) & SYSCTL_RCC_XTAL_M) >>
3058 SYSCTL_RCC_XTAL_S];
3059
3060 //
3061 // Calculate the PLL output frequency.
3062 //
3063 ulInputClock = ((ulInputClock * ((ulPLL & SYSCTL_PLLCFG_F_M) >>
3064 SYSCTL_PLLCFG_F_S)) /
3065 ((((ulPLL & SYSCTL_PLLCFG_R_M) >>
3066 SYSCTL_PLLCFG_R_S) + 1)));
3067
3068 //
3069 // See if the optional output divide by 2 is being used.
3070 //
3071 if(ulPLL & SYSCTL_PLLCFG_OD_2)
3072 {
3073 ulInputClock /= 2;
3074 }
3075
3076 //
3077 // See if the optional output divide by 4 is being used.
3078 //
3079 if(ulPLL & SYSCTL_PLLCFG_OD_4)
3080 {
3081 ulInputClock /= 4;
3082 }
3083 }
3084
3085 //
3086 // Verify that the requested MCLK frequency is attainable.
3087 //
3088 ASSERT(ulMClk < ulInputClock);
3089
3090 //
3091 // Add a rounding factor to the input clock, so that the MCLK frequency
3092 // that is closest to the desire value is selected.
3093 //
3094 ulInputClock += (ulMClk / 32) - 1;
3095
3096 //
3097 // Compute the integer portion of the MCLK divider.
3098 //
3099 ulDivInt = ulInputClock / ulMClk;
3100
3101 //
3102 // If the divisor is too large, then simply use the maximum divisor.
3103 //
3104 if(CLASS_IS_TEMPEST && REVISION_IS_B1 && (ulDivInt > 255))
3105 {
3106 ulDivInt = 255;
3107 ulDivFrac = 15;
3108 }
3109 else if(ulDivInt > 1023)
3110 {
3111 ulDivInt = 1023;
3112 ulDivFrac = 15;
3113 }
3114 else
3115 {
3116 //
3117 // Compute the fractional portion of the MCLK divider.
3118 //
3119 ulDivFrac = ((ulInputClock - (ulDivInt * ulMClk)) * 16) / ulMClk;
3120 }
3121
3122 //
3123 // Set the divisor for the TX and RX MCLK generators and enable the clocks.
3124 //
3125 HWREG(SYSCTL_I2SMCLKCFG) = (SYSCTL_I2SMCLKCFG_RXEN |
3126 (ulDivInt << SYSCTL_I2SMCLKCFG_RXI_S) |
3127 (ulDivFrac << SYSCTL_I2SMCLKCFG_RXF_S) |
3128 SYSCTL_I2SMCLKCFG_TXEN |
3129 (ulDivInt << SYSCTL_I2SMCLKCFG_TXI_S) |
3130 (ulDivFrac << SYSCTL_I2SMCLKCFG_TXF_S));
3131
3132 //
3133 // Return the actual MCLK frequency.
3134 //
3135 ulInputClock -= (ulMClk / 32) - 1;
3136 ulDivInt = (ulDivInt * 16) + ulDivFrac;
3137 ulMClk = (ulInputClock / ulDivInt) * 16;
3138 ulMClk += ((ulInputClock - ((ulMClk / 16) * ulDivInt)) * 16) / ulDivInt;
3139 return(ulMClk);
3140 }
3141
3142 //*****************************************************************************
3143 //
3144 // Close the Doxygen group.
3145 //! @}
3146 //
3147 //*****************************************************************************
3148