The objective of a super-nano Multi-Platform Nano-sized C++ Task Switching System (currently x64 and cortex-m) is to provide hardware and software that for All access will-free.
Build and revise are under way!
The Multi-Platform Task Switching System is a lightweight, efficient, and portable implementation of a cooperative multitasking system. It supports x64, Cortex-M4F, and Cortex-M7F architectures, making it suitable for a wide range of applications from desktop software to embedded systems. We try to use modern C++20 features, compatibility, and avoid STD or fat libs.
- Cross-Platform Compatibility: Runs on x64, Cortex-M4F, and Cortex-M7F architectures & next RISC-V in cenetr
- Lightweight: Minimal overhead, suitable for resource-constrained systems,KEEP arround KB of flash & bytes of RAM !! & arrount 100 cycle of cpu for switch
- Cooperative Multitasking: Efficient task switching without the need for a full RTOS, in next we ad managment event with high priority time ,but keep Cooperative this balance managment & safety
- Easy Integration: Simple API for creating and managing tasks
- Debuggable: Optional debug output for development and troubleshooting, NEXT under KB of code & can dubug & realtime trace with current SWD device
- Modern Build System: Uses CMake for easy compilation across different platforms
The system consists of the following key components:
- Task: Base class for defining individual tasks
- TaskManager: Manages task creation, scheduling, and switching
- Platform-Specific Implementations: Separate implementations for x64, Cortex-M4F, and Cortex-M7F
project_root/
├── CMakeLists.txt
├── include/
│ └── task_system.hpp
├── src/
│ ├── task_system.cpp
│ ├── task_system_x64.cpp
│ ├── task_system_cortex_m4f.cpp
│ ├── task_system_cortex_m7f.cpp
│ └── main.cpp
└── linker_script.ld (for ARM builds)
- CMake (version 3.15 or higher)
- For x64: A modern C++ compiler (GCC, Clang)
- For ARM: arm-none-eabi-gcc toolchain
-
Clone the repository:
git clone https://github.com/yourusername/task-switching-system.git cd task-switching-system
-
Create a build directory:
mkdir build && cd build
-
Configure the project using CMake (see Build Process for platform-specific commands)
-
Build the project:
cmake --build .
-
(Optional) Install the built binaries:
cmake --install .
cmake ..
cmake --build .
cmake -DCMAKE_SYSTEM_NAME=Generic -DCMAKE_SYSTEM_PROCESSOR=arm -DARM_CPU=cortex-m4f -DCMAKE_TOOLCHAIN_FILE=path/to/arm-none-eabi-gcc.cmake ..
cmake --build .
cmake -DCMAKE_SYSTEM_NAME=Generic -DCMAKE_SYSTEM_PROCESSOR=arm -DARM_CPU=cortex-m7f -DCMAKE_TOOLCHAIN_FILE=path/to/arm-none-eabi-gcc.cmake ..
cmake --build .
Add -DENABLE_DEBUG=ON
to your CMake configuration command to enable debug output.
-
Include the necessary header:
#include "task_system.hpp"
-
Define your task by inheriting from the
Task
class:class MyTask : public Task { public: MyTask() : Task(1) {} // 1 is the task ID void run() override { while (true) { // Your task logic here TaskManager::yield(); } } };
-
Create an instance of your task:
MyTask myTask;
In your main function:
int main() {
TaskManager taskManager;
taskManager.add_task(&myTask);
taskManager.start();
return 0;
}
Within your task's run()
method, use TaskManager::yield()
to cooperatively give up control:
TaskManager::yield();
When compiled with -DENABLE_DEBUG=ON
, the system will output debug information. You can add your own debug statements using the DEBUG_PRINT
macro:
DEBUG_PRINT("Task %u is running", task_id);
- The system uses cooperative multitasking, so tasks must yield voluntarily.
- On ARM platforms, context switching is optimized using assembly code.
- Avoid long-running operations without yielding to ensure responsive task switching.
- in next we weork on special mechanism keep Cooperative & also high level managment for tune perfomance & safety on the fly
-
Compilation Errors on ARM: Ensure you're using the correct toolchain file and have the arm-none-eabi-gcc toolchain installed.
-
Tasks Not Switching: Check that your tasks are calling
TaskManager::yield()
regularly. -
Unexpected Behavior on ARM: Verify that the linker script is correct for your specific microcontroller.
-
Debug Output Not Showing: Confirm that you've built with
-DENABLE_DEBUG=ON
.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.