代码拉取完成,页面将自动刷新
A_A _
o'' )_____// MOS @ STM32
`_/ MOS ) Cortex-M上的简单RTOS
(_(_/--(_/ MOS <=> Mini-RTOS
- Board: NUCLEO-144 F429ZI
- MCU: STM32F429ZIT6 (256KB SRAM, 2MB FLASH)
.
├── vendor // 硬件抽象层(SPL/HAL/LL/...)
└── src
├── drivers // 硬件抽象层兼容接口
│ ├── stm32f4xx // STM32F4xx 片上外设(USART, I2C, SPI,...)
│ └── device // 其他元器件(LED, LCD, SD,...)
│
├── mos
│ ├── config.h // 系统配置宏
│ ├── arch // 硬件架构相关
│ │ └── cpu.hpp // 初始化/上下文切换
│ │
│ ├── kernel // 内核层代码(架构无关)
│ │ ├── macro.hpp // 内核常量宏
│ │ ├── type.hpp // 基础类型
│ │ ├── concepts.hpp // 类型约束(可选)
│ │ ├── data_type.hpp // 基本数据结构
│ │ ├── alloc.hpp // 静态/动态内存分配
│ │ ├── global.hpp // 内核全局变量
│ │ ├── printf.h/.c // 线程安全的 printf(*)
│ │ ├── task.hpp // 任务控制
│ │ ├── sync.hpp // 同步原语
│ │ ├── scheduler.hpp // 调度器
│ │ ├── ipc.hpp // 进程间通信
│ │ └── utils.hpp // 其他工具
│ │
│ ├── kernel.hpp // 内核模块
│ └── shell.hpp // 简单的 Shell
│
├── user
│ ├── gui // GUI 相关
│ │ ├── GuiLite.h // GuiLite 框架
│ │ └── UICode.cpp // 自定义 UI
│ │
│ ├── global.hpp // 用户全局变量
│ ├── bsp.hpp // 板级支持包
│ ├── app.hpp // 用户任务
│ ├── fatfs.hpp // 文件系统
│ └── test.hpp // 测试代码
│
├── main.cpp // 入口函数
└── stm32f4xx_it.cpp // 中断处理子例程(部分)
Shell交互
Mutex测试
LCD驱动与GUI
并发任务周期与时序
// 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()
{
stdio.init(9600-8-1-N)
.rx_config(PXa) // RX -> PXa
.tx_config(PYb) // TX -> PYb
.it_enable(RXNE) // Enable RXNE interrupt
.enable(); // Enable UART
}
...
}
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
✅ 完成:
- 基本的调度器与任务控制,内存管理
📌 计划:
- 定时器,时间片轮转调度
- 进程间通信
IPC
,管道、消息队列- 进程同步
Sync
,信号量、互斥锁- 移植简单的
Shell
- 可变页面大小,内存分配器
SPI
驱动,移植GuiLite/LVGL
图形库- 移植到其他开发板/架构,例如
ESP32-C3(RISC-V)
📦 v0.2
✅ 完成:
Sync::{Sema_t, Lock_t, Mutex_t<T>, CondVar_t, Barrier_t}
同步原语,其中Mutex_t
使用优先级天花板协议Scheduler::Policy::PreemptPri
,在相同优先级下则以时间片轮转RoundRobin
调度Task::terminate
在任务退出时隐式调用,回收资源Shell::{Command, CmdCall, launch}
,简单的命令行交互HAL::STM32F4xx::SPI_t
和Driver::Device::ST7735S_t
, 移植GuiLite
图形> 库Kernel::Global::os_ticks
和Task::delay
,阻塞延时- 重构项目架构为
{kernel, arch, drivers}
- 支持
GCC
编译,兼容STM32Cube HAL
HAL::STM32F4xx::RTC_t
,CmdCall::date_cmd
,App::Calendar
实时日历idle
使用Kernel::Global::zombie_list
回收非活动页面- 三种基本的页面分配策略
Page_t::Policy::{POOL(池), DYNAMIC(动态), STATIC(静态)}
📦 v0.3
✅ 完成:
Tids
映射到BitMap_t
IPC::MsgQueue_t
,消息队列Task::create
允许泛型函数签名为void fn(auto argv)
,并提供类型检查- 添加
ESP32C3
作为WiFi
模块- (实验性) 原子类型
<stdatomic.h>
- (实验性)
Utils::IntrGuard_t
,嵌套中断- 添加
Driver::Device::SD_t
,SD
卡驱动(SPI
模式)- 添加
FatFs
文件系统- 添加
Shell::usr_cmds
,用户注册服务
📌 计划:
- 进程间通信:管道/通道
FPU
支持Result<T, E>, Option<T>
,错误处理- (实验性)
Async::{Future_t, async/await}
,异步无栈协程- (实验性) 对
Scheduler
进行简单的形式化验证DMA_t
驱动- 更多实时调度算法
- 软/硬件定时器
Timer
- 添加
POSIX
支持- 性能基准测试
Wake up, Neo...
The Matrix has you...
Follow the white rabbit.
Knock, knock, Neo.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型