1 /******************************************************************************
2 * Filename: prcm.c
3 * Revised: 2015-09-09 11:55:59 +0200 (Wed, 09 Sep 2015)
4 * Revision: 44536
5 *
6 * Description: Driver for the PRCM.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38
39 #include <driverlib/prcm.h>
40
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #if !defined(DOXYGEN)
48 #undef PRCMInfClockConfigureSet
49 #define PRCMInfClockConfigureSet NOROM_PRCMInfClockConfigureSet
50 #undef PRCMInfClockConfigureGet
51 #define PRCMInfClockConfigureGet NOROM_PRCMInfClockConfigureGet
52 #undef PRCMAudioClockConfigSet
53 #define PRCMAudioClockConfigSet NOROM_PRCMAudioClockConfigSet
54 #undef PRCMAudioClockConfigSetOverride
55 #define PRCMAudioClockConfigSetOverride NOROM_PRCMAudioClockConfigSetOverride
56 #undef PRCMPowerDomainOn
57 #define PRCMPowerDomainOn NOROM_PRCMPowerDomainOn
58 #undef PRCMPowerDomainOff
59 #define PRCMPowerDomainOff NOROM_PRCMPowerDomainOff
60 #undef PRCMPeripheralRunEnable
61 #define PRCMPeripheralRunEnable NOROM_PRCMPeripheralRunEnable
62 #undef PRCMPeripheralRunDisable
63 #define PRCMPeripheralRunDisable NOROM_PRCMPeripheralRunDisable
64 #undef PRCMPeripheralSleepEnable
65 #define PRCMPeripheralSleepEnable NOROM_PRCMPeripheralSleepEnable
66 #undef PRCMPeripheralSleepDisable
67 #define PRCMPeripheralSleepDisable NOROM_PRCMPeripheralSleepDisable
68 #undef PRCMPeripheralDeepSleepEnable
69 #define PRCMPeripheralDeepSleepEnable NOROM_PRCMPeripheralDeepSleepEnable
70 #undef PRCMPeripheralDeepSleepDisable
71 #define PRCMPeripheralDeepSleepDisable NOROM_PRCMPeripheralDeepSleepDisable
72 #undef PRCMPowerDomainStatus
73 #define PRCMPowerDomainStatus NOROM_PRCMPowerDomainStatus
74 #undef PRCMDeepSleep
75 #define PRCMDeepSleep NOROM_PRCMDeepSleep
76 #endif
77
78
79 //*****************************************************************************
80 //
81 // Arrays that maps the "peripheral set" number (which is stored in the
82 // third nibble of the PRCM_PERIPH_* defines) to the PRCM register that
83 // contains the relevant bit for that peripheral.
84 //
85 //*****************************************************************************
86
87 // Run mode registers
88 static const uint32_t g_pui32RCGCRegs[] =
89 {
90 PRCM_O_GPTCLKGR,
91 PRCM_O_SSICLKGR,
92 PRCM_O_UARTCLKGR,
93 PRCM_O_I2CCLKGR,
94 PRCM_O_SECDMACLKGR,
95 PRCM_O_GPIOCLKGR,
96 PRCM_O_I2SCLKGR
97 };
98
99 // Sleep mode registers
100 static const uint32_t g_pui32SCGCRegs[] =
101 {
102 PRCM_O_GPTCLKGS,
103 PRCM_O_SSICLKGS,
104 PRCM_O_UARTCLKGS,
105 PRCM_O_I2CCLKGS,
106 PRCM_O_SECDMACLKGS,
107 PRCM_O_GPIOCLKGS,
108 PRCM_O_I2SCLKGS
109 };
110
111 // Deep sleep mode registers
112 static const uint32_t g_pui32DCGCRegs[] =
113 {
114 PRCM_O_GPTCLKGDS,
115 PRCM_O_SSICLKGDS,
116 PRCM_O_UARTCLKGDS,
117 PRCM_O_I2CCLKGDS,
118 PRCM_O_SECDMACLKGDS,
119 PRCM_O_GPIOCLKGDS,
120 PRCM_O_I2SCLKGDS
121 };
122
123 //*****************************************************************************
124 //
125 // This macro extracts the array index out of the peripheral number
126 //
127 //*****************************************************************************
128 #define PRCM_PERIPH_INDEX(a) (((a) >> 8) & 0xf)
129
130 //*****************************************************************************
131 //
132 // This macro extracts the peripheral instance number and generates bit mask
133 //
134 //*****************************************************************************
135 #define PRCM_PERIPH_MASKBIT(a) (0x00000001 << ((a) & 0xf))
136
137
138 //*****************************************************************************
139 //
140 //! Configure the infrastructure clock.
141 //
142 //*****************************************************************************
143 void
PRCMInfClockConfigureSet(uint32_t ui32ClkDiv,uint32_t ui32PowerMode)144 PRCMInfClockConfigureSet(uint32_t ui32ClkDiv, uint32_t ui32PowerMode)
145 {
146 uint32_t ui32Divisor;
147
148 //
149 // Check the arguments.
150 //
151 ASSERT((ui32ClkDiv == PRCM_CLOCK_DIV_1) ||
152 (ui32ClkDiv == PRCM_CLOCK_DIV_2) ||
153 (ui32ClkDiv == PRCM_CLOCK_DIV_8) ||
154 (ui32ClkDiv == PRCM_CLOCK_DIV_32));
155 ASSERT((ui32PowerMode == PRCM_RUN_MODE) ||
156 (ui32PowerMode == PRCM_SLEEP_MODE) ||
157 (ui32PowerMode == PRCM_DEEP_SLEEP_MODE));
158
159 ui32Divisor = 0;
160
161 //
162 // Find the correct division factor.
163 //
164 if(ui32ClkDiv == PRCM_CLOCK_DIV_1)
165 {
166 ui32Divisor = 0x0;
167 }
168 else if(ui32ClkDiv == PRCM_CLOCK_DIV_2)
169 {
170 ui32Divisor = 0x1;
171 }
172 else if(ui32ClkDiv == PRCM_CLOCK_DIV_8)
173 {
174 ui32Divisor = 0x2;
175 }
176 else if(ui32ClkDiv == PRCM_CLOCK_DIV_32)
177 {
178 ui32Divisor = 0x3;
179 }
180
181 //
182 // Determine the correct power mode set the division factor accordingly.
183 //
184 if(ui32PowerMode == PRCM_RUN_MODE)
185 {
186 HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVR) = ui32Divisor;
187 }
188 else if(ui32PowerMode == PRCM_SLEEP_MODE)
189 {
190 HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVS) = ui32Divisor;
191 }
192 else if(ui32PowerMode == PRCM_DEEP_SLEEP_MODE)
193 {
194 HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVDS) = ui32Divisor;
195 }
196 }
197
198 //*****************************************************************************
199 //
200 //! Use this function to get the infrastructure clock configuration
201 //
202 //*****************************************************************************
203 uint32_t
PRCMInfClockConfigureGet(uint32_t ui32PowerMode)204 PRCMInfClockConfigureGet(uint32_t ui32PowerMode)
205 {
206 uint32_t ui32ClkDiv;
207 uint32_t ui32Divisor;
208
209 //
210 // Check the arguments.
211 //
212 ASSERT((ui32PowerMode == PRCM_RUN_MODE) ||
213 (ui32PowerMode == PRCM_SLEEP_MODE) ||
214 (ui32PowerMode == PRCM_DEEP_SLEEP_MODE));
215
216 ui32ClkDiv = 0;
217 ui32Divisor = 0;
218
219 //
220 // Determine the correct power mode.
221 //
222 if(ui32PowerMode == PRCM_RUN_MODE)
223 {
224 ui32ClkDiv = HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVR);
225 }
226 else if(ui32PowerMode == PRCM_SLEEP_MODE)
227 {
228 ui32ClkDiv = HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVS);
229 }
230 else if(ui32PowerMode == PRCM_DEEP_SLEEP_MODE)
231 {
232 ui32ClkDiv = HWREG(PRCM_BASE + PRCM_O_INFRCLKDIVDS);
233 }
234
235 //
236 // Find the correct division factor.
237 //
238 if(ui32ClkDiv == 0x0)
239 {
240 ui32Divisor = PRCM_CLOCK_DIV_1;
241 }
242 else if(ui32ClkDiv == 0x1)
243 {
244 ui32Divisor = PRCM_CLOCK_DIV_2;
245 }
246 else if(ui32ClkDiv == 0x2)
247 {
248 ui32Divisor = PRCM_CLOCK_DIV_8;
249 }
250 else if(ui32ClkDiv == 0x3)
251 {
252 ui32Divisor = PRCM_CLOCK_DIV_32;
253 }
254
255 //
256 // Return the clock division factor.
257 //
258 return ui32Divisor;
259 }
260
261
262 //*****************************************************************************
263 //
264 //! Configure the audio clock generation
265 //
266 //*****************************************************************************
267 void
PRCMAudioClockConfigSet(uint32_t ui32ClkConfig,uint32_t ui32SampleRate)268 PRCMAudioClockConfigSet(uint32_t ui32ClkConfig, uint32_t ui32SampleRate)
269 {
270 uint32_t ui32Reg;
271 uint32_t ui32MstDiv;
272 uint32_t ui32BitDiv;
273 uint32_t ui32WordDiv;
274
275 //
276 // Check the arguments.
277 //
278 ASSERT(!(ui32ClkConfig & (PRCM_I2SCLKCTL_WCLK_PHASE_M | PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_M)));
279 ASSERT((ui32SampleRate == I2S_SAMPLE_RATE_16K) ||
280 (ui32SampleRate == I2S_SAMPLE_RATE_24K) ||
281 (ui32SampleRate == I2S_SAMPLE_RATE_32K) ||
282 (ui32SampleRate == I2S_SAMPLE_RATE_48K));
283
284 ui32MstDiv = 0;
285 ui32BitDiv = 0;
286 ui32WordDiv = 0;
287
288 //
289 // Make sure the audio clock generation is disabled before reconfiguring.
290 //
291 PRCMAudioClockDisable();
292
293 //
294 // Define the clock division factors for the audio interface.
295 //
296 switch(ui32SampleRate)
297 {
298 case I2S_SAMPLE_RATE_16K :
299 ui32MstDiv = 6;
300 ui32BitDiv = 60;
301 ui32WordDiv = 25;
302 break;
303 case I2S_SAMPLE_RATE_24K :
304 ui32MstDiv = 4;
305 ui32BitDiv = 40;
306 ui32WordDiv = 25;
307 break;
308 case I2S_SAMPLE_RATE_32K :
309 ui32MstDiv = 3;
310 ui32BitDiv = 30;
311 ui32WordDiv = 25;
312 break;
313 case I2S_SAMPLE_RATE_48K :
314 ui32MstDiv = 2;
315 ui32BitDiv = 20;
316 ui32WordDiv = 25;
317 break;
318 }
319
320 //
321 // Make sure to compensate the Frame clock division factor if using single
322 // phase format.
323 //
324 if((ui32ClkConfig & PRCM_I2SCLKCTL_WCLK_PHASE_M) == PRCM_WCLK_SINGLE_PHASE)
325 {
326 ui32WordDiv -= 1;
327 }
328
329 //
330 // Write the clock division factors.
331 //
332 HWREG(PRCM_BASE + PRCM_O_I2SMCLKDIV) = ui32MstDiv;
333 HWREG(PRCM_BASE + PRCM_O_I2SBCLKDIV) = ui32BitDiv;
334 HWREG(PRCM_BASE + PRCM_O_I2SWCLKDIV) = ui32WordDiv;
335
336 //
337 // Configure the Word clock format and polarity.
338 //
339 ui32Reg = HWREG(PRCM_BASE + PRCM_O_I2SCLKCTL) & ~(PRCM_I2SCLKCTL_WCLK_PHASE_M |
340 PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_M);
341 HWREG(PRCM_BASE + PRCM_O_I2SCLKCTL) = ui32Reg | ui32ClkConfig;
342 }
343
344 //*****************************************************************************
345 //
346 //! Configure the audio clock generation with manual setting of clock divider.
347 //
348 //*****************************************************************************
349 void
PRCMAudioClockConfigSetOverride(uint32_t ui32ClkConfig,uint32_t ui32MstDiv,uint32_t ui32BitDiv,uint32_t ui32WordDiv)350 PRCMAudioClockConfigSetOverride(uint32_t ui32ClkConfig, uint32_t ui32MstDiv,
351 uint32_t ui32BitDiv, uint32_t ui32WordDiv)
352 {
353 uint32_t ui32Reg;
354
355 //
356 // Check the arguments.
357 //
358 ASSERT(!(ui32ClkConfig & (PRCM_I2SCLKCTL_WCLK_PHASE_M | PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_M)));
359
360 //
361 // Make sure the audio clock generation is disabled before reconfiguring.
362 //
363 PRCMAudioClockDisable();
364
365 //
366 // Make sure to compensate the Frame clock division factor if using single
367 // phase format.
368 //
369 if((ui32ClkConfig & PRCM_I2SCLKCTL_WCLK_PHASE_M) == PRCM_WCLK_SINGLE_PHASE)
370 {
371 ui32WordDiv -= 1;
372 }
373
374 //
375 // Write the clock division factors.
376 //
377 HWREG(PRCM_BASE + PRCM_O_I2SMCLKDIV) = ui32MstDiv;
378 HWREG(PRCM_BASE + PRCM_O_I2SBCLKDIV) = ui32BitDiv;
379 HWREG(PRCM_BASE + PRCM_O_I2SWCLKDIV) = ui32WordDiv;
380
381 //
382 // Configure the Word clock format and polarity.
383 //
384 ui32Reg = HWREG(PRCM_BASE + PRCM_O_I2SCLKCTL) & ~(PRCM_I2SCLKCTL_WCLK_PHASE_M |
385 PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_M);
386 HWREG(PRCM_BASE + PRCM_O_I2SCLKCTL) = ui32Reg | ui32ClkConfig;
387 }
388
389 //*****************************************************************************
390 //
391 //! Turn power on in power domains in the MCU domain
392 //
393 //*****************************************************************************
394 void
PRCMPowerDomainOn(uint32_t ui32Domains)395 PRCMPowerDomainOn(uint32_t ui32Domains)
396 {
397 //
398 // Check the arguments.
399 //
400 ASSERT((ui32Domains & PRCM_DOMAIN_RFCORE) ||
401 (ui32Domains & PRCM_DOMAIN_SERIAL) ||
402 (ui32Domains & PRCM_DOMAIN_PERIPH) ||
403 (ui32Domains & PRCM_DOMAIN_CPU) ||
404 (ui32Domains & PRCM_DOMAIN_VIMS));
405
406 //
407 // Assert the request to power on the right domains.
408 //
409 if(ui32Domains & PRCM_DOMAIN_RFCORE)
410 {
411 HWREG(PRCM_BASE +
412 PRCM_O_PDCTL0RFC) |= PRCM_PDCTL0RFC_ON;
413 HWREG(PRCM_BASE + PRCM_O_PDCTL1RFC) |= PRCM_PDCTL1RFC_ON;
414 }
415 if(ui32Domains & PRCM_DOMAIN_SERIAL)
416 {
417 HWREG(PRCM_BASE +
418 PRCM_O_PDCTL0SERIAL) |= PRCM_PDCTL0SERIAL_ON;
419 }
420 if(ui32Domains & PRCM_DOMAIN_PERIPH)
421 {
422 HWREG(PRCM_BASE +
423 PRCM_O_PDCTL0PERIPH) |= PRCM_PDCTL0PERIPH_ON;
424 }
425 if(ui32Domains & PRCM_DOMAIN_VIMS)
426 {
427 HWREG(PRCM_BASE + PRCM_O_PDCTL1VIMS) |=
428 PRCM_PDCTL1VIMS_ON;
429 }
430 if(ui32Domains & PRCM_DOMAIN_CPU)
431 {
432 HWREG(PRCM_BASE + PRCM_O_PDCTL1CPU) |= PRCM_PDCTL1CPU_ON;
433 }
434 }
435
436 //*****************************************************************************
437 //
438 //! Turn off a specific power domain
439 //
440 //*****************************************************************************
441 void
PRCMPowerDomainOff(uint32_t ui32Domains)442 PRCMPowerDomainOff(uint32_t ui32Domains)
443 {
444 //
445 // Check the arguments.
446 //
447 ASSERT((ui32Domains & PRCM_DOMAIN_RFCORE) ||
448 (ui32Domains & PRCM_DOMAIN_SERIAL) ||
449 (ui32Domains & PRCM_DOMAIN_PERIPH) ||
450 (ui32Domains & PRCM_DOMAIN_CPU) ||
451 (ui32Domains & PRCM_DOMAIN_VIMS));
452
453 //
454 // Assert the request to power off the right domains.
455 //
456 if(ui32Domains & PRCM_DOMAIN_RFCORE)
457 {
458 HWREG(PRCM_BASE +
459 PRCM_O_PDCTL0RFC) &= ~PRCM_PDCTL0RFC_ON;
460 HWREG(PRCM_BASE + PRCM_O_PDCTL1RFC) &= ~PRCM_PDCTL1RFC_ON;
461 }
462 if(ui32Domains & PRCM_DOMAIN_SERIAL)
463 {
464 HWREG(PRCM_BASE +
465 PRCM_O_PDCTL0SERIAL) &= ~PRCM_PDCTL0SERIAL_ON;
466 }
467 if(ui32Domains & PRCM_DOMAIN_PERIPH)
468 {
469 HWREG(PRCM_BASE +
470 PRCM_O_PDCTL0PERIPH) &= ~PRCM_PDCTL0PERIPH_ON;
471 }
472 if(ui32Domains & PRCM_DOMAIN_VIMS)
473 {
474 HWREG(PRCM_BASE + PRCM_O_PDCTL1VIMS) &=
475 ~PRCM_PDCTL1VIMS_ON;
476 }
477 if(ui32Domains & PRCM_DOMAIN_CPU)
478 {
479 HWREG(PRCM_BASE + PRCM_O_PDCTL1CPU) &= ~PRCM_PDCTL1CPU_ON;
480 }
481 }
482
483 //*****************************************************************************
484 //
485 //! Enables a peripheral in Run mode
486 //
487 //*****************************************************************************
488 void
PRCMPeripheralRunEnable(uint32_t ui32Peripheral)489 PRCMPeripheralRunEnable(uint32_t ui32Peripheral)
490 {
491 //
492 // Check the arguments.
493 //
494 ASSERT(PRCMPeripheralValid(ui32Peripheral));
495
496 //
497 // Enable module in Run Mode.
498 //
499 HWREG(PRCM_BASE + g_pui32RCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) |=
500 PRCM_PERIPH_MASKBIT(ui32Peripheral);
501 }
502
503 //*****************************************************************************
504 //
505 //! Disables a peripheral in Run mode
506 //
507 //*****************************************************************************
508 void
PRCMPeripheralRunDisable(uint32_t ui32Peripheral)509 PRCMPeripheralRunDisable(uint32_t ui32Peripheral)
510 {
511 //
512 // Check the arguments.
513 //
514 ASSERT(PRCMPeripheralValid(ui32Peripheral));
515
516 //
517 // Disable module in Run Mode.
518 //
519 HWREG(PRCM_BASE + g_pui32RCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) &=
520 ~PRCM_PERIPH_MASKBIT(ui32Peripheral);
521 }
522
523 //*****************************************************************************
524 //
525 //! Enables a peripheral in sleep mode
526 //
527 //*****************************************************************************
528 void
PRCMPeripheralSleepEnable(uint32_t ui32Peripheral)529 PRCMPeripheralSleepEnable(uint32_t ui32Peripheral)
530 {
531 //
532 // Check the arguments.
533 //
534 ASSERT(PRCMPeripheralValid(ui32Peripheral));
535
536 //
537 // Enable this peripheral in sleep mode.
538 //
539 HWREG(PRCM_BASE + g_pui32SCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) |=
540 PRCM_PERIPH_MASKBIT(ui32Peripheral);
541 }
542
543 //*****************************************************************************
544 //
545 //! Disables a peripheral in sleep mode
546 //
547 //*****************************************************************************
548 void
PRCMPeripheralSleepDisable(uint32_t ui32Peripheral)549 PRCMPeripheralSleepDisable(uint32_t ui32Peripheral)
550 {
551 //
552 // Check the arguments.
553 //
554 ASSERT(PRCMPeripheralValid(ui32Peripheral));
555
556 //
557 // Disable this peripheral in sleep mode
558 //
559 HWREG(PRCM_BASE + g_pui32SCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) &=
560 ~PRCM_PERIPH_MASKBIT(ui32Peripheral);
561 }
562
563 //*****************************************************************************
564 //
565 //! Enables a peripheral in deep-sleep mode
566 //
567 //*****************************************************************************
568 void
PRCMPeripheralDeepSleepEnable(uint32_t ui32Peripheral)569 PRCMPeripheralDeepSleepEnable(uint32_t ui32Peripheral)
570 {
571 //
572 // Check the arguments.
573 //
574 ASSERT(PRCMPeripheralValid(ui32Peripheral));
575
576 //
577 // Enable this peripheral in deep-sleep mode.
578 //
579 HWREG(PRCM_BASE + g_pui32DCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) |=
580 PRCM_PERIPH_MASKBIT(ui32Peripheral);
581 }
582
583 //*****************************************************************************
584 //
585 //! Disables a peripheral in deep-sleep mode
586 //
587 //*****************************************************************************
588 void
PRCMPeripheralDeepSleepDisable(uint32_t ui32Peripheral)589 PRCMPeripheralDeepSleepDisable(uint32_t ui32Peripheral)
590 {
591 //
592 // Check the arguments.
593 //
594 ASSERT(PRCMPeripheralValid(ui32Peripheral));
595
596 //
597 // Disable this peripheral in Deep Sleep mode.
598 //
599 HWREG(PRCM_BASE + g_pui32DCGCRegs[PRCM_PERIPH_INDEX(ui32Peripheral)]) &=
600 ~PRCM_PERIPH_MASKBIT(ui32Peripheral);
601 }
602
603 //*****************************************************************************
604 //
605 //! Get the status for a specific power domain
606 //
607 //*****************************************************************************
608 uint32_t
PRCMPowerDomainStatus(uint32_t ui32Domains)609 PRCMPowerDomainStatus(uint32_t ui32Domains)
610 {
611 bool bStatus;
612 uint32_t ui32StatusRegister0;
613 uint32_t ui32StatusRegister1;
614
615 //
616 // Check the arguments.
617 //
618 ASSERT((ui32Domains & (PRCM_DOMAIN_RFCORE |
619 PRCM_DOMAIN_SERIAL |
620 PRCM_DOMAIN_PERIPH)));
621
622 bStatus = true;
623 ui32StatusRegister0 = HWREG(PRCM_BASE + PRCM_O_PDSTAT0);
624 ui32StatusRegister1 = HWREG(PRCM_BASE + PRCM_O_PDSTAT1);
625
626 //
627 // Return the correct power status.
628 //
629 if(ui32Domains & PRCM_DOMAIN_RFCORE)
630 {
631 bStatus = bStatus &&
632 ((ui32StatusRegister0 & PRCM_PDSTAT0_RFC_ON) ||
633 (ui32StatusRegister1 & PRCM_PDSTAT1_RFC_ON));
634 }
635 if(ui32Domains & PRCM_DOMAIN_SERIAL)
636 {
637 bStatus = bStatus && (ui32StatusRegister0 & PRCM_PDSTAT0_SERIAL_ON);
638 }
639 if(ui32Domains & PRCM_DOMAIN_PERIPH)
640 {
641 bStatus = bStatus && (ui32StatusRegister0 & PRCM_PDSTAT0_PERIPH_ON);
642 }
643
644 //
645 // Return the status.
646 //
647 return (bStatus ? PRCM_DOMAIN_POWER_ON : PRCM_DOMAIN_POWER_OFF);
648 }
649
650 //*****************************************************************************
651 //
652 //! Put the processor into deep-sleep mode
653 //
654 //*****************************************************************************
655 void
PRCMDeepSleep(void)656 PRCMDeepSleep(void)
657 {
658 //
659 // Enable deep-sleep.
660 //
661 HWREG(NVIC_SYS_CTRL) |= NVIC_SYS_CTRL_SLEEPDEEP;
662
663 //
664 // Wait for an interrupt.
665 //
666 CPUwfi();
667
668 //
669 // Disable deep-sleep so that a future sleep will work correctly.
670 //
671 HWREG(NVIC_SYS_CTRL) &= ~(NVIC_SYS_CTRL_SLEEPDEEP);
672 }
673