7 ms·
We've done quite a bit of experimentation with adding preemptive multitasking support to non-hard real time software running on MCUs at my current company. Aft
by ramary 4y ago
We've done quite a bit of experimentation with adding preemptive multitasking support to non-hard real time software running on MCUs at my current company.
After a lot of head banging and dead ends, I've come to the conclusion personally that the embedded community could really use an implementation of the POSIX threading APIs or some meaningful subset thereof for various platforms. They're already standardized, well understood/used, and aren't that hard to implement on an MCU.
Of course, there would probably be some semantics that wouldn't make sense to or may not be possible to implement on MCUs, and there would be work required to support different cores, but these tradeoffs seem better to me than reinventing the wheel and probably needing to make the same tradeoffs at some point down the line with a ground up new API.
For Arduino, exposing POSIX APIs wouldn't be very user-friendly. But wrapping something more user-friendly around them seems like a maintainable and extensible path for the project and community.
- Tajnymag 4y agoThreads are already supported by esp-idf on esp32 source: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/pthread.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32/...
- ramary 4y agoThat's great, thanks for sharing!
- Teknoman117 4y agoDo you know how the core scheduling works? Does it migrate tasks between cores? Is there any notable core to core migration penalty?
- deepspace 4y agoAnd esp-idf uses FreeRTOS, which is pretty much the standard for this kind of thing.
- qbasic_forever 4y agoThis is the direction a lot of RTOSs go, for example Zephyr (https://docs.zephyrproject.org/3.0.0/guides/portability/posix.html https://docs.zephyrproject.org/3.0.0/guides/portability/posi...) and FreeRTOS (https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_POSIX/index.html https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_POSIX/i...).
- ramary 4y agoThanks for sharing! I hope the Arduino teams heads in this direction as well.
- inamberclad 4y agoRTEMS has been providing a real time, multi threaded, POSIX API on embedded systems for decades. It's got preemption, interactive shells, a libbsd port with networking, etc. It's popular in spacecraft, especially in combination with NASA's Core Flight System (cFS). I've run it on an STM32F4 and a Raspberry Pi. BSP support is a little lacking in some cases. The raspberry pi is currently crashing on a call to fflush(). No idea why. I really wish more people knew about it. As a matter of fact, I'll post about it here.
- ramary 4y agoThis is great to know about, thank you for sharing!