Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mickeyl/esp-microsleep
A replacement for FreeRTOS vTaskDelay with subtick granularity
https://github.com/mickeyl/esp-microsleep
esp32-idf freertos
Last synced: 19 days ago
JSON representation
A replacement for FreeRTOS vTaskDelay with subtick granularity
- Host: GitHub
- URL: https://github.com/mickeyl/esp-microsleep
- Owner: mickeyl
- License: mit
- Created: 2024-03-07T16:17:20.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-10T18:58:34.000Z (7 months ago)
- Last Synced: 2024-04-11T17:11:24.812Z (7 months ago)
- Topics: esp32-idf, freertos
- Language: C
- Homepage: https://www.vanille.de
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esp-microsleep
A replacement for FreeRTOS `vTaskDelay` with subtick granularity.
## Why?
Due to the way FreeRTOS works, it is impossible to achieve fine-grained
delays in the millisecond or sub-millisecond region.
Busy waiting is no alternative, since you will a) burn cycles and b) might
trigger the FreeRTOS task watchdog.## How?
This little ESP-IDF component fixes this by leveraging the `esp_timer`
subsystem. The currently running task starts a timer and waits
for a notification from the timer's ISR.## Installation
1. Adjust your `idf_component.yml` file to depend on this component:
```yml
dependencies:
mickeyl/esp_microsleep:
git: "https://github.com/mickeyl/esp-microsleep.git"
```2. Configure your project to allow for esp_timer dispatching via ISR:
`CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD=y`
3. Configure the proper amount of thread local storage.
If you're not using thread local storage elsewhere in your app, 2 will be enough:`CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2`
4. Configure the appropriate thread local storage index:`CONFIG_ESP_MICROSLEEP_TLS_INDEX=1`
## Usage
```c
// Include the header file.
#include// Calibrate the compensation value (for more accurate sleep times).
esp_microsleep_calibrate();// Call to delay the currently running task for 400 µs.
esp_microsleep_delay(400);
```## Implementation Notes
While the task is "waiting" for the notification to arrive,
it is suspended via `xTaskNotifyWait`.Since it takes a while from the timer alarm
to get the task notification processed, you
may achieve slightly longer sleep times than requested.To compensate for that, you should call `esp_microsleep_calibrate()`
which computes a value suitable for your system.## License
MIT.
## Maintainer
This component is maintained by Dr. Michael 'Mickey' Lauer