Skip to content

Commit d4690da

Browse files
author
Amanda Butler
authored
Merge pull request #423 from bulislaw/power_mgmt
Sleep handbook improvements
2 parents a5095de + 26f3bc8 commit d4690da

File tree

2 files changed

+74
-61
lines changed

2 files changed

+74
-61
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
## Power management
2+
3+
### Sleep
4+
5+
There is only one sleep function in Mbed OS:
6+
7+
```c++
8+
void sleep();
9+
```
10+
11+
This function invokes sleep manager, which selects the most appropriate sleep mode.
12+
13+
<span class="notes">**Note:** In most cases, you don't need to call `sleep()` directly. Mbed OS enters sleep mode automatically any time the system is idle. That is when all your threads are in a waiting state, for example waiting for an event or a timeout.</span>
14+
15+
#### Sleep modes
16+
17+
There are two available sleep modes:
18+
19+
1. Sleep mode
20+
21+
The system clock to the core stops until a reset or an interrupt occurs. This eliminates dynamic power that the processor, memory systems and buses use. This mode maintains the processor, peripheral and memory state, and the peripherals continue to work and can generate interrupts.
22+
23+
You can wake up the processor by any internal peripheral interrupt or external pin interrupt.
24+
25+
2. Deep sleep mode
26+
27+
This mode is similar to sleep but saves more power and has a longer wakeup time. It saves additional power by turning off the high-speed clocks. Because of this, you can only enter this mode when peripherals relying on high-speed clocks are not in use. Peripherals that do not rely on high-speed clocks include the LowPowerTicker, RTC and InterruptIn APIs. This mode maintains all state.
28+
29+
#### Sleep manager
30+
31+
The sleep manager provides an API and logic to control device sleep mode selection. Although standard sleep doesn't affect application execution, deep sleep might introduce some additional power savings that can affect the application, for instance high-speed clock-dependent drivers. To ensure correct operation of your application, sleep manager may disable deep sleep, in which case your board enters normal sleep, instead. This mechanism is mostly invisible to the user, but you should be aware that it may affect the power consumption of your hardware.
32+
33+
These Mbed OS drivers can lock the deep sleep:
34+
35+
- `Ticker`.
36+
- `Timeout`.
37+
- `Timer`.
38+
- `SPI`.
39+
- `I2C`.
40+
- `CAN`.
41+
- `SerialBase`.
42+
43+
#### Example
44+
45+
[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/)](https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/file/e85412b4147e/main.cpp)
46+
47+
### Function reference
48+
49+
[![View code](https://www.mbed.com/embed/?type=library)](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/group__platform__power__mgmt.html)
50+
51+
### Idle loop
52+
53+
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:
54+
55+
```c++
56+
void new_idle_loop()
57+
{
58+
// do nothing
59+
}
60+
61+
void main()
62+
{
63+
rtos_attach_idle_hook(&new_idle_loop);
64+
}
65+
```
66+
67+
#### Function reference
68+
69+
[![View code](https://www.mbed.com/embed/?type=library)](https://os.mbed.com/docs/v5.7/mbed-os-api-doxy/group__rtos___idle.html)
70+
71+
### Example
72+
73+
[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/)](https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/file/e85412b4147e/main.cpp)
74+

docs/reference/api/platform/SleepManager.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)