Mistake on this page?
Report an issue in GitHub or email us

DeepSleepLock

The DeepSleepLock class provides an RAII object for disabling sleep. In other words, creating a DeepSleepLock object calls its constructor, which increments the deep sleep prevention lock. The DeepSleepLock object automatically releases the deep sleep prevention lock in its destructor when the object goes out of scope. Another way to look at this is when the DeepSleepLock object exists, it prevents deep sleep.

Note: Drivers that don't work in deep sleep mode automatically prevent deep sleep mode, so DeepSleepLock does not need to protect them.

DeepSleepLock class reference

Public Member Functions
void lock ()
 Mark the start of a locked deep sleep section. More...
void unlock ()
 Mark the end of a locked deep sleep section. More...

Example

This example shows how you can lock deep sleep to decrease interrupt latency at the expense of increased power consumption.

/*
 * Copyright (c) 2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */
#include "mbed.h"

InterruptIn button(BUTTON1);
DigitalOut led(LED1);

void toggle()
{
    led = !led;
}

int main()
{
    button.rise(&toggle);
    button.fall(&toggle);

    // Lock deep sleep to decrease interrupt latency
    // at the expense of high power consumption
    DeepSleepLock lock;

    while (1) {
        // Wait and let interrupts take care of the rest
        ThisThread::sleep_for(1000);
    }
}

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.