test

Dependencies:   HMC5883L MPL3115 MPU6050 MU2Class SDFileSystem mbed

Committer:
pyonta2017
Date:
Wed Sep 06 15:45:18 2017 +0000
Revision:
1:1f1bbb95af44
Parent:
0:1f956fab4d28
test

Who changed what in which revision?

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