mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

Committer:
okini3939
Date:
Fri Mar 16 15:26:46 2012 +0000
Revision:
8:bed0b81794ba

        

Who changed what in which revision?

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