MAX32625PICO LP0 mode

Dependencies:   SX1276GenericLib USBDevice

Fork of PICO_LP0 by Walter Luu

main.cpp

Committer:
walterluu
Date:
2020-10-16
Revision:
7:c92ed2d6e344
Parent:
6:51f492ca61a2

File content as of revision 7:c92ed2d6e344:

#include "mbed.h"

// Low Power Mode
#include "lp.h"
#include "mxc_config.h"
#include "lp.h"
#include "rtc.h"
//#define LP1_WakeTime    3 //seconds
#define LP0_WakeTime    3 //seconds

/***************************************************************************
 * LEDs Instantiation
 **************************************************************************/
//DigitalOut gLED(LED2);          // green LED
//DigitalOut rLED(LED1);          // red LED
//DigitalOut bLED(LED3);          // blue LED


// *****************************************************************************
void RTC_Setup()
{
    rtc_cfg_t RTCconfig;

    RTCconfig.compareCount[0] = LP0_WakeTime;//3 second timer          
//    RTCconfig.compareCount[1] = LP1_WakeTime;      //3 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;

    RTC_Init(&RTCconfig);

    RTC_Start();
}

int main() {
 
    // Set all LEDs off
//    gLED = LED_OFF;
//    rLED = LED_OFF;
//    bLED = LED_OFF;
    
    
     // LP0 Wake Up call
    if(LP_IsLP0WakeUp()){
        wait(1);
    }  
    
    
    //configure RTC and start
    RTC_Setup();

    while (1) {
        
        // Set all LEDs off
//        gLED = LED_OFF;
//        rLED = LED_OFF;
//        bLED = LED_OFF;
        
    
        /***************************************************************************
        * LP0 Experiment
        **************************************************************************/
        //Clear existing wake-up config
        LP_ClearWakeUpConfig();

        //Clear any event flags
        LP_ClearWakeUpFlags();

        //configure wake-up on RTC compare 0
        LP_ConfigRTCWakeUp(1, 0, 0, 0);


        //set RTC compare 0 value
        uint32_t cmp = RTC_GetCount() + LP0_WakeTime;
        RTC_SetCompare(0,cmp);
        RTC_ClearFlags(MXC_F_RTC_FLAGS_COMP0);


        //interrupts are disabled in LP_EnterLP0
        LP_EnterLP0();

        //firmware will reset on wake-up

    } // end of while(1) loop
        
}  // end of main()