Expand description
§XWOS RUST
§简介
XWOS RUST是Rust语言 #![no_std] 环境下的XWOS框架,可让用户使用RUST语言开发RTOS的应用。
在编写XWOS RUST时,作者充分阅读并参考了RUST语言std库的代码,尽量仿照std库的形式提供API。
传统RUST程序的入口是 main.rs 的 fn main() ,
XWOS RUST的入口是 pub unsafe extern "C" fn xwrust_main() 。
编写XWOS RUST的应用时,需要以下步骤:
- 
- 在工程目录(例如电路板模块 bm文件夹 或$(OEM)文件夹)建立一个独立的 玄武模块 , 并创建makefile。
 
- 在工程目录(例如电路板模块 
include $(XWOS_WKSPC_DIR)/XWOS.cfg
include xwbs/functions.mk
include xwbs/xwmo.rust.mk- 
- 创建 Cargo.toml。
 
- 创建 
[package]
name = "rustapp"
version = "0.1.0"
edition = "2021"
[lib]
name = "rustapp"
crate-type = ["staticlib"]
[dependencies]
cortex-m = "0.7"
xwrust = {path = "../../../../xwmd/xwrust"}- 
- 创建 .cargo/config.toml。
 
- 创建 
[build]
rustflags = [
 "--cfg", "unix",
 "--cfg", "target_env=\"newlib\"",
]
target-dir = "target"
[unstable]
build-std = ["core", "alloc"]- 
- 在 src/lib.rs中实现pub unsafe extern "C" fn xwrust_main()。
 
- 在 
#![no_std]
use xwrust::xwmm::allocator::AllocatorMempool;
#[global_allocator]
pub static GLOBAL_ALLOCATOR: AllocatorMempool = AllocatorMempool;
#[no_mangle]
pub unsafe extern "C" fn xwrust_main() {
    // 用户代码
}- 
- 在XWOS的C语言入口 xwos_main()中创建一个线程来调用xwrust_main()。
 
- 在XWOS的C语言入口 
extern void xwrust_main(void);
xwer_t xwrust_task(void * arg);
xwos_thd_d xwrust_thd;
xwer_t xwos_main(void)
{
        struct xwos_thd_attr attr;
        xwos_thd_attr_init(&attr);
        attr.name = "xwrust.thd";
        attr.stack = NULL;
        attr.stack_size = 8192;
        attr.priority = XWRUST_THD_PRIORITY;
        attr.detached = true;
        attr.privileged = true;
        xwos_thd_create(&xwrust_thd, &attr, xwrust_task, NULL);
}
xwer_t xwrust_task(void * arg)
{
        xwrust_main();
}§XWOS RUST 的功能
XWOS RUST提供了RTOS的基本功能:
XWOS RUST所有功能都提供了 static 创建的方法,如果不使用 Arc<T>, Box<T> 等,
即可实现完全静态内存分配的代码。
§返回XWOS首页
Modules§
- XWOS RUST:配置
- XWOS RUST:错误码
- XWOS RUST:宏
- XWOS RUST:panic
- XWOS RUST:基本类型
- XWOS RUST:位图数组
- XWOS RUST:设备栈
- XWOS RUST:中间件
- XWOS RUST:内存管理
- XWOS RUST:内核库
- XWOS RUST:系统时间
Macros§
- 生成位掩码的宏
- 生成GPIO PIN掩码的宏