Skip to content

Commit ab86b64

Browse files
author
Amanda Butler
authored
Merge pull request #209 from bulislaw/pg_sleep
Porting guide: Add Sleep API pg page
2 parents aa498c7 + cad78ac commit ab86b64

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

docs/contributing/sleep_deep_sleep.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1-
### Sleep and deep sleep
1+
## Sleep HAL API
22

3-
[A document explaining sleep and deep sleep]
3+
Mbed OS defines two sleep modes for HAL:
4+
5+
- Sleep.
6+
- Deep sleep.
7+
8+
Each target should document in their implementation:
9+
10+
- The target's mode description for each mode (how the target's mode maps to the Mbed OS sleep modes).
11+
- Wake-up latency for each mode.
12+
- Wake-up sources for each mode.
13+
14+
### Sleep
15+
16+
The core system clock is disabled, both the low and high precision clocks are enabled and RAM is retained.
17+
18+
1. Wake-up sources - any interrupt source can wake up the MCU.
19+
1. Latency - can wake up within 10 us.
20+
21+
### Deep sleep
22+
23+
The core system clock is disabled. The low precision clocks are enabled, and RAM is retained.
24+
25+
1. Wake-up sources - RTC, low power ticker and GPIO can wake up the MCU.
26+
1. Latency - can wake up within 10 ms.
27+
28+
The deep sleep latency (10 ms) is the higher limit of the boards we support. Most of targets have wake-up latency for deep sleep within a few microseconds, but often, reinitializing clocks and other configurations require additional time to restore previous state.
29+
30+
### Implementing the Sleep API
31+
32+
There are two functions that the target needs to implement to support sleep, Their prototypes are in [hal/sleep_api.h](/docs/v5.4/mbed-os-api-doxy/sleep__api_8h_source.html):
33+
34+
- Sleep.
35+
36+
```c++
37+
void hal_sleep(void);
38+
```
39+
40+
- Deep sleep.
41+
42+
```c++
43+
void hal_deepsleep(void);
44+
```
45+
46+
To enable sleep support in Mbed OS, you need to add the `SLEEP` label in the `device_has` option of the target's section in the `targets.json` file.

0 commit comments

Comments
 (0)