freertos_rust/
lib.rs

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