RF24Network Send example program.

Dependencies:   xtoff RF24Network mbed

Fork of RF24Network_Send by Akash Vibhute

Committer:
pietor
Date:
Thu Mar 08 09:23:05 2018 +0000
Revision:
8:62b4607c44ca
8/03;

Who changed what in which revision?

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