Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTOS Support #32

Open
vpochapuis opened this issue Aug 1, 2022 · 4 comments
Open

RTOS Support #32

vpochapuis opened this issue Aug 1, 2022 · 4 comments

Comments

@vpochapuis
Copy link

Hello!
Is there any current support for a RTOS with esp-rs (for example a safe API to work with the ESP-IDF FreeRTOS) ?
And if yes could it be documented in the Book? (And if not maybe add a part or note about the status of RTOS with esp-rs).
(I am new to this environment, sorry if the question isn't relevant.)

Thank you for your help

@MabezDev
Copy link
Member

MabezDev commented Aug 1, 2022

Most RTOS APIs are already integrated into the standard library, for things like threads and mutexes. Other APIs that are not expressible via the standard library we recommend using the freertos C functions from esp-idf-sys. If you have ideas for safe wrappers for those, PRs are most welcome :).

@vpochapuis
Copy link
Author

Most RTOS APIs are already integrated into the standard library, for things like threads and mutexes. Other APIs that are not expressible via the standard library we recommend using the freertos C functions from esp-idf-sys. If you have ideas for safe wrappers for those, PRs are most welcome :).

Thank you. My main concern is about the timings, I need to run task at a specific frequency that is not dependent on the Task execution time (using DelayUntil in FreeRTOS). And I am worried that using the esp-idf-sys function wrapper would not be a good solution inside a Thread as I don't understand well yet the relationship between the Standard Library and the way FreeRTOS is integrated under. (For example, is a Thread considered a FreeRTOS Task? etc.. And what about Task Priorities).

I use Rust since March, so I am sorry if my low level understanding is still limited in this language.

And I wish I could do a PR XD I still need more experience before doing so! (But would be pleased to do so once I get the knowledge and the confidence)

Thanks for your help

@MabezDev
Copy link
Member

MabezDev commented Aug 1, 2022

(For example, is a Thread considered a FreeRTOS Task? etc.. And what about Task Priorities).

Yes, but sort of no. A thread is a FreeRTOS task, but instead of the Rust standard library calling FreeRTOS APIs, it actually calls libc APIs, specifically pthread APIs. esp-idf has the glue between the two so that pthread can create and manage FreeRTOS tasks.

With all that said, they are still FreeRTOS tasks underneath, so you can get the handle to the task with https://github.com/esp-rs/esp-idf-hal/blob/75b4e4f406c91d8b5e444343b42518b3a176dbdb/src/interrupt.rs#L108 and use whatever raw C FreeRTOS API you like :)

@vpochapuis
Copy link
Author

(For example, is a Thread considered a FreeRTOS Task? etc.. And what about Task Priorities).

Yes, but sort of no. A thread is a FreeRTOS task, but instead of the Rust standard library calling FreeRTOS APIs, it actually calls libc APIs, specifically pthread APIs. esp-idf has the glue between the two so that pthread can create and manage FreeRTOS tasks.

With all that said, they are still FreeRTOS tasks underneath, so you can get the handle to the task with https://github.com/esp-rs/esp-idf-hal/blob/75b4e4f406c91d8b5e444343b42518b3a176dbdb/src/interrupt.rs#L108 and use whatever raw C FreeRTOS API you like :)

Ok great!
Thanks for the explanations, it helps me better understand the ecosystem and guide me for future developments.
I will contribute if i have any chance in the future!

For the Book, I don't know if it really would be interesting for others, but when coming from Real Time Embedded Systems, I think having a Section about RTOS, even just with your previous explanation, could be useful for anyone concerned by this topic!

Thanks for everything,
I am glad we can have such quick and good support, this is a great community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants