Repository navigation
V4 Virtual Machine v0.9.0
V4 Virtual Machine v0.9.0 π
Major release adding preemptive multitasking system for embedded microcontrollers.
π― Highlights
Preemptive Multitasking System
- Priority-based scheduler supporting up to 8 concurrent tasks
- Inter-task messaging with 16-message ring buffer queue
- Platform abstraction for timer interrupts (ESP32-C6, CH32V203, etc.)
- Lightweight footprint: 42KB static library with LTO optimization
New VM Opcodes (0x90-0x9A)
11 new instructions for task control and messaging:
TASK_SPAWN,TASK_EXIT,TASK_SLEEP,TASK_YIELDCRITICAL_ENTER,CRITICAL_EXITTASK_SEND,TASK_RECEIVE,TASK_RECEIVE_BLOCKINGTASK_SELF,TASK_COUNT
π Performance
| Metric | Value |
|---|---|
| Context switch | <100ΞΌs |
| Message passing | <50ΞΌs |
| Default time slice | 10ms (configurable) |
πΎ Memory Footprint
| Component | Size |
|---|---|
| Static library (Release) | 42KB |
| Task scheduler | ~400 bytes |
| Per-task TCB | 32 bytes |
| Message queue | 132 bytes (16 messages) |
π§ Build Optimizations
- LTO (Link Time Optimization) now enabled by default
- Function/data section splitting for better dead code elimination
- Linker garbage collection (
-Wl,--gc-sections) - Unused features automatically removed in final applications
π API Example
#include "v4/task.h"
// Initialize task system (10ms time slice)
vm_task_init(vm, 10);
// Spawn a task with priority 128
int task_id = vm_task_spawn(vm, word_idx, 128, 256, 64);
// Task control
vm_task_sleep(vm, 100); // Sleep 100ms
vm_task_yield(vm); // Yield to other tasks
// Inter-task messaging
vm_task_send(vm, target_task, msg_type, data);
vm_task_receive(vm, msg_type, &data, &src_task);π§ͺ Testing
- 10 test suites with comprehensive coverage
- 119 assertions for task system functionality
- All tests passing β
π Documentation
See updated:
- README.md - Getting started and examples
- CHANGELOG.md - Complete release notes
- include/v4/task.h - Full API reference
- include/v4/task_platform.h - Platform porting guide
π Platform Support
Task system requires platform-specific timer interrupt implementation:
- Mock platform included for testing
- Platform implementations available in V4-ports repository
π Credits
Implemented with assistance from Claude Code (Anthropic).
Full Changelog
Added:
- Preemptive multitasking system with priority-based scheduler
- Task management API:
vm_task_init(),vm_task_spawn(),vm_task_exit() - Task control:
vm_task_sleep(),vm_task_yield(),vm_task_critical_enter/exit() - Inter-task messaging with type filtering and broadcast support
- Platform abstraction layer (
v4_task_platform.h) - 11 new VM opcodes (0x90-0x9A)
- Comprehensive test suite (119 assertions)
Changed:
- LTO enabled by default (
V4_ENABLE_LTO=ON) - Enhanced size optimization with function/data section splitting
- Binary size increase: +28KB (14KB β 42KB static library)
Performance:
- Context switch: <100ΞΌs
- Message passing: <50ΞΌs
- Default time slice: 10ms (configurable)
See CHANGELOG.md for complete details.