LP Transmitter Wakeup

Dependencies:   max32630fthr USBDevice

Files at this revision

API Documentation at this revision

Comitter:
MI
Date:
Wed Jan 24 01:15:14 2018 +0000
Parent:
0:41ed595f83f5
Child:
2:33b3b46a9c0d
Commit message:
Initial commit

Changed in this revision

USBDevice.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice.lib	Tue Jan 09 19:10:44 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/#17ac7abb27a7
--- a/main.cpp	Tue Jan 09 19:10:44 2018 +0000
+++ b/main.cpp	Wed Jan 24 01:15:14 2018 +0000
@@ -1,11 +1,10 @@
 #include "mbed.h"
 #include "max32630fthr.h"
-#include "USBSerial.h"
 #include "mxc_config.h"
 #include "lp.h"
 #include "gpio.h"
-
-MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+#include "rtc.h"
+#include "MAX14690.h"
 
 DigitalOut rLED(LED1);
 DigitalOut gLED(LED2);
@@ -13,90 +12,79 @@
 
 DigitalIn sw1(SW1);
 
-gpio_cfg_t gpioLP0;
-
-#define LP0_WAKE_GPIO_PORT  2
-#define LP0_WAKE_GPIO_PIN   PIN_3
-
 // *****************************************************************************
-void Wakeup_blinks()
+void RTC_Setup()
 {
-    int numBlinks = 3;
-
-    bLED = LED_OFF;
-    gLED = LED_OFF;
+    rtc_cfg_t RTCconfig;
     
-    while(numBlinks) {
-        rLED = LED_ON;
-        wait_ms(167);
-        rLED = LED_OFF;
-        wait_ms(167);
+    RTCconfig.compareCount[0] = 1;//1 second timer
+    RTCconfig.compareCount[1] = 10;//10 second timer
+    RTCconfig.prescaler = RTC_PRESCALE_DIV_2_12; //1Hz clock
+    RTCconfig.prescalerMask = RTC_PRESCALE_DIV_2_12;//used for prescaler compare
+    RTCconfig.snoozeCount = 0;
+    RTCconfig.snoozeMode = RTC_SNOOZE_DISABLE;
 
-        numBlinks--;
-    }
-    
-}
+    RTC_Init(&RTCconfig);
 
-// *****************************************************************************
-void Powerdown_blinks()
-{
-    gLED = LED_OFF;
-    
-    int numBlinks = 3;
-
-    while(numBlinks) {
-        bLED = LED_ON;
-        wait_ms(167);
-        bLED = LED_OFF;
-        wait_ms(167);
-
-        numBlinks--;
-    }
-    
+    RTC_Start();
 }
 
 /******************************************************************************/
 int main(void)
 {
+    MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+    
     //check if starting at main because of LP0 wake-up
-    if(LP_IsLP0WakeUp())
-        Wakeup_blinks();        //blinks red LED 3 times
+    if(LP_IsLP0WakeUp()) {
+        
+    }
     else {
         //We did not wake up from sleep and this is first power-on
-
+        //Only configure RTC the first time around 
+        RTC_Setup();
     }
 
-    //initialize LEDs
     gLED = LED_ON;
-    bLED = LED_OFF;
-    rLED = LED_OFF;
-    
-    //use the gpio_cfg_t type to control GPIO operation with built-in Maxim library functions
-    gpioLP0.port = LP0_WAKE_GPIO_PORT;
-    gpioLP0.mask = LP0_WAKE_GPIO_PIN;
-    gpioLP0.func = GPIO_FUNC_GPIO;
-    gpioLP0.pad = GPIO_PAD_INPUT_PULLUP;
-    GPIO_Config(&gpioLP0);
+    rLED = LED_ON;
+    bLED = LED_ON;
 
     while(1) {
-        //Wait for user to push sw1 to enter LP0
-        if(sw1 == 0)
-        {
-            Powerdown_blinks();     //blinks blue LED 3 times
+        
+        //hold down switch 1 to prevent the microcontroller from going into LP0
+        while(sw1 == 0);
+        
+        //keep LED on long enough to see it!
+        wait_ms(100);
+        
+        gLED = LED_OFF;
+        rLED = LED_OFF;
+        bLED = LED_OFF;
 
-            //Clear existing wake-up config
-            LP_ClearWakeUpConfig();
+        //disable unused PMIC rails to minimize power consumption
+        pegasus.max14690.ldo2SetMode(MAX14690::LDO_DISABLED);
+        pegasus.max14690.ldo3SetMode(MAX14690::LDO_DISABLED);
+
+        //Clear existing wake-up config
+        LP_ClearWakeUpConfig();
 
-            //Clear any event flags
-            LP_ClearWakeUpFlags();
-
-            //configure wake-up on GPIO
-            LP_ConfigGPIOWakeUpDetect(&gpioLP0, 0, LP_WEAK_PULL_UP);
+        //Clear any event flags
+        LP_ClearWakeUpFlags();
 
-            //interrupts are disabled in LP_EnterLP0
-            LP_EnterLP0();
+        //configure wake-up on RTC compare 0
+        //LP_ConfigRTCWakeUp(enable compare 0, enable compare 1, set prescale, set rollover)
+        LP_ConfigRTCWakeUp(1, 0, 0, 0);
+        
+        //read the current RTC timer and add 5 seconds to it
+        uint32_t cmp = RTC_GetCount() + 5;
+        
+        //set RTC to generate an interrupt 5 seconds from current value
+        RTC_SetCompare(0,cmp);
+        
+        //clear comparison flag in the RTC registers
+        RTC_ClearFlags(MXC_F_RTC_FLAGS_COMP0);
 
-            //firmware will reset with no prior knowledge on wake-up
-        }
+        LP_EnterLP0();
+
+        //firmware will reset with no prior knowledge on wake-up
     }
 }