| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
sanoRTOS is a minimal Real-Time Operating System (RTOS) designed for ARM Cortex-M and RISC-V microcontrollers. This implementation provides a simple yet effective API for task management, synchronization, and communication, enabling efficient and predictable multitasking in embedded systems.
Priority-Based Preemptive Scheduling
Efficient task management with support for preemptive scheduling based on task priority levels.
Optional Priority Inheritance
Prevents priority inversion during mutex acquisition by temporarily elevating the priority of lower-priority tasks.
Symmetric Multiprocessing (SMP) Support
Fully supports multi-core systems with per-task core affinity configuration for optimal load balancing.
Dynamic Stack Overflow Detection
Runtime monitoring of task stacks to catch and handle stack overflows proactively.
Configurable Tick Rate
Easily adjustable tick frequency to match application-specific timing and power requirements.
Task Synchronization Primitives
Includes mutexes, semaphores, condition variables, and event objects for safe and efficient coordination between tasks.
Inter-Task Communication
Enables message passing between tasks using message queues, stream buffers, message buffers, and mailboxes.
Minimalistic and Lightweight Design
Designed for embedded systems with limited resources — small footprint, fast context switches, and no unnecessary bloat.
The detailed API reference, including example code for each kernel object, lives in API_REFERENCE.md.
Clone the Repository:
Open STM32Cube IDE:
Include sanoRTOS in Project:
Add Source Files:
Edit stm32xxxx_it.c file:
STM32 initializes the SysTick timer during its clock initialization process and defines the SysTick_Handler ISR function for the implementation of the delay function in the Core > Src > stm32xxxx_it.c file. Hence, the SysTick_Handler ISR function cannot be redefined inside the sanoRTOS. Instead, call sanoRTOS_SysTickHook() from the SDK's SysTick_Handler() implementation.
Moreover, sanoRTOS includes definition for PendSV_Handler used for task scheduling and context switching. STM32 also defines this ISR in stm32xxxx_it.c file; Hence, we need to remove the definition of this ISR from the stm32xxxx_it.c file to avoid multiple definition error.
Clone the Repository:
Set Up Your Pico Project:
file(GLOB_RECURSE SANORTOS_SRCS
sanoRTOS/source/*.c
sanoRTOS/ports/arm/rp2350/port.c)
#for Hazard3 RISC-V cores, add source files from risc-v port of rp2350 (sanoRTOS/ports/riscv/rp2350/port.c and sanoRTOS/ports/riscv/rp2350/port.S)
target_include_directories(project_name PRIVATE
sanoRTOS/include
sanoRTOS/ports/arm/rp2350/include #for RISC-V port replace this line with sanoRTOS/ports/risc-v/rp2350/include
)
target_sources(project_name PRIVATE ${SANORTOS_SRCS})
file(GLOB_RECURSE SANORTOS_SRCS
sanoRTOS/source/*.c
sanoRTOS/ports/arm/rp2040/port.c)
target_include_directories(project_name PRIVATE
sanoRTOS/include
sanoRTOS/ports/arm/rp2040/include
)
target_sources(project_name PRIVATE ${SANORTOS_SRCS})
target_link_libraries(project_name PRIVATE pico_stdlib pico_multicore hardware_sync)#include "sanoRTOS/config.h"
#include "sanoRTOS/scheduler.h"
#include "sanoRTOS/task.h"
//Include MCU-specific header files here
// Define two tasks with 1024-byte stacks.
// These tasks are assigned to any available core using AFFINITY_CORE_ANY.
//
// On multicore MCUs (e.g. RP2350), sanoRTOS can schedule tasks on different cores
// depending on the affinity setting. AFFINITY_CORE_ANY allows the scheduler to choose any core.
// This can help distribute load across both cores and enable true parallel execution.
//
// On single-core MCUs, this setting is safely ignored — all tasks will run on the only available core.
TASK_DEFINE(task1, 1024, firstTask, NULL, 1, AFFINITY_CORE_ANY);
TASK_DEFINE(task2, 1024, secondTask, NULL, 1, AFFINITY_CORE_ANY);
taskHandleType *dynamicTask = NULL;
// Task 1 function – user-defined logic inside this loop
void firstTask(void *args) {
while (1) {
// Task1 code to run repeatedly
}
}
// Task 2 function – user-defined logic inside this loop
void secondTask(void *args) {
while (1) {
// Task2 code to run repeatedly
}
}
// Dynamically created task function
void thirdTask(void *args) {
while (1) {
// Dynamic task code to run repeatedly
}
}
int main() {
// Perform MCU-specific initializations here
// Example: initialize GPIO, UART, peripherals, etc.
// Start tasks
taskStart(&task1);
taskStart(&task2);
// Create and start a dynamic task
int ret = taskCreate(&dynamicTask,
"dynamicTask",
1024,
thirdTask,
NULL,
1,
AFFINITY_CORE_ANY);
if (ret != RET_SUCCESS) {
// Handle task creation failure
while (1) {
}
}
// Start the sanoRTOS scheduler (will not return)
schedulerStart();
// Control should never reach here if scheduler is working correctly
return 0;
}This RTOS includes ports for the following Espressif RISC-V based MCUs:
Unlike most ESP32 projects, these ports do not use Espressif's ESP-IDF.
Instead, they are built on top of custom ESP32 RISC-V bare-metal SDK developed specifically for low-level control and minimal system overhead.
The bare-metal SDK provides:
This SDK allows the RTOS to run without the ESP-IDF framework, making the implementation closer to traditional embedded RTOS ports.
This project is licensed under the MIT License-see the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |