pmu_8xx.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * @brief LPC8xx PMU chip driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __PMU_8XX_H_
  32. #define __PMU_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup PMU_8XX CHIP: LPC8xx PMU driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief LPC8xx Power Management Unit register block structure
  42. */
  43. typedef struct {
  44. __IO uint32_t PCON; /*!< Offset: 0x000 Power control Register (R/W) */
  45. __IO uint32_t GPREG[4]; /*!< Offset: 0x004 General purpose Registers 0..3 (R/W) */
  46. __IO uint32_t DPDCTRL; /*!< Offset: 0x014 Deep power-down control register (R/W) */
  47. } LPC_PMU_T;
  48. /* Reserved bits masks for registers */
  49. #define PMU_PCON_RESERVED ((0xf<<4)|(0x6<<8)|0xfffff000)
  50. #define PMU_DPDCTRL_RESERVED (~0xf)
  51. /**
  52. * @brief LPC8xx low power mode type definitions
  53. */
  54. typedef enum CHIP_PMU_MCUPOWER {
  55. PMU_MCU_SLEEP = 0, /*!< Sleep mode */
  56. PMU_MCU_DEEP_SLEEP, /*!< Deep Sleep mode */
  57. PMU_MCU_POWER_DOWN, /*!< Power down mode */
  58. PMU_MCU_DEEP_PWRDOWN /*!< Deep power down mode */
  59. } CHIP_PMU_MCUPOWER_T;
  60. /**
  61. * PMU PCON register bit fields & masks
  62. */
  63. #define PMU_PCON_PM_SLEEP (0x0) /*!< ARM WFI enter sleep mode */
  64. #define PMU_PCON_PM_DEEPSLEEP (0x1) /*!< ARM WFI enter Deep-sleep mode */
  65. #define PMU_PCON_PM_POWERDOWN (0x2) /*!< ARM WFI enter Power-down mode */
  66. #define PMU_PCON_PM_DEEPPOWERDOWN (0x3) /*!< ARM WFI enter Deep Power-down mode */
  67. #define PMU_PCON_NODPD (1 << 3) /*!< Disable deep power-down mode */
  68. #define PMU_PCON_SLEEPFLAG (1 << 8) /*!< Sleep mode flag */
  69. #define PMU_PCON_DPDFLAG (1 << 11) /*!< Deep power-down flag */
  70. /**
  71. * PMU DPDCTRL register bit fields & masks
  72. */
  73. #define PMU_DPDCTRL_WAKEUPPHYS (1 << 0) /** Enable wake-up pin hysteresis */
  74. #define PMU_DPDCTRL_WAKEPAD (1 << 1) /** Disable the Wake-up */
  75. #define PMU_DPDCTRL_LPOSCEN (1 << 2) /** Enable the low-power oscillator (10 khz self wk) */
  76. #define PMU_DPDCTRL_LPOSCDPDEN (1 << 3) /** Enable the low-power oscillator in deep power-down*/
  77. /**
  78. * @brief Write a value to a GPREG register
  79. * @param pPMU : Pointer to PMU register block
  80. * @param regIndex : Register index to write to, must be 0..3
  81. * @param value : Value to write
  82. * @return None
  83. */
  84. STATIC INLINE void Chip_PMU_WriteGPREG(LPC_PMU_T *pPMU, uint8_t regIndex, uint32_t value)
  85. {
  86. pPMU->GPREG[regIndex] = value;
  87. }
  88. /**
  89. * @brief Read a value to a GPREG register
  90. * @param pPMU : Pointer to PMU register block
  91. * @param regIndex : Register index to read from, must be 0..3
  92. * @return Value read from the GPREG register
  93. */
  94. STATIC INLINE uint32_t Chip_PMU_ReadGPREG(LPC_PMU_T *pPMU, uint8_t regIndex)
  95. {
  96. return pPMU->GPREG[regIndex];
  97. }
  98. /**
  99. * @brief Enter MCU Sleep mode
  100. * @param pPMU : Pointer to PMU register block
  101. * @return None
  102. * @note The sleep mode affects the ARM Cortex-M0+ core only. Peripherals
  103. * and memories are active.
  104. */
  105. void Chip_PMU_SleepState(LPC_PMU_T *pPMU);
  106. /**
  107. * @brief Enter MCU Deep Sleep mode
  108. * @param pPMU : Pointer to PMU register block
  109. * @return None
  110. * @note In Deep-sleep mode, the peripherals receive no internal clocks.
  111. * The flash is in stand-by mode. The SRAM memory and all peripheral registers
  112. * as well as the processor maintain their internal states. The WWDT, WKT,
  113. * and BOD can remain active to wake up the system on an interrupt.
  114. */
  115. void Chip_PMU_DeepSleepState(LPC_PMU_T *pPMU);
  116. /**
  117. * @brief Enter MCU Power down mode
  118. * @param pPMU : Pointer to PMU register block
  119. * @return None
  120. * @note In Power-down mode, the peripherals receive no internal clocks.
  121. * The internal SRAM memory and all peripheral registers as well as the
  122. * processor maintain their internal states. The flash memory is powered
  123. * down. The WWDT, WKT, and BOD can remain active to wake up the system
  124. * on an interrupt.
  125. */
  126. void Chip_PMU_PowerDownState(LPC_PMU_T *pPMU);
  127. /**
  128. * @brief Enter MCU Deep Power down mode
  129. * @param pPMU : Pointer to PMU register block
  130. * @return None
  131. * @note For maximal power savings, the entire system is shut down
  132. * except for the general purpose registers in the PMU and the self
  133. * wake-up timer. Only the general purpose registers in the PMU maintain
  134. * their internal states. The part can wake up on a pulse on the WAKEUP
  135. * pin or when the self wake-up timer times out. On wake-up, the part
  136. * reboots.
  137. */
  138. void Chip_PMU_DeepPowerDownState(LPC_PMU_T *pPMU);
  139. /**
  140. * @brief Place the MCU in a low power state
  141. * @param pPMU : Pointer to PMU register block
  142. * @param SleepMode : Sleep mode
  143. * @return None
  144. */
  145. void Chip_PMU_Sleep(LPC_PMU_T *pPMU, CHIP_PMU_MCUPOWER_T SleepMode);
  146. /**
  147. * @brief Disables deep power-down mode
  148. * @param pPMU : Pointer to PMU register block
  149. * @return None
  150. * @note Calling this functions prevents entry to Deep power-down
  151. * mode. Once set, this can only be cleared by power-on reset.
  152. */
  153. STATIC INLINE void Chip_PMU_DisableDeepPowerDown(LPC_PMU_T *pPMU)
  154. {
  155. pPMU->PCON = PMU_PCON_NODPD | (pPMU->PCON & ~PMU_PCON_RESERVED);
  156. }
  157. /**
  158. * @brief Returns sleep/power-down flags
  159. * @param pPMU : Pointer to PMU register block
  160. * @return Or'ed values of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG
  161. * @note These indicate that the PMU is setup for entry into a low
  162. * power state on the next WFI() instruction.
  163. */
  164. STATIC INLINE uint32_t Chip_PMU_GetSleepFlags(LPC_PMU_T *pPMU)
  165. {
  166. return (pPMU->PCON & (PMU_PCON_SLEEPFLAG | PMU_PCON_DPDFLAG));
  167. }
  168. /**
  169. * @brief Clears sleep/power-down flags
  170. * @param pPMU : Pointer to PMU register block
  171. * @param flags : Or'ed value of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG
  172. * @return Nothing
  173. * @note Use this function to clear a low power state prior to calling
  174. * WFI().
  175. */
  176. STATIC INLINE void Chip_PMU_ClearSleepFlags(LPC_PMU_T *pPMU, uint32_t flags)
  177. {
  178. pPMU->PCON |= (flags & (~PMU_PCON_RESERVED));
  179. }
  180. /**
  181. * @brief Sets deep power-down functions
  182. * @param pPMU : Pointer to PMU register block
  183. * @param flags : Or'ed value of PMU_DPDCTRL_* values
  184. * @return Nothing
  185. * @note Some of these functions may need to be set prior to going
  186. * into a low power mode. Note that some calls to this function enable
  187. * functions while others disable it based on the PMU_DPDCTRL_*
  188. * definitions.
  189. */
  190. STATIC INLINE void Chip_PMU_SetPowerDownControl(LPC_PMU_T *pPMU, uint32_t flags)
  191. {
  192. pPMU->DPDCTRL = flags | (pPMU->DPDCTRL & ~PMU_DPDCTRL_RESERVED);
  193. }
  194. /**
  195. * @brief Cleats deep power-down functions
  196. * @param pPMU : Pointer to PMU register block
  197. * @param flags : Or'ed value of PMU_DPDCTRL_* values
  198. * @return Nothing
  199. * @note Some of these functions may need to be cleared prior to going
  200. * into a low power mode. Note that some calls to this function enable
  201. * functions while others disable it based on the PMU_DPDCTRL_*
  202. * definitions.
  203. */
  204. STATIC INLINE void Chip_PMU_ClearPowerDownControl(LPC_PMU_T *pPMU, uint32_t flags)
  205. {
  206. pPMU->DPDCTRL &= ~(flags | PMU_DPDCTRL_RESERVED);
  207. }
  208. /**
  209. * @}
  210. */
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* __PMU_8XX_H_ */