A_A _
o'' )_____// [MOS-STM32]
`_/ MOS ) Mini RTOS on Cortex-M
(_(_/--(_/ MOS <=> Mini-RTOS
- Board: NUCLEO-144 F429ZI
- MCU: STM32F429ZIT6 (256KB SRAM, 2MB FLASH)
.
βββ vendor // Hardware Abstraction Layer(SPL/HAL/LL/...)
βββ src
βββ drivers // Hardware Driver Portable Interface
β βββ stm32f4xx // STM32F4xx On-Chip Peripherals(USART, I2C, SPI, ...)
β βββ device // Other components(LED, LCD, ...)
β
βββ mos
β βββ config.h // System Configuration
β βββ arch // Arch-related
β β βββ cpu.hpp // asm for init/context_switch
β β
β βββ kernel // Kernel(Arch-independent)
β β βββ macro.hpp // Kernel Constant Macros
β β βββ type.hpp // Basic Types
β β βββ concepts.hpp // Type Constraints(Optional)
β β βββ data_type.hpp // Basic Data Structures
β β βββ alloc.hpp // Static/Dynamic Allocator
β β βββ global.hpp // Kernel Globals
β β βββ printf.h/.c // Thread-safe printf (by mpaland)
β β βββ task.hpp // Task control
β β βββ sync.hpp // Sync primitives
β β βββ scheduler.hpp // Scheduler and Policy
β β βββ ipc.hpp // Inter-Process Communication
β β βββ utils.hpp // Utils
β β
β βββ kernel.hpp // Import Kernel Modules
β βββ shell.hpp // Simple Shell
β
βββ user
β βββ gui // GUI-related
β β βββ GuiLite.h // GuiLite Framework
β β βββ UICode.cpp // User Interface
β β
β βββ global.hpp // User Globals
β βββ bsp.hpp // Board Support Package
β βββ app.hpp // User Applications
β βββ test.hpp // Test
β
βββ main.cpp // Entry main()
βββ stm32f4xx_it.cpp // Interrput SubRoutine(Partly)
Concurrent Task Period & Time Sequence
// MOS Kernel & Shell
#include "mos/kernel.hpp"
#include "mos/shell.hpp"
// HAL and Device
#include "drivers/stm32f4xx/hal.hpp"
#include "drivers/device/led.hpp"
namespace MOS::User::Global
{
using namespace HAL::STM32F4xx;
using namespace Driver::Device;
using namespace DataType;
// Shell I/O UART and Buffer
auto& stdio = STM32F4xx::convert(USARTx);
DataType::SyncRxBuf_t<16> io_buf;
// LED red, green, blue
Device::LED_t leds[] = {...};
}
namespace MOS::User::BSP
{
using namespace Driver;
using namespace Global;
void LED_Config()
{
for (auto& led: leds) {
led.init();
}
}
void USART_Config()
{
// Simplified
stdio.init(9600-8-1-N)
.rx_config(PXa) // RX -> PXa
.tx_config(PYb) // TX -> PYb
.it_enable(RXNE) // Enable RXNE interrupt
.enable();
}
...
}
namespace MOS::User::App
{
Sync::Barrier_t bar {2};
void LED_1(Device::LED_t leds[])
{
bar.wait();
for (auto _: Range(0, 20)) {
leds[1].toggle(); // green
Task::delay(250_ms);
}
kprintf("L1 exits...\n");
}
void LED_0(Device::LED_t leds[])
{
Task::create(
LED_1,
leds,
Task::current()->get_pri(),
"L1"
);
bar.wait();
while (true) {
leds[0].toggle(); // red
Task::delay(500_ms);
}
}
}
int main()
{
using namespace MOS;
using namespace Kernel;
using namespace User;
using namespace User::Global;
BSP::config(); // Init hardware and clocks
Task::create( // Create Calendar with RTC
App::Calendar, nullptr, 0, "Calendar"
);
Task::create( // Create Shell with io_buf
Shell::launch, &io_buf, 1, "Shell"
);
/* User Tasks */
Task::create(App::LED_0, &leds, 2, "L0");
...
/* Test examples */
Test::MutexTest();
Test::MsgQueueTest();
...
// Start scheduling, never return
Scheduler::launch();
}
A_A _ Version @ x.x.x(...)
o'' )_____// Build @ TIME, DATE
`_/ MOS ) Chip @ MCU, ARCH
(_(_/--(_/ 2023-2024 Copyright by Eplankton
Tid Name Priority Status Stack%
-----------------------------------------
#0 idle 15 READY 10%
#1 Shell 1 BLOCKED 21%
#2 L0 2 RUNNING 9%
-----------------------------------------
π¦ v0.1
β Done
- Basic Scheduler and Task control, memory management
π Plan
- Timers,
RoundRobin
- Inter-process communication
IPC
, pipes, message queues- Sync, semaphore, mutex, lock
- Porting simple shells
- Mutable page size, memory allocator
SPI
driver andLVGL
library- Port to other platform like
ESP32-C3(RISC-V)
π¦ v0.2
β Done
Sync::{Sema_t, Lock_t, Mutex_t<T>, CondVar_t, Barrier_t}
, whereMutex_t
adopts Priority Ceiling ProtocolScheduler::Policy::PreemptPri
, under same priority ->RoundRobin
Task::terminate
will be implicitly called when task exitsShell::{Command, CmdCall, launch}
HAL::STM32F4xx::SPI_t
andDriver::ST7735S_t
, supportGuiLite
Kernel::Global::os_ticks
andTask::delay
for blocking delay- Refactor the project into
{kernel, arch, drivers}
- Support
GCC
andSTM32CubeMX HAL
HAL::STM32F4xx::RTC_t
,CmdCall::date_cmd
andApp::Calendar
idle
usesKernel::Global::zombie_list
to recycle inactive pages- Three basic page allocator policies,
Page_t::Policy::{POOL, DYNAMIC, STATIC}
π¦ v0.3
β Done
Tids
fromBitMap_t
- (Experimental)
Task::Async::{Future_t, async/await}
IPC::MsgQueue_t
, Message QueueTask::create
allows genericfn
signature asvoid fn(auto argv)
with type check- Add
ESP32C3
asWiFi
Module- (Experimental) Atomic Type in
<stdatomic.h>
- (Experimental)
Utils::IntrGuard_t
, Nested Interrupt Lock Guard- Add
Driver::Device::SD_t
driver withSPI
mode- Add
FatFs
as File System- Add
Shell::usr_cmds
οΌUser Register Service
π Plan
IPC::pipe/channel
- Soft/Hardware Timers
- (Experimental) Async Stackless Coroutine
Async::{Future_t, async/await}
- (Experimental) Basic Formal Verification on
Scheduler
DMA_t
Driver- More real-time scheduling algorithms
FPU
supportResult<T, E>, Option<T>
- Add
POSIX
support- Performance Benchmark
- How to build a Real-Time Operating System(RTOS)
- PeriodicScheduler_Semaphore
- STM32F4-LCD_ST7735s
- A printf/sprintf Implementation for Embedded Systems
- GuiLite
- STMViewer
- FatFs
Wake up, Neo...
The Matrix has you...
Follow the white rabbit.
Knock, knock, Neo.