a

Dependencies:   HMC5883 MPL3115A MPU605 MU2Class SDFileSystem mbed

Committer:
pyonta2017
Date:
Sat Sep 09 23:18:12 2017 +0000
Revision:
0:ac7a5495d95c
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyonta2017 0:ac7a5495d95c 1 /* mbed PowerControl Library
pyonta2017 0:ac7a5495d95c 2 * Copyright (c) 2010 Michael Wei
pyonta2017 0:ac7a5495d95c 3 */
pyonta2017 0:ac7a5495d95c 4
pyonta2017 0:ac7a5495d95c 5 #ifndef MBED_POWERCONTROL_H
pyonta2017 0:ac7a5495d95c 6 #define MBED_POWERCONTROL_H
pyonta2017 0:ac7a5495d95c 7
pyonta2017 0:ac7a5495d95c 8 //shouldn't have to include, but fixes weird problems with defines
pyonta2017 0:ac7a5495d95c 9 //#include "LPC1768.h"
pyonta2017 0:ac7a5495d95c 10
pyonta2017 0:ac7a5495d95c 11 //System Control Register
pyonta2017 0:ac7a5495d95c 12 // bit 0: Reserved
pyonta2017 0:ac7a5495d95c 13 // bit 1: Sleep on Exit
pyonta2017 0:ac7a5495d95c 14 #define LPC1768_SCR_SLEEPONEXIT 0x2
pyonta2017 0:ac7a5495d95c 15 // bit 2: Deep Sleep
pyonta2017 0:ac7a5495d95c 16 #define LPC1768_SCR_SLEEPDEEP 0x4
pyonta2017 0:ac7a5495d95c 17 // bit 3: Resereved
pyonta2017 0:ac7a5495d95c 18 // bit 4: Send on Pending
pyonta2017 0:ac7a5495d95c 19 #define LPC1768_SCR_SEVONPEND 0x10
pyonta2017 0:ac7a5495d95c 20 // bit 5-31: Reserved
pyonta2017 0:ac7a5495d95c 21
pyonta2017 0:ac7a5495d95c 22 //Power Control Register
pyonta2017 0:ac7a5495d95c 23 // bit 0: Power mode control bit 0 (power-down mode)
pyonta2017 0:ac7a5495d95c 24 #define LPC1768_PCON_PM0 0x1
pyonta2017 0:ac7a5495d95c 25 // bit 1: Power mode control bit 1 (deep power-down mode)
pyonta2017 0:ac7a5495d95c 26 #define LPC1768_PCON_PM1 0x2
pyonta2017 0:ac7a5495d95c 27 // bit 2: Brown-out reduced power mode
pyonta2017 0:ac7a5495d95c 28 #define LPC1768_PCON_BODRPM 0x4
pyonta2017 0:ac7a5495d95c 29 // bit 3: Brown-out global disable
pyonta2017 0:ac7a5495d95c 30 #define LPC1768_PCON_BOGD 0x8
pyonta2017 0:ac7a5495d95c 31 // bit 4: Brown-out reset disable
pyonta2017 0:ac7a5495d95c 32 #define LPC1768_PCON_BORD 0x10
pyonta2017 0:ac7a5495d95c 33 // bit 5-7 : Reserved
pyonta2017 0:ac7a5495d95c 34 // bit 8: Sleep Mode Entry Flag
pyonta2017 0:ac7a5495d95c 35 #define LPC1768_PCON_SMFLAG 0x100
pyonta2017 0:ac7a5495d95c 36 // bit 9: Deep Sleep Entry Flag
pyonta2017 0:ac7a5495d95c 37 #define LPC1768_PCON_DSFLAG 0x200
pyonta2017 0:ac7a5495d95c 38 // bit 10: Power Down Entry Flag
pyonta2017 0:ac7a5495d95c 39 #define LPC1768_PCON_PDFLAG 0x400
pyonta2017 0:ac7a5495d95c 40 // bit 11: Deep Power Down Entry Flag
pyonta2017 0:ac7a5495d95c 41 #define LPC1768_PCON_DPDFLAG 0x800
pyonta2017 0:ac7a5495d95c 42 // bit 12-31: Reserved
pyonta2017 0:ac7a5495d95c 43
pyonta2017 0:ac7a5495d95c 44 //"Sleep Mode" (WFI).
pyonta2017 0:ac7a5495d95c 45 inline void Sleep(void)
pyonta2017 0:ac7a5495d95c 46 {
pyonta2017 0:ac7a5495d95c 47 __WFI();
pyonta2017 0:ac7a5495d95c 48 }
pyonta2017 0:ac7a5495d95c 49
pyonta2017 0:ac7a5495d95c 50 //"Deep Sleep" Mode
pyonta2017 0:ac7a5495d95c 51 inline void DeepSleep(void)
pyonta2017 0:ac7a5495d95c 52 {
pyonta2017 0:ac7a5495d95c 53 SCB->SCR |= LPC1768_SCR_SLEEPDEEP;
pyonta2017 0:ac7a5495d95c 54 __WFI();
pyonta2017 0:ac7a5495d95c 55 }
pyonta2017 0:ac7a5495d95c 56
pyonta2017 0:ac7a5495d95c 57 //"Power-Down" Mode
pyonta2017 0:ac7a5495d95c 58 inline void PowerDown(void)
pyonta2017 0:ac7a5495d95c 59 {
pyonta2017 0:ac7a5495d95c 60 SCB->SCR |= LPC1768_SCR_SLEEPDEEP;
pyonta2017 0:ac7a5495d95c 61 LPC_SC->PCON &= ~LPC1768_PCON_PM1;
pyonta2017 0:ac7a5495d95c 62 LPC_SC->PCON |= LPC1768_PCON_PM0;
pyonta2017 0:ac7a5495d95c 63 __WFI();
pyonta2017 0:ac7a5495d95c 64 //reset back to normal
pyonta2017 0:ac7a5495d95c 65 LPC_SC->PCON &= ~(LPC1768_PCON_PM1 | LPC1768_PCON_PM0);
pyonta2017 0:ac7a5495d95c 66 }
pyonta2017 0:ac7a5495d95c 67
pyonta2017 0:ac7a5495d95c 68 //"Deep Power-Down" Mode
pyonta2017 0:ac7a5495d95c 69 inline void DeepPowerDown(void)
pyonta2017 0:ac7a5495d95c 70 {
pyonta2017 0:ac7a5495d95c 71 SCB->SCR |= LPC1768_SCR_SLEEPDEEP;
pyonta2017 0:ac7a5495d95c 72 LPC_SC->PCON |= LPC1768_PCON_PM1 | LPC1768_PCON_PM0;
pyonta2017 0:ac7a5495d95c 73 __WFI();
pyonta2017 0:ac7a5495d95c 74 //reset back to normal
pyonta2017 0:ac7a5495d95c 75 LPC_SC->PCON &= ~(LPC1768_PCON_PM1 | LPC1768_PCON_PM0);
pyonta2017 0:ac7a5495d95c 76 }
pyonta2017 0:ac7a5495d95c 77
pyonta2017 0:ac7a5495d95c 78 //shut down BOD during power-down/deep sleep
pyonta2017 0:ac7a5495d95c 79 inline void BrownOut_ReducedPowerMode_Enable(void)
pyonta2017 0:ac7a5495d95c 80 {
pyonta2017 0:ac7a5495d95c 81 LPC_SC->PCON |= LPC1768_PCON_BODRPM;
pyonta2017 0:ac7a5495d95c 82 }
pyonta2017 0:ac7a5495d95c 83
pyonta2017 0:ac7a5495d95c 84 //turn on BOD during power-down/deep sleep
pyonta2017 0:ac7a5495d95c 85 inline void BrownOut_ReducedPowerMode_Disable(void)
pyonta2017 0:ac7a5495d95c 86 {
pyonta2017 0:ac7a5495d95c 87 LPC_SC->PCON &= ~LPC1768_PCON_BODRPM;
pyonta2017 0:ac7a5495d95c 88 }
pyonta2017 0:ac7a5495d95c 89
pyonta2017 0:ac7a5495d95c 90 //turn off brown out circutry
pyonta2017 0:ac7a5495d95c 91 inline void BrownOut_Global_Disable(void)
pyonta2017 0:ac7a5495d95c 92 {
pyonta2017 0:ac7a5495d95c 93 LPC_SC->PCON |= LPC1768_PCON_BOGD;
pyonta2017 0:ac7a5495d95c 94 }
pyonta2017 0:ac7a5495d95c 95
pyonta2017 0:ac7a5495d95c 96 //turn on brown out circutry
pyonta2017 0:ac7a5495d95c 97 inline void BrownOut_Global_Enable(void)
pyonta2017 0:ac7a5495d95c 98 {
pyonta2017 0:ac7a5495d95c 99 LPC_SC->PCON &= !LPC1768_PCON_BOGD;
pyonta2017 0:ac7a5495d95c 100 }
pyonta2017 0:ac7a5495d95c 101
pyonta2017 0:ac7a5495d95c 102 //turn off brown out reset circutry
pyonta2017 0:ac7a5495d95c 103 inline void BrownOut_Reset_Disable(void)
pyonta2017 0:ac7a5495d95c 104 {
pyonta2017 0:ac7a5495d95c 105 LPC_SC->PCON |= LPC1768_PCON_BORD;
pyonta2017 0:ac7a5495d95c 106 }
pyonta2017 0:ac7a5495d95c 107
pyonta2017 0:ac7a5495d95c 108 //turn on brown outreset circutry
pyonta2017 0:ac7a5495d95c 109 inline void BrownOut_Reset_Enable(void)
pyonta2017 0:ac7a5495d95c 110 {
pyonta2017 0:ac7a5495d95c 111 LPC_SC->PCON &= ~LPC1768_PCON_BORD;
pyonta2017 0:ac7a5495d95c 112 }
pyonta2017 0:ac7a5495d95c 113 //Peripheral Control Register
pyonta2017 0:ac7a5495d95c 114 // bit 0: Reserved
pyonta2017 0:ac7a5495d95c 115 // bit 1: PCTIM0: Timer/Counter 0 power/clock enable
pyonta2017 0:ac7a5495d95c 116 #define LPC1768_PCONP_PCTIM0 0x2
pyonta2017 0:ac7a5495d95c 117 // bit 2: PCTIM1: Timer/Counter 1 power/clock enable
pyonta2017 0:ac7a5495d95c 118 #define LPC1768_PCONP_PCTIM1 0x4
pyonta2017 0:ac7a5495d95c 119 // bit 3: PCUART0: UART 0 power/clock enable
pyonta2017 0:ac7a5495d95c 120 #define LPC1768_PCONP_PCUART0 0x8
pyonta2017 0:ac7a5495d95c 121 // bit 4: PCUART1: UART 1 power/clock enable
pyonta2017 0:ac7a5495d95c 122 #define LPC1768_PCONP_PCUART1 0x10
pyonta2017 0:ac7a5495d95c 123 // bit 5: Reserved
pyonta2017 0:ac7a5495d95c 124 // bit 6: PCPWM1: PWM 1 power/clock enable
pyonta2017 0:ac7a5495d95c 125 #define LPC1768_PCONP_PCPWM1 0x40
pyonta2017 0:ac7a5495d95c 126 // bit 7: PCI2C0: I2C interface 0 power/clock enable
pyonta2017 0:ac7a5495d95c 127 #define LPC1768_PCONP_PCI2C0 0x80
pyonta2017 0:ac7a5495d95c 128 // bit 8: PCSPI: SPI interface power/clock enable
pyonta2017 0:ac7a5495d95c 129 #define LPC1768_PCONP_PCSPI 0x100
pyonta2017 0:ac7a5495d95c 130 // bit 9: PCRTC: RTC power/clock enable
pyonta2017 0:ac7a5495d95c 131 #define LPC1768_PCONP_PCRTC 0x200
pyonta2017 0:ac7a5495d95c 132 // bit 10: PCSSP1: SSP interface 1 power/clock enable
pyonta2017 0:ac7a5495d95c 133 #define LPC1768_PCONP_PCSSP1 0x400
pyonta2017 0:ac7a5495d95c 134 // bit 11: Reserved
pyonta2017 0:ac7a5495d95c 135 // bit 12: PCADC: A/D converter power/clock enable
pyonta2017 0:ac7a5495d95c 136 #define LPC1768_PCONP_PCADC 0x1000
pyonta2017 0:ac7a5495d95c 137 // bit 13: PCCAN1: CAN controller 1 power/clock enable
pyonta2017 0:ac7a5495d95c 138 #define LPC1768_PCONP_PCCAN1 0x2000
pyonta2017 0:ac7a5495d95c 139 // bit 14: PCCAN2: CAN controller 2 power/clock enable
pyonta2017 0:ac7a5495d95c 140 #define LPC1768_PCONP_PCCAN2 0x4000
pyonta2017 0:ac7a5495d95c 141 // bit 15: PCGPIO: GPIOs power/clock enable
pyonta2017 0:ac7a5495d95c 142 #define LPC1768_PCONP_PCGPIO 0x8000
pyonta2017 0:ac7a5495d95c 143 // bit 16: PCRIT: Repetitive interrupt timer power/clock enable
pyonta2017 0:ac7a5495d95c 144 #define LPC1768_PCONP_PCRIT 0x10000
pyonta2017 0:ac7a5495d95c 145 // bit 17: PCMCPWM: Motor control PWM power/clock enable
pyonta2017 0:ac7a5495d95c 146 #define LPC1768_PCONP_PCMCPWM 0x20000
pyonta2017 0:ac7a5495d95c 147 // bit 18: PCQEI: Quadrature encoder interface power/clock enable
pyonta2017 0:ac7a5495d95c 148 #define LPC1768_PCONP_PCQEI 0x40000
pyonta2017 0:ac7a5495d95c 149 // bit 19: PCI2C1: I2C interface 1 power/clock enable
pyonta2017 0:ac7a5495d95c 150 #define LPC1768_PCONP_PCI2C1 0x80000
pyonta2017 0:ac7a5495d95c 151 // bit 20: Reserved
pyonta2017 0:ac7a5495d95c 152 // bit 21: PCSSP0: SSP interface 0 power/clock enable
pyonta2017 0:ac7a5495d95c 153 #define LPC1768_PCONP_PCSSP0 0x200000
pyonta2017 0:ac7a5495d95c 154 // bit 22: PCTIM2: Timer 2 power/clock enable
pyonta2017 0:ac7a5495d95c 155 #define LPC1768_PCONP_PCTIM2 0x400000
pyonta2017 0:ac7a5495d95c 156 // bit 23: PCTIM3: Timer 3 power/clock enable
pyonta2017 0:ac7a5495d95c 157 #define LPC1768_PCONP_PCQTIM3 0x800000
pyonta2017 0:ac7a5495d95c 158 // bit 24: PCUART2: UART 2 power/clock enable
pyonta2017 0:ac7a5495d95c 159 #define LPC1768_PCONP_PCUART2 0x1000000
pyonta2017 0:ac7a5495d95c 160 // bit 25: PCUART3: UART 3 power/clock enable
pyonta2017 0:ac7a5495d95c 161 #define LPC1768_PCONP_PCUART3 0x2000000
pyonta2017 0:ac7a5495d95c 162 // bit 26: PCI2C2: I2C interface 2 power/clock enable
pyonta2017 0:ac7a5495d95c 163 #define LPC1768_PCONP_PCI2C2 0x4000000
pyonta2017 0:ac7a5495d95c 164 // bit 27: PCI2S: I2S interface power/clock enable
pyonta2017 0:ac7a5495d95c 165 #define LPC1768_PCONP_PCI2S 0x8000000
pyonta2017 0:ac7a5495d95c 166 // bit 28: Reserved
pyonta2017 0:ac7a5495d95c 167 // bit 29: PCGPDMA: GP DMA function power/clock enable
pyonta2017 0:ac7a5495d95c 168 #define LPC1768_PCONP_PCGPDMA 0x20000000
pyonta2017 0:ac7a5495d95c 169 // bit 30: PCENET: Ethernet block power/clock enable
pyonta2017 0:ac7a5495d95c 170 #define LPC1768_PCONP_PCENET 0x40000000
pyonta2017 0:ac7a5495d95c 171 // bit 31: PCUSB: USB interface power/clock enable
pyonta2017 0:ac7a5495d95c 172 #define LPC1768_PCONP_PCUSB 0x80000000
pyonta2017 0:ac7a5495d95c 173
pyonta2017 0:ac7a5495d95c 174 //Powers Up specified Peripheral(s)
pyonta2017 0:ac7a5495d95c 175 inline unsigned int Peripheral_PowerUp(unsigned int bitMask)
pyonta2017 0:ac7a5495d95c 176 {
pyonta2017 0:ac7a5495d95c 177 return LPC_SC->PCONP |= bitMask;
pyonta2017 0:ac7a5495d95c 178 }
pyonta2017 0:ac7a5495d95c 179
pyonta2017 0:ac7a5495d95c 180 //Powers Down specified Peripheral(s)
pyonta2017 0:ac7a5495d95c 181 inline unsigned int Peripheral_PowerDown(unsigned int bitMask)
pyonta2017 0:ac7a5495d95c 182 {
pyonta2017 0:ac7a5495d95c 183 return LPC_SC->PCONP &= ~bitMask;
pyonta2017 0:ac7a5495d95c 184 }
pyonta2017 0:ac7a5495d95c 185
pyonta2017 0:ac7a5495d95c 186 //returns if the peripheral is on or off
pyonta2017 0:ac7a5495d95c 187 inline bool Peripheral_GetStatus(unsigned int peripheral)
pyonta2017 0:ac7a5495d95c 188 {
pyonta2017 0:ac7a5495d95c 189 return (LPC_SC->PCONP & peripheral) ? true : false;
pyonta2017 0:ac7a5495d95c 190 }
pyonta2017 0:ac7a5495d95c 191
pyonta2017 0:ac7a5495d95c 192 #endif