freertos_rust/
lib.rs

1#![feature(allocator_api)]
2//! # FreeRTOS for Rust
3//!
4//! Rust interface for the FreeRTOS embedded operating system. Requires nightly Rust.
5//! It is assumed that dynamic memory allocation is provided on the target system.
6//!
7//! This library interfaces with FreeRTOS using a C shim library which provides function
8//! wrappers for FreeRTOS macros. The compiled Rust application should be linked to the
9//! base C/C++ firmware binary.
10//!
11//! Examples are provided inside [freertos-rust-examples](https://github.com/lobaro/FreeRTOS-rust/tree/master/freertos-rust-examples)
12//!
13//! For more examples, check the enclosed GCC ARM/Rust/QEMU based unit tests. The project
14//! ``qemu_runner`` cross-compiles this library, compiles the main firmware using GCC ARM and links
15//! in the appropriate entry points for unit tests. [GNU ARM Eclipse QEMU](http://gnuarmeclipse.github.io/qemu/)
16//! is used to run the test binaries.
17//!
18//! Be sure to check the [FreeRTOS documentation](http://www.freertos.org/RTOS.html).
19//!
20//! # Samples
21//!
22//! Spawning a new task
23//!
24//! ```rust
25//! # use freertos_rs::*;
26//! Task::new().name("hello").stack_size(128).start(|| {
27//! 	loop {
28//! 		println!("Hello world!");
29//! 		CurrentTask::delay(Duration::infinite());
30//! 	}
31//! }).unwrap();
32//!
33//! FreeRtosUtils::start_scheduler();
34//! ```
35//!
36//! Queue
37//!
38//! ```rust
39//! # use freertos_rs::*;
40//! let q = Queue::new(10).unwrap();
41//! q.send(10, Duration::ms(5)).unwrap();
42//! q.receive(Duration::infinite()).unwrap();
43//! ```
44//!
45//! Mutex
46//!
47//! ```rust
48//! # use freertos_rs::*;
49//! let m = Mutex::new(0).unwrap();
50//! {
51//! 	let mut v = m.lock(Duration::infinite()).unwrap();
52//! 	*v += 1;
53//! }
54//! ```
55
56#![no_std]
57#![allow(non_upper_case_globals)]
58#![allow(non_camel_case_types)]
59#![allow(non_snake_case)]
60
61#[macro_use]
62extern crate alloc;
63
64mod hooks;
65mod prelude;
66mod shim;
67
68mod base;
69mod task;
70mod timers;
71mod queue;
72mod semaphore;
73mod mutex;
74mod units;
75mod utils;
76mod isr;
77mod delays;
78mod critical;
79mod allocator;
80
81pub mod patterns;
82
83// Internal stuff that is only public for first Proof of Concept
84pub use crate::base::*;
85pub use crate::shim::*;
86// ----------
87
88pub use crate::base::FreeRtosError;
89pub use crate::task::*;
90pub use crate::queue::*;
91pub use crate::units::*;
92pub use crate::mutex::*;
93pub use crate::semaphore::*;
94pub use crate::isr::*;
95pub use crate::delays::*;
96pub use crate::timers::*;
97pub use crate::critical::*;
98pub use crate::hooks::*;
99pub use crate::allocator::*;
100
101pub use crate::utils::shim_sanity_check;