2 * Copyright (c) 2015-2016, Texas Instruments Incorporated
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 /** ============================================================================
35 * @brief Power manager interface for the CC32XX
37 * The Power header file should be included in an application as follows:
39 * #include <ti/drivers/Power.h>
40 * #include <ti/drivers/power/PowerCC32XX.h>
43 * Refer to @ref Power.h for a complete description of APIs.
46 * This module defines the power resources, constraints, events, sleep
47 * states and transition latencies for CC32XX.
49 * A reference power policy is provided which can transition the MCU from the
50 * active state to one of two sleep states: LPDS or Sleep.
51 * The policy looks at the estimated idle time remaining, and the active
52 * constraints, and determine which sleep state to transition to. The
53 * policy will give first preference to choosing LPDS, but if that is not
54 * appropriate (e.g., not enough idle time), it will choose Sleep.
56 * ============================================================================
59 #ifndef ti_drivers_power_PowerCC32XX__include
60 #define ti_drivers_power_PowerCC32XX__include
63 #include <ti/drivers/utils/List.h>
64 #include <ti/drivers/Power.h>
66 /* driverlib header files */
67 #include <ti/devices/cc32xx/inc/hw_types.h>
68 #include <ti/devices/cc32xx/driverlib/rom.h>
69 #include <ti/devices/cc32xx/driverlib/rom_map.h>
70 #include <ti/devices/cc32xx/driverlib/pin.h>
76 /* latency values were measured with a logic analyzer, and rounded up */
78 /*! The latency to reserve for resuming from LPDS (usec) */
79 #define PowerCC32XX_RESUMETIMELPDS 2500
81 /*! The total latency to reserve for entry to and exit from LPDS (usec) */
82 #define PowerCC32XX_TOTALTIMELPDS 20000
84 /*! The total latency to reserve for entry to and exit from Shutdown (usec) */
85 #define PowerCC32XX_TOTALTIMESHUTDOWN 500000
88 #define PowerCC32XX_PERIPH_CAMERA 0
89 /*!< Resource ID: Camera */
91 #define PowerCC32XX_PERIPH_I2S 1
92 /*!< Resource ID: I2S */
94 #define PowerCC32XX_PERIPH_SDHOST 2
95 /*!< Resource ID: SDHost */
97 #define PowerCC32XX_PERIPH_GSPI 3
98 /*!< Resource ID: General Purpose SPI (GSPI) */
100 #define PowerCC32XX_PERIPH_LSPI 4
101 /*!< Resource ID: LSPI */
103 #define PowerCC32XX_PERIPH_UDMA 5
104 /*!< Resource ID: uDMA Controller */
106 #define PowerCC32XX_PERIPH_GPIOA0 6
107 /*!< Resource ID: General Purpose I/O Port A0 */
109 #define PowerCC32XX_PERIPH_GPIOA1 7
110 /*!< Resource ID: General Purpose I/O Port A1 */
112 #define PowerCC32XX_PERIPH_GPIOA2 8
113 /*!< Resource ID: General Purpose I/O Port A2 */
115 #define PowerCC32XX_PERIPH_GPIOA3 9
116 /*!< Resource ID: General Purpose I/O Port A3 */
118 #define PowerCC32XX_PERIPH_GPIOA4 10
119 /*!< Resource ID: General Purpose I/O Port A4 */
121 #define PowerCC32XX_PERIPH_WDT 11
122 /*!< Resource ID: Watchdog module */
124 #define PowerCC32XX_PERIPH_UARTA0 12
125 /*!< Resource ID: UART 0 */
127 #define PowerCC32XX_PERIPH_UARTA1 13
128 /*!< Resource ID: UART 1 */
130 #define PowerCC32XX_PERIPH_TIMERA0 14
131 /*!< Resource ID: General Purpose Timer A0 */
133 #define PowerCC32XX_PERIPH_TIMERA1 15
134 /*!< Resource ID: General Purpose Timer A1 */
136 #define PowerCC32XX_PERIPH_TIMERA2 16
137 /*!< Resource ID: General Purpose Timer A2 */
139 #define PowerCC32XX_PERIPH_TIMERA3 17
140 /*!< Resource ID: General Purpose Timer A3 */
142 #define PowerCC32XX_PERIPH_DTHE 18
143 /*!< Resource ID: Cryptography Accelerator (DTHE) */
145 #define PowerCC32XX_PERIPH_SSPI 19
146 /*!< Resource ID: Serial Flash SPI (SSPI) */
148 #define PowerCC32XX_PERIPH_I2CA0 20
149 /*!< Resource ID: I2C */
152 #define PowerCC32XX_NUMRESOURCES 21 /* Number of resources in database */
156 * Power constraints on the CC32XX device
158 #define PowerCC32XX_DISALLOW_LPDS 0
159 /*!< Constraint: Disallow entry to Low Power Deep Sleep (LPDS) */
161 #define PowerCC32XX_DISALLOW_SHUTDOWN 1
162 /*!< Constraint: Disallow entry to Shutdown */
165 #define PowerCC32XX_NUMCONSTRAINTS 2 /*!< number of constraints */
169 * Power events on the CC32XX device
171 * Each event must be a power of two, and the event IDs must be sequential
174 #define PowerCC32XX_ENTERING_LPDS 0x1
175 /*!< Power event: The device is entering the LPDS sleep state */
177 #define PowerCC32XX_ENTERING_SHUTDOWN 0x2
178 /*!< Power event: The device is entering the Shutdown state */
180 #define PowerCC32XX_AWAKE_LPDS 0x4
181 /*!< Power event: The device is waking from the LPDS sleep state */
184 #define PowerCC32XX_NUMEVENTS 3 /*!< number of events */
187 /* Power sleep states */
188 #define PowerCC32XX_LPDS 0x1 /*!< The LPDS sleep state */
191 /* Use by NVIC Register structure */
192 #define PowerCC32XX_numNVICSetEnableRegs 6
193 #define PowerCC32XX_numNVICIntPriority 49
197 /* Number of pins that can be parked in LPDS */
198 #define PowerCC32XX_NUMPINS 34
201 /*! @brief Used to specify parking of a pin during LPDS */
202 typedef struct PowerCC32XX_ParkInfo {
204 /*!< The pin to be parked */
206 /*!< The state to park the pin (an enumerated PowerCC32XX_ParkState) */
207 } PowerCC32XX_ParkInfo;
209 /*! @brief Power global configuration */
210 typedef struct PowerCC32XX_ConfigV1 {
211 /*! Initialization function for the power policy */
212 Power_PolicyInitFxn policyInitFxn;
213 /*! The power policy function */
214 Power_PolicyFxn policyFxn;
216 * @brief Hook function called before entering LPDS
218 * This function is called after any notifications are complete,
219 * and before any pins are parked, just before entry to LPDS.
221 void (*enterLPDSHookFxn)(void);
223 * @brief Hook function called when resuming from LPDS
225 * This function is called early in the wake sequence, before any
226 * notification functions are run.
228 void (*resumeLPDSHookFxn)(void);
229 /*! Determines whether to run the power policy function */
231 /*! Enable GPIO as a wakeup source for LPDS */
232 bool enableGPIOWakeupLPDS;
233 /*! Enable GPIO as a wakeup source for shutdown */
234 bool enableGPIOWakeupShutdown;
235 /*! Enable Network activity as a wakeup source for LPDS */
236 bool enableNetworkWakeupLPDS;
238 * @brief The GPIO source for wakeup from LPDS
240 * Only one GPIO {2,4,11,13,17,24,26} can be specified as a wake source
241 * for LPDS. The GPIO must be specified as one of the following (as
242 * defined in driverlib/prcm.h): PRCM_LPDS_GPIO2, PRCM_LPDS_GPIO4,
243 * PRCM_LPDS_GPIO11, PRCM_LPDS_GPIO13, PRCM_LPDS_GPIO17, PRCM_LPDS_GPIO24,
246 uint32_t wakeupGPIOSourceLPDS;
248 * @brief The GPIO trigger type for wakeup from LPDS
250 * Value can be one of the following (defined in driverlib/prcm.h):
251 * PRCM_LPDS_LOW_LEVEL, PRCM_LPDS_HIGH_LEVEL,
252 * PRCM_LPDS_FALL_EDGE, PRCM_LPDS_RISE_EDGE
254 uint32_t wakeupGPIOTypeLPDS;
256 * @brief Function to be called when the configured GPIO triggers wakeup
259 * During LPDS the internal GPIO module is powered off, and special
260 * periphery logic is used instead to detect the trigger and wake the
261 * device. No GPIO interrupt service routine will be triggered in this
262 * case (even if an ISR is configured, and used normally to detect GPIO
263 * interrupts when not in LPDS). This function can be used in lieu of a
264 * GPIO ISR, to take specific action upon LPDS wakeup.
266 * A value of NULL indicates no GPIO wakeup function will be called.
268 * An argument for this wakeup function can be specified via
269 * wakeupGPIOFxnLPDSArg.
271 * Note that this wakeup function will be called as one of the last steps
272 * in Power_sleep(), after all notifications have been sent out, and after
273 * pins have been restored to their previous (non-parked) states.
275 void (*wakeupGPIOFxnLPDS)(uint_least8_t argument);
277 * @brief The argument to be passed to wakeupGPIOFxnLPDS()
279 uint_least8_t wakeupGPIOFxnLPDSArg;
281 * @brief The GPIO sources for wakeup from shutdown
283 * Only one GPIO {2,4,11,13,17,24,26} can be specified as a wake source
284 * for Shutdown. The GPIO must be specified as one of the following (as
285 * defined in driverlib/prcm.h): PRCM_HIB_GPIO2, PRCM_HIB_GPIO4,
286 * PRCM_HIB_GPIO11, PRCM_HIB_GPIO13, PRCM_HIB_GPIO17, PRCM_HIB_GPIO24,
289 uint32_t wakeupGPIOSourceShutdown;
291 * @brief The GPIO trigger type for wakeup from shutdown
293 * Value can be one of the following (defined in driverlib/prcm.h):
294 * PRCM_HIB_LOW_LEVEL, PRCM_HIB_HIGH_LEVEL,
295 * PRCM_HIB_FALL_EDGE, PRCM_HIB_RISE_EDGE
297 uint32_t wakeupGPIOTypeShutdown;
299 * @brief SRAM retention mask for LPDS
301 * Value can be a mask of the following (defined in driverlib/prcm.h):
302 * PRCM_SRAM_COL_1, PRCM_SRAM_COL_2, PRCM_SRAM_COL_3,
305 uint32_t ramRetentionMaskLPDS;
307 * @brief Keep debug interface active during LPDS
309 * This Boolean controls whether the debug interface will be left active
310 * when LPDS is entered. For best power savings this flag should be set
311 * to false. Setting the flag to true will enable better debug
312 * capability, but will prevent full LPDS, and will result in increased
315 bool keepDebugActiveDuringLPDS;
317 * @brief IO retention mask for Shutdown
319 * Value can be a mask of the following (defined in driverlib/prcm.h):
320 * PRCM_IO_RET_GRP_0, PRCM_IO_RET_GRP_1, PRCM_IO_RET_GRP_2
323 uint32_t ioRetentionShutdown;
325 * @brief Pointer to an array of pins to be parked during LPDS
327 * A value of NULL will disable parking of any pins during LPDS
329 PowerCC32XX_ParkInfo * pinParkDefs;
331 * @brief Number of pins to be parked during LPDS
334 } PowerCC32XX_ConfigV1;
338 * NVIC registers that need to be saved before entering LPDS.
340 typedef struct PowerCC32XX_NVICRegisters {
341 uint32_t vectorTable;
343 uint32_t intCtrlState;
351 uint32_t systickCtrl;
352 uint32_t systickReload;
353 uint32_t systickCalib;
354 uint32_t intSetEn[PowerCC32XX_numNVICSetEnableRegs];
355 uint32_t intPriority[PowerCC32XX_numNVICIntPriority];
356 } PowerCC32XX_NVICRegisters;
361 * MCU core registers that need to be save before entering LPDS.
363 typedef struct PowerCC32XX_MCURegisters {
371 } PowerCC32XX_MCURegisters;
376 * Structure of context registers to save before entering LPDS.
378 typedef struct PowerCC32XX_SaveRegisters {
379 PowerCC32XX_MCURegisters m4Regs;
380 PowerCC32XX_NVICRegisters nvicRegs;
381 } PowerCC32XX_SaveRegisters;
384 /*! @brief Enumeration of states a pin can be parked in */
386 /*! No pull resistor, leave pin in a HIZ state */
387 PowerCC32XX_NO_PULL_HIZ = PIN_TYPE_STD,
388 /*! Pull-up resistor for standard pin type */
389 PowerCC32XX_WEAK_PULL_UP_STD = PIN_TYPE_STD_PU,
390 /*! Pull-down resistor for standard pin type */
391 PowerCC32XX_WEAK_PULL_DOWN_STD = PIN_TYPE_STD_PD,
392 /*! Pull-up resistor for open drain pin type */
393 PowerCC32XX_WEAK_PULL_UP_OPENDRAIN = PIN_TYPE_OD_PU,
394 /*! Pull-down resistor for open drain pin type */
395 PowerCC32XX_WEAK_PULL_DOWN_OPENDRAIN = PIN_TYPE_OD_PD,
396 /*! Drive pin to a low logic state */
397 PowerCC32XX_DRIVE_LOW,
398 /*! Drive pin to a high logic state */
399 PowerCC32XX_DRIVE_HIGH,
400 /*! Take no action; do not park the pin */
401 PowerCC32XX_DONT_PARK
402 } PowerCC32XX_ParkState;
404 /*! @brief Enumeration of pins that can be parked */
407 PowerCC32XX_PIN01 = PIN_01,
409 PowerCC32XX_PIN02 = PIN_02,
411 PowerCC32XX_PIN03 = PIN_03,
413 PowerCC32XX_PIN04 = PIN_04,
415 PowerCC32XX_PIN05 = PIN_05,
417 PowerCC32XX_PIN06 = PIN_06,
419 PowerCC32XX_PIN07 = PIN_07,
421 PowerCC32XX_PIN08 = PIN_08,
423 PowerCC32XX_PIN11 = PIN_11,
425 PowerCC32XX_PIN12 = PIN_12,
427 PowerCC32XX_PIN13 = PIN_13,
429 PowerCC32XX_PIN14 = PIN_14,
431 PowerCC32XX_PIN15 = PIN_15,
433 PowerCC32XX_PIN16 = PIN_16,
435 PowerCC32XX_PIN17 = PIN_17,
437 PowerCC32XX_PIN18 = PIN_18,
439 PowerCC32XX_PIN19 = PIN_19,
441 PowerCC32XX_PIN20 = PIN_20,
443 PowerCC32XX_PIN21 = PIN_21,
445 PowerCC32XX_PIN29 = 0x1C,
447 PowerCC32XX_PIN30 = 0x1D,
449 PowerCC32XX_PIN45 = PIN_45,
451 PowerCC32XX_PIN50 = PIN_50,
453 PowerCC32XX_PIN52 = PIN_52,
455 PowerCC32XX_PIN53 = PIN_53,
457 PowerCC32XX_PIN55 = PIN_55,
459 PowerCC32XX_PIN57 = PIN_57,
461 PowerCC32XX_PIN58 = PIN_58,
463 PowerCC32XX_PIN59 = PIN_59,
465 PowerCC32XX_PIN60 = PIN_60,
467 PowerCC32XX_PIN61 = PIN_61,
469 PowerCC32XX_PIN62 = PIN_62,
471 PowerCC32XX_PIN63 = PIN_63,
473 PowerCC32XX_PIN64 = PIN_64
477 * @brief Specify the wakeup sources for LPDS and Shutdown
479 * The wakeup sources for LPDS and Shutdown can be dynamically changed
480 * at runtime, via PowerCC32XX_configureWakeup(). The application
481 * should fill a structure of this type, and pass it as the parameter
482 * to PowerCC32XX_configureWakeup() to specify the new wakeup settings.
484 typedef struct PowerCC32XX_Wakeup {
485 /*! Enable GPIO as a wakeup source for LPDS */
486 bool enableGPIOWakeupLPDS;
487 /*! Enable GPIO as a wakeup source for shutdown */
488 bool enableGPIOWakeupShutdown;
489 /*! Enable Network activity as a wakeup source for LPDS */
490 bool enableNetworkWakeupLPDS;
492 * @brief The GPIO source for wakeup from LPDS
494 * Only one GPIO {2,4,11,13,17,24,26} can be specified as a wake source
495 * for LPDS. The GPIO must be specified as one of the following (as
496 * defined in driverlib/prcm.h): PRCM_LPDS_GPIO2, PRCM_LPDS_GPIO4,
497 * PRCM_LPDS_GPIO11, PRCM_LPDS_GPIO13, PRCM_LPDS_GPIO17, PRCM_LPDS_GPIO24,
500 uint32_t wakeupGPIOSourceLPDS;
502 * @brief The GPIO trigger type for wakeup from LPDS
504 * Value can be one of the following (defined in driverlib/prcm.h):
505 * PRCM_LPDS_LOW_LEVEL, PRCM_LPDS_HIGH_LEVEL,
506 * PRCM_LPDS_FALL_EDGE, PRCM_LPDS_RISE_EDGE
508 uint32_t wakeupGPIOTypeLPDS;
510 * @brief Function to be called when the configured GPIO triggers wakeup
513 * During LPDS the internal GPIO module is powered off, and special
514 * periphery logic is used instead to detect the trigger and wake the
515 * device. No GPIO interrupt service routine will be triggered in this
516 * case (even if an ISR is configured, and used normally to detect GPIO
517 * interrupts when not in LPDS). This function can be used in lieu of a
518 * GPIO ISR, to take specific action upon LPDS wakeup.
520 * A value of NULL indicates no GPIO wakeup function will be called.
522 * An argument for this wakeup function can be specified via
523 * wakeupGPIOFxnLPDSArg.
525 * Note that this wakeup function will be called as one of the last steps
526 * in Power_sleep(), after all notifications have been sent out, and after
527 * pins have been restored to their previous (non-parked) states.
529 void (*wakeupGPIOFxnLPDS)(uint_least8_t argument);
531 * @brief The argument to be passed to wakeupGPIOFxnLPDS()
533 uint_least8_t wakeupGPIOFxnLPDSArg;
535 * @brief The GPIO sources for wakeup from shutdown
537 * Only one GPIO {2,4,11,13,17,24,26} can be specified as a wake source
538 * for Shutdown. The GPIO must be specified as one of the following (as
539 * defined in driverlib/prcm.h): PRCM_HIB_GPIO2, PRCM_HIB_GPIO4,
540 * PRCM_HIB_GPIO11, PRCM_HIB_GPIO13, PRCM_HIB_GPIO17, PRCM_HIB_GPIO24,
543 uint32_t wakeupGPIOSourceShutdown;
545 * @brief The GPIO trigger type for wakeup from shutdown
547 * Value can be one of the following (defined in driverlib/prcm.h):
548 * PRCM_HIB_LOW_LEVEL, PRCM_HIB_HIGH_LEVEL,
549 * PRCM_HIB_FALL_EDGE, PRCM_HIB_RISE_EDGE
551 uint32_t wakeupGPIOTypeShutdown;
552 } PowerCC32XX_Wakeup;
556 * Internal structure defining Power module state.
558 typedef struct PowerCC32XX_ModuleState {
559 List_List notifyList;
560 uint32_t constraintMask;
562 uint16_t dbRecords[PowerCC32XX_NUMRESOURCES];
565 uint8_t refCount[PowerCC32XX_NUMRESOURCES];
566 uint8_t constraintCounts[PowerCC32XX_NUMCONSTRAINTS];
567 Power_PolicyFxn policyFxn;
568 uint32_t pinType[PowerCC32XX_NUMPINS];
569 uint16_t pinDir[PowerCC32XX_NUMPINS];
570 uint8_t pinMode[PowerCC32XX_NUMPINS];
571 uint16_t stateAntPin29;
572 uint16_t stateAntPin30;
573 uint32_t pinLockMask;
574 PowerCC32XX_Wakeup wakeupConfig;
575 } PowerCC32XX_ModuleState;
579 * @brief Function configures wakeup for LPDS and shutdown
581 * This function allows the app to configure the GPIO source and
582 * type for waking up from LPDS and shutdown and the network host
583 * as a wakeup source for LPDS. This overwrites any previous
586 * @param wakeup Settings applied to wakeup configuration
588 void PowerCC32XX_configureWakeup(PowerCC32XX_Wakeup *wakeup);
590 /*! OS-specific power policy initialization function */
591 void PowerCC32XX_initPolicy(void);
594 * @brief Function to get wakeup configuration settings
596 * This function allows an app to query the current LPDS and shutdown
597 * wakeup configuration settings.
599 * @param wakeup A PowerCC32XX_Wakeup structure to be written into
601 void PowerCC32XX_getWakeup(PowerCC32XX_Wakeup *wakeup);
603 /*! CC32XX-specific function to dynamically set the LPDS park state for a pin */
604 void PowerCC32XX_setParkState(PowerCC32XX_Pin pin, uint32_t level);
607 * @brief Function to disable IO retention and unlock pin groups following
608 * exit from Shutdown.
610 * PowerCC32XX_ConfigV1.ioRetentionShutdown can be used to specify locking and
611 * retention of pin groups during Shutdown. Upon exit from Shutdown, and
612 * when appropriate, an application can call this function, to
613 * correspondingly disable IO retention, and unlock the specified pin groups.
615 * @param groupFlags A logical OR of one or more of the following
616 * flags (defined in driverlib/prcm.h):
617 * PRCM_IO_RET_GRP_0 - all pins except sFlash and JTAG interface
618 * PRCM_IO_RET_GRP_1 - sFlash interface pins 11,12,13,14
619 * PRCM_IO_RET_GRP_2 - JTAG TDI and TDO interface pins 16,17
620 * PRCM_IO_RET_GRP_3 - JTAG TCK and TMS interface pins 19,20
622 void PowerCC32XX_disableIORetention(unsigned long groupFlags);
624 /*! OS-specific power policy function */
625 void PowerCC32XX_sleepPolicy(void);
628 #define Power_getPerformanceLevel(void) 0
629 #define Power_setPerformanceLevel(level) Power_EFAIL
636 #endif /* ti_drivers_power_PowerCC32XX__include */