Real-Time Operating System in 96 Lines of C | RIOS

preview_player
Показать описание
Let's take a look at the most basic form of an RTOS - a project called RIOS, which in it's most basic form fits under 50 lines of C.

Рекомендации по теме
Комментарии
Автор

3:24 "The next thing... is a typo" cracked me up.

UliTroyo
Автор

I wrote one for an 8080 in 1981 for a custom industrial SBC. It is still in use in a few places in the world today.

LuminosityUK
Автор

You could install an RTOS from a USB stick if you wanted. Interestingly BlackBerryOS was real-time despite being a user-facing OS.

Jupiter___
Автор

I waited for something like this since 2006

優さん-nm
Автор

Very impressive! I've wondered for like 20 years how a multi tasking operating system would switch mid-task to the next process. Now I know a lot more about this process.

Gersberms
Автор

The microcontroller in Arduino was originally an atMega8 at 16MHz, replaced by an atMega328P (at 16MHz too, but upgradable to 20MHz), which is the argument you passed to AVRDude.
Now, to be fair, using interrupts (especially the CLK one) is catastrophic in terms of timewaste and stack management. You're better putting counters and have a switch/case in your "main" loop that calls functions by pointer. From there, you can craft your functions so they perform an atomic part of the entire task every time they're called (such as updating the screen, turning one LED on or off in a field of LEDs, etc.). Interrupts are cool, but that's admitting the defeat of intelligence by paying incompetece with clock cycles.

RegisMichelLeclerc
Автор

Thats good for only periodic tasks. We also have inter task communucation. Meaning that task b can send an event to task a in that case an asyncronous preemption can be needed!

mecitpamuk
Автор

Man, where have you been all these days?

jwd.t
Автор

I don't think I would consider this as an OS, it still fits more into runtime category. Having a loader for external binary executables is I think an essential part to qualify as OS, otherwise it's just statically compiled task scheduler. Good stuff thou, especially for learning, and still very useful. Registers not being pushed to and popped from stack between task switching is a bit concerning. Guess this has to be done by task itself.

ivanmaglica
Автор

I just cant describe amount of problems you'll get when using such approach, it's completely wrong. Just never use interrupts like this, that's not what they meant for. Never call user code bigger that assigning value to a register/shared memory from ISR. Never enable interrupts from ISR unless you want another high-priority interrupt to be called. And never use nested interrupts like this - its a way to stack overflow, only use it when it's necessary to handle event in time.

If you want just run some code "simultaniousely" just add all your "tasks" into for() loop and in every task add check for timeout and do something only when timeouted (see how Runnables in AUTOSAR works)

dzm_mlc
Автор

A char in a struct full of ints won't save any memory unless your compiler packs structs. Packed structs mean unaligned access which is slow on most architectures. Even some models of x86 (which has unaligned opcodes) have slow unaligned access to data. I don't know the native word size of the CPU you're using. Any larger than a byte and you don't want to pack.

eekee
Автор

RTOS doesn't mean a basic OS, though they typically are. It means that they are designed to handle real-time constraints which is difficult to do on bloated OSes, hence why they tend to be stripped down, bare bones implementations.

jon
Автор

*laughs in solar flare on unhardened chip*. really though, this a nice exposition, its got the bones.

trejohnson
Автор

Looks cool, maybe i'll make my own using a round robin sheduler, i'll see

ItsCOMMANDer_
Автор

Right, that makes a lot of sense. RTOSs allow this structure of overlapping periodic tasks. This seems like a very basic and common requirement.
The existence of RIOS bags the question then, why use something bigger like freeRTOS, or even pay for one? What's the thing that makes RIOS non-viable for "real" projects?

ThePlacehole
Автор

How complex, time consuming can the tick function be?
If none of the tasks finishes before the next interrupt, is the avr gonna crash bc of stack overflow?

kriszSTNX
Автор

0:18 Bold of you to assume that my OS can run Minecraft.

arduous
Автор

Actually this is very similar to time driven non-cooperative multitasking system.

RasitEvduzen
Автор

Not sure if a minimalist scheduler running on a microcontroller qualifies as an operating system, but hey. It's kind of cute.

Kalumbatsch
Автор

This was so informative and interesting

esra_erimez