Same as ECE4180Lab1Part2 but with Power Management added. Turns off unused interfaces on mbed (including usb interface, so must be powered externally)

Dependencies:   PowerControl mbed

Files at this revision

API Documentation at this revision

Comitter:
wschon
Date:
Sun Jan 31 21:05:09 2016 +0000
Commit message:
Same as ECE4180Lab1Part2 but with Power Management added

Changed in this revision

PowerControl.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r da73efbce5d9 PowerControl.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PowerControl.lib	Sun Jan 31 21:05:09 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JST2011/code/PowerControl/#d0fa2aeb02a4
diff -r 000000000000 -r da73efbce5d9 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jan 31 21:05:09 2016 +0000
@@ -0,0 +1,82 @@
+#include "mbed.h"
+#include "PowerControl/PowerControl.h"
+#include "PowerControl/EthernetPowerControl.h"
+
+PwmOut myled(p21);
+DigitalIn button1(p30);
+DigitalIn button2(p29);
+DigitalIn switch1(p8);
+DigitalOut myled4(LED4);
+DigitalOut myled3(LED3);
+float intensity = 0.5f;
+
+// Function to power down magic USB interface chip with new firmware
+#define USR_POWERDOWN    (0x104)
+int semihost_powerdown() {
+    uint32_t arg;
+    return __semihost(USR_POWERDOWN, &arg);
+}
+
+class Watchdog {
+public:
+// Load timeout value in watchdog timer and enable
+    void kick(float s) {
+        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+        uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+        LPC_WDT->WDTC = s * (float)clk;
+        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+        kick();
+    }
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+    void kick() {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+ 
+// Setup the watchdog timer
+Watchdog wdt;
+
+
+int main() {
+    PHY_PowerDown();   //Power down Ethernet interface
+    int result;
+    result = semihost_powerdown();  //Power down USB interface
+    int count = 0;
+    Peripheral_PowerDown(0xFFFF7FFF);
+
+    wdt.kick(4.0);
+    if ((LPC_WDT->WDMOD >> 2) & 1)
+        myled4 = 1; else myled3 = 1;
+        wait(2);
+        myled4 = 0;
+        myled3 = 0;
+
+     
+    
+    while(1) {
+        if (button1 == 0)  {
+            if (intensity <= 1.0f) {
+                intensity += 0.07f;
+            }
+        }
+        if (button2 == 0) {
+            if (intensity >= 0.0f) {
+                intensity -= 0.07f;
+            }
+        }
+        if (switch1 == 0) {
+            myled = intensity;
+        }
+        else {
+            myled = 0.0f;
+            }
+        wait(0.1);
+        count++;
+        if (count == 80) {
+            wait(11);
+            }
+        wdt.kick(); //kick the watchdog timer
+    }
+}
diff -r 000000000000 -r da73efbce5d9 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jan 31 21:05:09 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file