|
1 |
| -### Sleep and deep sleep |
| 1 | +### Sleep |
2 | 2 |
|
3 |
| -Mbed OS defines two sleep modes for HAL: |
| 3 | +<span class="warnings">**Warning:** We are changing the Sleep HAL API in an upcoming release of Mbed OS. You can find details on how it may affect you in the [Implementing the Sleep API](#implementing-the-sleep-api) section. |
4 | 4 |
|
5 |
| -- Sleep. |
6 |
| -- Deep sleep. |
| 5 | +Implement the Sleep HAL API to enable your device to go into a low power state when you are not actively using it. |
7 | 6 |
|
8 |
| -Each target should document in their implementation: |
| 7 | +#### Assumptions |
9 | 8 |
|
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. |
| 9 | +##### Defined behavior |
13 | 10 |
|
14 |
| -#### Sleep |
| 11 | +There are two power saving modes available in Mbed OS: |
15 | 12 |
|
16 |
| -The core system clock is disabled, both the low and high precision clocks are enabled and RAM is retained. |
| 13 | +###### Sleep |
17 | 14 |
|
18 |
| -1. Wake-up sources - any interrupt source can wake up the MCU. |
19 |
| -1. Latency - can wake up within 10 us. |
| 15 | +The core system clock is disabled. You can use both the low- and high-frequency clocks and retain RAM. |
20 | 16 |
|
21 |
| -#### Deep sleep |
| 17 | +1. Wake-up sources - Any interrupt must wake up the MCU. |
| 18 | +1. Latency - The MCU must wake up within 10 us. |
22 | 19 |
|
23 |
| -The core system clock is disabled. The low precision clocks are enabled, and RAM is retained. |
| 20 | +###### Deep sleep |
24 | 21 |
|
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. |
| 22 | +The core system clock is disabled. You can only enable the low-frequency clocks and retain RAM. |
27 | 23 |
|
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. |
| 24 | +1. Wake-up sources - RTC, low power ticker or GPIO must wake up the MCU. |
| 25 | +1. Latency - The MCU must wake up within 10 ms. |
29 | 26 |
|
30 | 27 | #### Implementing the Sleep API
|
31 | 28 |
|
32 |
| -There are two functions that the target needs to implement to support sleep, Their prototypes are in [hal/sleep_api.h](/docs/v5.7/mbed-os-api-doxy/sleep__api_8h_source.html): |
| 29 | +We are working on the new HAL Sleep API, which will replace the current version in an upcoming release of Mbed OS. You need to implement the Sleep API in both variants. First, you need to implement the current API. You can find it on master branch: |
33 | 30 |
|
34 |
| -- Sleep. |
| 31 | +[](https://os-doc-builder.test.mbed.com/docs/v5.7/mbed-os-api-doxy/sleep__api_8h_source.html) |
35 | 32 |
|
36 |
| -```c++ |
37 |
| -void hal_sleep(void); |
38 |
| -``` |
| 33 | +To make sure your platform is ready for the upcoming changes, you need to implement the future API and submit it in a separate pull request against `feature-hal-spec-sleep` branch. You can find the API and specification for the new Sleep API in the following header file: |
| 34 | + |
| 35 | +[](https://os.mbed.com/docs/v5.7/feature-hal-spec-sleep-doxy/group__hal__sleep.html) |
| 36 | + |
| 37 | +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. |
39 | 38 |
|
40 |
| -- Deep sleep. |
| 39 | +#### Testing |
41 | 40 |
|
42 |
| -```c++ |
43 |
| -void hal_deepsleep(void); |
| 41 | +The Mbed OS HAL provides a set of conformance tests for Sleep. You can use these tests to validate the correctness of your implementation. To run the Sleep HAL tests, use the following command: |
| 42 | + |
| 43 | +``` |
| 44 | +mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-sleep*" |
44 | 45 | ```
|
45 | 46 |
|
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. |
| 47 | +You can read more about the test cases: |
| 48 | + |
| 49 | +[](https://os.mbed.com/docs/v5.7/feature-hal-spec-sleep-doxy/group__hal__sleep__tests.html) |
0 commit comments