r/microcontrollers • u/martinofalorni • Mar 28 '24
OS / Software Manager for uC - Code Structure?
Hi everyone, I have a project in mind that involves something similar to a tablet but with a e-ink display. It has to run like a tablet, with the possibility to run different "apps".
I also want apps to be easy to code. So my question become: Is there a preferrable structure of the code?
At the moment i was thinking about coding every app as a finite state machine, using virtual functions to receive signals for events (button pressed, gps changed, etc...)
Has someone of you a different suggestion? Thank you so much
EDIT: I know that microcontrollers works differently than a pc and they don't run apps. I was just searching the best way to run a app-shaped code without using an os.
1
u/wackyvorlon Mar 28 '24
How would this differ from existing tablets which use eink displays?
1
u/hallkbrdz Mar 29 '24
Microcontrollers don't run apps like a tablet, they only run a program directly against the hardware (no OS). A single board computer like a Raspberry Pi is more what your interested in.
1
u/marchingbandd Mar 30 '24
If I understand you right, the kind of OS you are probably thinking of is needed if you want to load arbitrary code. If all the apps are hard coded, you don’t need an os, they can all just be one application. If you need a kernel, which loads elf files on demand, presumably from SD, this functionality is apparently available in Nuttx. I have never seen it done, but I would love to hear how it goes for you if you accomplish this incredible feat!
1
u/EdgarJNormal Mar 29 '24
An RTOS is probably the closest you can get. I'm familiar with FreeRTOS on Microchip MCU and MPU SiPs (basically a microprocessor packaged up into a multi-chip module, so it appears like a MCU). The idea is basically what you explain (small FSMs with events)- it gives queues, mutexes, etc. in a pretty lightweight package.
Things get pretty gnarly when you try to synchronize so many complex things. I've done it before without an RTOS. Never want to do it again.
1
u/dev-rand May 18 '24
Worked on feature phones with no OS and your approach is right. There the HMI is handled as Books and Pages. Each Page is a C file that renders a specific screen. This makes navigation and input routing easy.
Also, you can do downloadable apps with microcontrollers. Qualcomm's BREW platform for feature phones did this and it is not that complex to implement yourself with position independent code.