OSAL Backend Configuration Guide¶
This guide provides detailed configuration information for OSAL (Operating System Abstraction Layer) backends in the Nexus Embedded Platform.
概述¶
OSAL提供
Backend selection (Bare-metal, FreeRTOS, RT-Thread, Zephyr, Linux, Native)
System parameters (tick rate, heap size, stack size)
链接器 script configuration
Backend-specific options
后端 Selection¶
Select one OSAL backend using the choice menu:
choice
prompt "OSAL Backend"
default OSAL_BAREMETAL
config OSAL_BAREMETAL
bool "Bare-metal (No OS)"
config OSAL_FREERTOS
bool "FreeRTOS"
config OSAL_RTTHREAD
bool "RT-Thread"
config OSAL_ZEPHYR
bool "Zephyr RTOS"
config OSAL_LINUX
bool "Linux"
config OSAL_NATIVE
bool "Native (PC Simulation)"
endchoice
Only one backend can be selected at a time.
Bare-Metal 后端¶
概述¶
The bare-metal backend provides minimal RTOS functionality without a full operating system.
Features:
No RTOS overhead
Simple cooperative scheduler
Basic synchronization primitives
Minimal memory footprint
Deterministic behavior
Use Cases:
Simple applications
Resource-constrained systems
Real-time critical systems
Bootloaders
配置¶
Basic configuration:
CONFIG_OSAL_BAREMETAL=y
CONFIG_OSAL_BACKEND_NAME="baremetal"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=16384
CONFIG_OSAL_MAIN_STACK_SIZE=4096
Generated configuration:
#define NX_CONFIG_OSAL_BAREMETAL 1
#define NX_CONFIG_OSAL_BACKEND_NAME "baremetal"
#define NX_CONFIG_OSAL_TICK_RATE_HZ 1000
#define NX_CONFIG_OSAL_HEAP_SIZE 16384
#define NX_CONFIG_OSAL_MAIN_STACK_SIZE 4096
可用 APIs¶
Task Management:
osal_task_create()- Create cooperative taskosal_task_delete()- Delete taskosal_task_delay()- Delay taskosal_task_yield()- Yield to other tasks
Synchronization:
osal_mutex_create()- Create mutex (simple lock)osal_semaphore_create()- Create counting semaphoreosal_queue_create()- Create message queue
Time:
osal_get_tick_count()- Get system tick countosal_delay_ms()- Delay in milliseconds
限制¶
No preemptive scheduling
No priority-based scheduling
Limited synchronization primitives
No advanced RTOS features
最佳实践¶
Keep tasks short and cooperative
Use delays to yield CPU
Minimize heap usage
Avoid blocking operations
示例 配置¶
Minimal bare-metal system:
CONFIG_OSAL_BAREMETAL=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=8192
CONFIG_OSAL_MAIN_STACK_SIZE=2048
FreeRTOS 后端¶
概述¶
FreeRTOS is the most popular real-time operating system for embedded systems.
Features:
Preemptive multitasking
Priority-based scheduling
Rich synchronization primitives
Mature and well-tested
Large ecosystem
Commercial support available
Use Cases:
通用嵌入式应用
Multi-threaded applications
Real-time systems
Production systems
配置¶
Basic configuration:
CONFIG_OSAL_FREERTOS=y
CONFIG_OSAL_BACKEND_NAME="FreeRTOS"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
Generated configuration:
#define NX_CONFIG_OSAL_FREERTOS 1
#define NX_CONFIG_OSAL_BACKEND_NAME "FreeRTOS"
#define NX_CONFIG_OSAL_TICK_RATE_HZ 1000
#define NX_CONFIG_OSAL_HEAP_SIZE 32768
#define NX_CONFIG_OSAL_MAIN_STACK_SIZE 2048
#define NX_CONFIG_OSAL_MAX_PRIORITIES 32
可用 APIs¶
Task Management:
osal_task_create()- Create task with priorityosal_task_delete()- Delete taskosal_task_suspend()- Suspend taskosal_task_resume()- Resume taskosal_task_delay()- Delay taskosal_task_delay_until()- Delay until absolute timeosal_task_get_priority()- Get task priorityosal_task_set_priority()- Set task priority
Synchronization:
osal_mutex_create()- Create mutexosal_mutex_lock()- Lock mutexosal_mutex_unlock()- Unlock mutexosal_semaphore_create()- Create semaphoreosal_semaphore_give()- Give semaphoreosal_semaphore_take()- Take semaphoreosal_queue_create()- Create queueosal_queue_send()- Send to queueosal_queue_receive()- Receive from queueosal_event_group_create()- Create event group
Memory:
osal_malloc()- Allocate memoryosal_free()- Free memory
Time:
osal_get_tick_count()- Get system tick countosal_delay_ms()- Delay in milliseconds
Tick Rate 配置¶
Standard tick rate (1000 Hz):
CONFIG_OSAL_TICK_RATE_HZ=1000
1 ms resolution
Good balance
Most common
High resolution (10000 Hz):
CONFIG_OSAL_TICK_RATE_HZ=10000
0.1 ms resolution
Higher CPU overhead
For precise timing
Low resolution (100 Hz):
CONFIG_OSAL_TICK_RATE_HZ=100
10 ms resolution
Lower CPU overhead
For power-sensitive applications
堆 配置¶
Small system (16 KB):
CONFIG_OSAL_HEAP_SIZE=16384
Medium system (32 KB):
CONFIG_OSAL_HEAP_SIZE=32768
Large system (64 KB):
CONFIG_OSAL_HEAP_SIZE=65536
优先级 配置¶
Standard priorities (32 levels):
CONFIG_OSAL_MAX_PRIORITIES=32
0 = Idle priority
1-30 = Application priorities
31 = Highest priority
Minimal priorities (8 levels):
CONFIG_OSAL_MAX_PRIORITIES=8
Lower memory usage
Simpler scheduling
最佳实践¶
Use appropriate task priorities
Avoid priority inversion
Use mutexes for shared resources
Keep ISRs short
Use queues for inter-task communication
Monitor stack usage
Configure heap size appropriately
示例 Configurations¶
General purpose application:
CONFIG_OSAL_FREERTOS=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
Resource-constrained system:
CONFIG_OSAL_FREERTOS=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=16384
CONFIG_OSAL_MAIN_STACK_SIZE=1024
CONFIG_OSAL_MAX_PRIORITIES=8
High-performance system:
CONFIG_OSAL_FREERTOS=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=65536
CONFIG_OSAL_MAIN_STACK_SIZE=4096
CONFIG_OSAL_MAX_PRIORITIES=32
RT-Thread 后端¶
概述¶
RT-Thread is a Chinese open-source RTOS with rich features and IoT support.
Features:
Preemptive multitasking
Priority-based scheduling
Rich middleware (file system, network stack)
IoT protocols (MQTT, CoAP)
Device driver framework
Package manager
Use Cases:
IoT applications
Connected devices
Applications requiring middleware
Chinese market
配置¶
Basic configuration:
CONFIG_OSAL_RTTHREAD=y
CONFIG_OSAL_BACKEND_NAME="rtthread"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
可用 APIs¶
RT-Thread provides similar APIs to FreeRTOS through the OSAL abstraction:
任务 management
Synchronization primitives
内存管理
Time management
最佳实践¶
Use RT-Thread's device driver framework
Leverage built-in middleware
Use package manager for components
Follow RT-Thread conventions
示例 配置¶
CONFIG_OSAL_RTTHREAD=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
Zephyr 后端¶
概述¶
Zephyr is a Linux Foundation RTOS with modern architecture and extensive hardware support.
Features:
Modern C-based RTOS
Extensive hardware support
Device tree configuration
Networking stack
Bluetooth stack
Security features
Use Cases:
Modern embedded applications
IoT devices
Bluetooth applications
Security-critical systems
配置¶
Basic configuration:
CONFIG_OSAL_ZEPHYR=y
CONFIG_OSAL_BACKEND_NAME="zephyr"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=100
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
最佳实践¶
Use device tree for hardware configuration
Leverage Zephyr's networking stack
Use Zephyr's security features
Follow Zephyr conventions
示例 配置¶
CONFIG_OSAL_ZEPHYR=y
CONFIG_OSAL_TICK_RATE_HZ=100
CONFIG_OSAL_HEAP_SIZE=32768
CONFIG_OSAL_MAIN_STACK_SIZE=2048
CONFIG_OSAL_MAX_PRIORITIES=32
Linux 后端¶
概述¶
The Linux backend uses POSIX threads for testing on Linux systems.
Features:
POSIX threads
Standard Linux tools
Easy debugging
Fast development
Use Cases:
开发 and testing
Algorithm validation
CI/CD pipelines
配置¶
Basic configuration:
CONFIG_OSAL_LINUX=y
CONFIG_OSAL_BACKEND_NAME="linux"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=65536
CONFIG_OSAL_MAIN_STACK_SIZE=4096
最佳实践¶
Use for development and testing
Validate algorithms before hardware deployment
Use standard Linux debugging tools
示例 配置¶
CONFIG_OSAL_LINUX=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=65536
CONFIG_OSAL_MAIN_STACK_SIZE=4096
Native 后端¶
概述¶
The Native backend provides PC simulation for development and testing.
Features:
Cross-platform (Windows, Linux, macOS)
快速开发迭代
无需硬件
Standard debugging tools
Use Cases:
开发 and testing
Algorithm validation
CI/CD pipelines
配置¶
Basic configuration:
CONFIG_OSAL_NATIVE=y
CONFIG_OSAL_BACKEND_NAME="native"
System parameters:
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=65536
CONFIG_OSAL_MAIN_STACK_SIZE=4096
最佳实践¶
Use for development and testing
在硬件部署前验证配置
用于 CI/CD 测试
示例 配置¶
CONFIG_OSAL_NATIVE=y
CONFIG_OSAL_TICK_RATE_HZ=1000
CONFIG_OSAL_HEAP_SIZE=65536
CONFIG_OSAL_MAIN_STACK_SIZE=4096
后端 Comparison¶
Feature Comparison¶
Feature |
裸机 |
FreeRTOS |
RT-Thread |
Zephyr |
Linux |
Native |
|---|---|---|---|---|---|---|
Preemptive |
否 |
是 |
是 |
是 |
是 |
是 |
优先级 |
否 |
是 |
是 |
是 |
是 |
是 |
内存 |
Minimal |
Small |
Medium |
Medium |
Large |
Large |
Middleware |
否 |
Limited |
Rich |
Rich |
Full |
Full |
Maturity |
N/A |
Very High |
High |
High |
Very High |
N/A |
Ecosystem |
N/A |
Large |
Medium |
Large |
Very Large |
N/A |
用例建议¶
Bare-metal:
Simple applications
Bootloaders
Resource-constrained systems
Deterministic behavior required
FreeRTOS:
通用嵌入式应用
Production systems
Multi-threaded applications
Industry standard
RT-Thread:
IoT applications
Chinese market
Applications requiring middleware
Connected devices
Zephyr:
Modern embedded applications
Bluetooth applications
Security-critical systems
Extensive hardware support needed
Linux:
开发 and testing
Algorithm validation
CI/CD pipelines
Native:
开发 and testing
跨平台开发
CI/CD pipelines
另请参阅¶
Kconfig 教程 - Kconfig tutorial
Platform-Specific 配置 Guide - Platform-specific configuration
OSAL API 参考 - OSAL API reference
移植指南 - Platform porting guide