Idle loop
Idle loop is a background system thread, which scheduler executes when no other threads are ready to run. That may happen when your application is waiting for an event to happen. By default, the idle loop invokes sleep manager to enter a sleep mode. You can overwrite this behavior by providing a different handler:
void new_idle_loop()
{
// do nothing
}
void main()
{
rtos_attach_idle_hook(&new_idle_loop);
}
Function reference
Example
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
int main()
{
// Deep sleep for 1 second
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
ThisThread::sleep_for(1000);
// Lock deep sleep
printf("Locking deep sleep\r\n");
sleep_manager_lock_deep_sleep();
// Sleep for 1 second
printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep());
ThisThread::sleep_for(1000);
}