MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

Adding Sleep API #28

Closed will127534 closed 7 years ago

will127534 commented 7 years ago

Hi all, I notice that MT7697 SDK have sleep function so maybe Arduino API can add a sleep() function to reduce power consumption

here is the function at /core/arduino/delay.c

void sleep(uint32_t ms){
    if(hal_sleep_manager_init() == HAL_SLEEP_MANAGER_ERROR)
    {
        // Check the log for error handling.
        return;
    }
    if(hal_sleep_manager_is_sleep_locked())
    {
        printf("Cannot enter the sleep mode, as the sleep is locked\n");
    }else
    {
        if (hal_sleep_manager_set_sleep_time(ms) == HAL_SLEEP_MANAGER_OK)
        {
            hal_sleep_manager_enter_sleep_mode(HAL_SLEEP_MODE_SLEEP);
        }
    }
}
pablosun commented 7 years ago

Note that we'll keep tickless mode disabled in FreeRTOS. Therefore this API will actually put the board "deeper" into WFI sleep mode - which should save more power than an "idle (delay)" sleep.

pablosun commented 7 years ago

Hi @will127534 , how long does the sleep API is being able to sleep in your case? In my case the enter_sleep_mode succeeded but immediately wakes up.

  Serial.print("start sleep, time=");
  Serial.println(millis());
  bool isOK = sleep(5000);
  Serial.print("sleep result=");
  Serial.println(isOK);
  Serial.print("time=");
  Serial.println(millis());

And the output is always

start sleep, time=1
sleep result=1
time=5
pablosun commented 7 years ago

We'll set this enhancement to pending statue first, until a more concete usage scenario appears.