lobaro / FreeRTOS-rust

Rust crate for FreeRTOS
MIT License
354 stars 58 forks source link

Add delay provider #5

Open xoviat opened 3 years ago

xoviat commented 3 years ago

This and other projects may require a delay provider (for example: https://github.com/stm32-rs/stm32f4xx-hal/blob/master/src/delay.rs) that provides delayms and delayus functions. lt should be possible to provide this functionality as part of this package. I am new to rust (I thought it could be a better option than c), but I use pdMS_TO_TICKS in C.

xoviat commented 3 years ago

I've partially implemented something, but then realized that FreeRTOS does not provide accurate timing below 1ms (configTICK_RATE_HZ for me is set to 1000, which I think means the minimum delay is 1ms). So a better solution would be that for delays less than 1ms, the standard delay library is used, and for delays above 1 ms, the FreeRTOS delay is used? Of course, the FreeRTOS delay is less accurate, but that might not be a problem? What are your thoughts on this?

niondir commented 3 years ago

I basically agree. I think that the FreeRTOS delay functions are perfect for most application timings where high accuracy isn't needed. Indeed it depends on the configTICK_RATE_HZ

An implementation could check if a given delay is above the minimum delay allowed based on configTICK_RATE_HZ and have some documentation about limited granularity.

I'm fine with accepting a PR to implement FreeRTOS based timing functions. There is also some API for "waitUntil" which is worth a look. For drivers and hardware related timings (e.g. implementing 1-wire) one might still need to use system timers.