Preemptive Real Time OS
Disclaimer: The purpose of this project is learning. It should not be used for anything serious. If you are looking for an environment for running some production cortex-m code, you should check cortex-m-rtic or TockOS
For an example you should check chaos-example Heavily inpired by cortex-m-rtic, ChaOS uses procedural macros for defining the context and tasks:
#[chaos::os(quanta_us = 10_000, scheduler = chaos::scheduler::RRScheduler)]
mod chaos {
#[task(stack_size = 500)]
fn task0() {
}
}
All os related attributes are specified in the os macro. Available attributes:
quanta_us
: The interval for a SysTick in microseconds (default to 10_000)scheduler
: The scheduler to be used (mandatory)ahb_freq
: The frequency of the bus that drives the SysTick (default to16_000_000
as I only tested forSTM32f4DISCOVERY
). This is only used ifSYST::get_ticks_per_10ms
returns 0
Inside the mod you can define the tasks that will be scheduled. Available attributes:
stack_size
: The size of the stack for the task (mandatory)privileged
: Flag set the task should run in privileged mode (default disabled)fp
: Flag set if the task should start with floating point context enabled (default disabled)
ChaOS is preemptive, it will construct an array from the provided tasks and will pass it to the scheduler. At every SysTick interrupt or sleep system call, the scheduler will decide which task to schedule next and the os will do the context switch very similar to the one presented in The Definitive Guide to ARM Cortex -M3 and Cortex-M4 Processors
Everything is static right now. You can not add task dynamically or start/stop existing ones.
Available syscalls:
- Sleep. The name is not really good. What this does is that it preempts the task.
- starting/stopping tasks
- dynamic memory
- dynamic tasks
- MMU
- os objects (mutexes, semaphores, condition variables, etc.)
- drivers
[1]: The Definitive Guide to ARM Cortex -M3 and Cortex-M4 Processors by Joseph Yiu