An application which show how to reach lowest current consumption for the LPC4088 QuickStart Board

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Wed Apr 09 10:31:10 2014 +0000
Revision:
1:26dc920733ee
Parent:
0:7a7964515b10
Updated to latest version of EALib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:7a7964515b10 1 /******************************************************************************
embeddedartists 0:7a7964515b10 2 * Includes
embeddedartists 0:7a7964515b10 3 *****************************************************************************/
embeddedartists 0:7a7964515b10 4 #include "mbed.h"
embeddedartists 0:7a7964515b10 5 #include "sdram.h"
embeddedartists 0:7a7964515b10 6
embeddedartists 0:7a7964515b10 7 /******************************************************************************
embeddedartists 0:7a7964515b10 8 * Local variables
embeddedartists 0:7a7964515b10 9 *****************************************************************************/
embeddedartists 0:7a7964515b10 10
embeddedartists 0:7a7964515b10 11 // led1 + led 2 -> active low
embeddedartists 0:7a7964515b10 12 static DigitalOut led1(LED1);
embeddedartists 0:7a7964515b10 13 static DigitalOut led2(LED2);
embeddedartists 0:7a7964515b10 14 // led3 + led 4 -> active high
embeddedartists 0:7a7964515b10 15 static DigitalOut led3(LED3);
embeddedartists 0:7a7964515b10 16 static DigitalOut led4(LED4);
embeddedartists 0:7a7964515b10 17
embeddedartists 0:7a7964515b10 18 static DigitalIn p2_10(P2_10);
embeddedartists 0:7a7964515b10 19 static InterruptIn wkp(P2_10);
embeddedartists 0:7a7964515b10 20
embeddedartists 0:7a7964515b10 21 static int cnt = 0;
embeddedartists 0:7a7964515b10 22
embeddedartists 0:7a7964515b10 23 /******************************************************************************
embeddedartists 0:7a7964515b10 24 * Local functions
embeddedartists 0:7a7964515b10 25 *****************************************************************************/
embeddedartists 0:7a7964515b10 26
embeddedartists 0:7a7964515b10 27 #define MIND_BUSY 0x00000001 /* MII is Busy */
embeddedartists 0:7a7964515b10 28 #define DP83848C_DEF_ADR 0x0100 /* Default PHY device address */
embeddedartists 0:7a7964515b10 29 #define MII_WR_TOUT 0x00050000 /* MII Read timeout count */
embeddedartists 0:7a7964515b10 30 #define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */
embeddedartists 0:7a7964515b10 31 #define PHY_BMCR_PWR_DOWN (1 << 11) /* 1 = General power down mode */
embeddedartists 0:7a7964515b10 32
embeddedartists 0:7a7964515b10 33 static int phy_write(unsigned int PhyReg, unsigned short Data) {
embeddedartists 0:7a7964515b10 34 unsigned int timeOut;
embeddedartists 0:7a7964515b10 35
embeddedartists 0:7a7964515b10 36 LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg;
embeddedartists 0:7a7964515b10 37 LPC_EMAC->MWTD = Data;
embeddedartists 0:7a7964515b10 38
embeddedartists 0:7a7964515b10 39 for(timeOut = 0; timeOut < MII_WR_TOUT; timeOut++) { /* Wait until operation completed */
embeddedartists 0:7a7964515b10 40 if((LPC_EMAC->MIND & MIND_BUSY) == 0) {
embeddedartists 0:7a7964515b10 41 return 0;
embeddedartists 0:7a7964515b10 42 }
embeddedartists 0:7a7964515b10 43 }
embeddedartists 0:7a7964515b10 44
embeddedartists 0:7a7964515b10 45 return -1;
embeddedartists 0:7a7964515b10 46 }
embeddedartists 0:7a7964515b10 47
embeddedartists 0:7a7964515b10 48 static void powerDown() {
embeddedartists 0:7a7964515b10 49 // SRC[SLEEPDEEP] set to 1 = sleep
embeddedartists 0:7a7964515b10 50 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
embeddedartists 0:7a7964515b10 51
embeddedartists 0:7a7964515b10 52 LPC_SC->PCON = 0x01;
embeddedartists 0:7a7964515b10 53
embeddedartists 0:7a7964515b10 54 // wait for interrupt
embeddedartists 0:7a7964515b10 55 __WFI();
embeddedartists 0:7a7964515b10 56
embeddedartists 0:7a7964515b10 57 }
embeddedartists 0:7a7964515b10 58
embeddedartists 0:7a7964515b10 59 static void incCnt() {
embeddedartists 0:7a7964515b10 60
embeddedartists 0:7a7964515b10 61 // A counter is increased by one when the LPC4088 is brought out of
embeddedartists 0:7a7964515b10 62 // power down. The 4 LEDs will reflect the state of the counter.
embeddedartists 0:7a7964515b10 63 // Please note that when a LED is on more power will be consumed.
embeddedartists 0:7a7964515b10 64 // Press the button enough times (16) and all LEDs will be off
embeddedartists 0:7a7964515b10 65 // again.
embeddedartists 0:7a7964515b10 66
embeddedartists 0:7a7964515b10 67 cnt++;
embeddedartists 0:7a7964515b10 68
embeddedartists 0:7a7964515b10 69 if (cnt & 0x01) {
embeddedartists 0:7a7964515b10 70 led4 = 1;
embeddedartists 0:7a7964515b10 71 }
embeddedartists 0:7a7964515b10 72 else {
embeddedartists 0:7a7964515b10 73 led4 = 0;
embeddedartists 0:7a7964515b10 74 }
embeddedartists 0:7a7964515b10 75
embeddedartists 0:7a7964515b10 76 if (cnt & 0x02) {
embeddedartists 0:7a7964515b10 77 led3 = 1;
embeddedartists 0:7a7964515b10 78 }
embeddedartists 0:7a7964515b10 79 else {
embeddedartists 0:7a7964515b10 80 led3 = 0;
embeddedartists 0:7a7964515b10 81 }
embeddedartists 0:7a7964515b10 82
embeddedartists 0:7a7964515b10 83 if (cnt & 0x04) {
embeddedartists 0:7a7964515b10 84 led2 = 0;
embeddedartists 0:7a7964515b10 85 }
embeddedartists 0:7a7964515b10 86 else {
embeddedartists 0:7a7964515b10 87 led2 = 1;
embeddedartists 0:7a7964515b10 88 }
embeddedartists 0:7a7964515b10 89
embeddedartists 0:7a7964515b10 90 if (cnt & 0x08) {
embeddedartists 0:7a7964515b10 91 led1 = 0;
embeddedartists 0:7a7964515b10 92 }
embeddedartists 0:7a7964515b10 93 else {
embeddedartists 0:7a7964515b10 94 led1 = 1;
embeddedartists 0:7a7964515b10 95 }
embeddedartists 0:7a7964515b10 96 }
embeddedartists 0:7a7964515b10 97
embeddedartists 0:7a7964515b10 98 /******************************************************************************
embeddedartists 0:7a7964515b10 99 * Local functions
embeddedartists 0:7a7964515b10 100 *****************************************************************************/
embeddedartists 0:7a7964515b10 101
embeddedartists 0:7a7964515b10 102 int main() {
embeddedartists 0:7a7964515b10 103 // user push button is available on P2.10. Make sure pull-up is enabled
embeddedartists 0:7a7964515b10 104 // on this pin since it is put low when the button is pressed.
embeddedartists 0:7a7964515b10 105 p2_10.mode(PullUp);
embeddedartists 0:7a7964515b10 106
embeddedartists 0:7a7964515b10 107 // enable interrupt on p2.10 and register interrupt handler. When the
embeddedartists 0:7a7964515b10 108 // user-push button is pressed the application will be brought out
embeddedartists 0:7a7964515b10 109 // of power-down mode and incCnt function will be called.
embeddedartists 0:7a7964515b10 110 wkp.rise(&incCnt);
embeddedartists 0:7a7964515b10 111
embeddedartists 0:7a7964515b10 112 // turn off all LEDs by default
embeddedartists 0:7a7964515b10 113 led1 = 1;
embeddedartists 0:7a7964515b10 114 led2 = 1;
embeddedartists 0:7a7964515b10 115 led3 = 0;
embeddedartists 0:7a7964515b10 116 led4 = 0;
embeddedartists 0:7a7964515b10 117
embeddedartists 0:7a7964515b10 118
embeddedartists 0:7a7964515b10 119 // ------------------------------------------------------->
embeddedartists 0:7a7964515b10 120 // Initialize SDRAM and set CKE 0 to make sure SDRAM is
embeddedartists 0:7a7964515b10 121 // in power-down mode. CKE is also connected to a 1K5 pull
embeddedartists 0:7a7964515b10 122 // down resistor
embeddedartists 0:7a7964515b10 123 sdram_init();
embeddedartists 0:7a7964515b10 124 DigitalOut cke(P2_24);
embeddedartists 0:7a7964515b10 125 cke = 0; // set low not to draw any current
embeddedartists 0:7a7964515b10 126 // <-------------------------------------------------------
embeddedartists 0:7a7964515b10 127
embeddedartists 0:7a7964515b10 128
embeddedartists 0:7a7964515b10 129 // ------------------------------------------------------->
embeddedartists 0:7a7964515b10 130 // Initialize Ethernet by instantiating the Ethernet class
embeddedartists 0:7a7964515b10 131 // The Ethernet interface doesn't contain a power-down
embeddedartists 0:7a7964515b10 132 // method so we reimplement phy_write in this app and
embeddedartists 0:7a7964515b10 133 // puts the PHY in power-down here
embeddedartists 0:7a7964515b10 134 Ethernet eth;
embeddedartists 0:7a7964515b10 135 phy_write(PHY_REG_BMCR, PHY_BMCR_PWR_DOWN);
embeddedartists 0:7a7964515b10 136 // <-------------------------------------------------------
embeddedartists 0:7a7964515b10 137
embeddedartists 0:7a7964515b10 138
embeddedartists 0:7a7964515b10 139 // must be low to disable U7 (STMPS2171STR)
embeddedartists 0:7a7964515b10 140 DigitalOut p1_19(P1_19);
embeddedartists 0:7a7964515b10 141 p1_19 = 0;
embeddedartists 0:7a7964515b10 142
embeddedartists 0:7a7964515b10 143
embeddedartists 0:7a7964515b10 144 // p2.18 connected to 1K5 pull-down resistor
embeddedartists 0:7a7964515b10 145 DigitalOut p2_18(P2_18);
embeddedartists 0:7a7964515b10 146 p2_18 = 0;
embeddedartists 0:7a7964515b10 147
embeddedartists 0:7a7964515b10 148
embeddedartists 0:7a7964515b10 149 while(1) {
embeddedartists 0:7a7964515b10 150 // when the above initialization is done, all LEDs are off,
embeddedartists 0:7a7964515b10 151 // HDK is disaabled (jumper on JP3 removed) and LPC4088 in
embeddedartists 0:7a7964515b10 152 // power-down, the measured current consumption is ~5 mA.
embeddedartists 0:7a7964515b10 153
embeddedartists 0:7a7964515b10 154 powerDown();
embeddedartists 0:7a7964515b10 155
embeddedartists 0:7a7964515b10 156 // In this example we are not doing anything here when the LPC4088 is
embeddedartists 0:7a7964515b10 157 // brought out of power-down. Instead the incCnt function is registerd
embeddedartists 0:7a7964515b10 158 // as an interrupt handler and will be called when the user push-button
embeddedartists 0:7a7964515b10 159 // is pressed.
embeddedartists 0:7a7964515b10 160
embeddedartists 0:7a7964515b10 161 }
embeddedartists 0:7a7964515b10 162 }