freertos_next/
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_next::*;
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_next::*;
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_next::*;
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 = "sync")]
79mod event_group;
80#[cfg(feature = "interrupt")]
81mod isr;
82#[cfg(feature = "sync")]
83mod mutex;
84#[cfg(cortex_m)]
85mod os_traits_impls;
86#[cfg(feature = "sync")]
87mod queue;
88#[cfg(feature = "sync")]
89mod semaphore;
90#[cfg(any(feature = "time", feature = "sync"))]
91mod task;
92#[cfg(feature = "time")]
93mod timers;
94#[cfg(any(feature = "time", feature = "sync"))]
95mod units;
96mod utils;
97
98#[cfg(feature = "sync")]
99pub mod patterns;
100
101// Internal stuff that is only public for first Proof of Concept
102pub use crate::base::*;
103pub use crate::shim::*;
104// ----------
105
106#[cfg(feature = "allocator")]
107pub use crate::allocator::*;
108pub use crate::base::FreeRtosError;
109#[cfg(feature = "sync")]
110pub use crate::critical::*;
111#[cfg(feature = "time")]
112pub use crate::delays::*;
113#[cfg(feature = "sync")]
114pub use crate::event_group::*;
115#[cfg(feature = "hooks")]
116pub use crate::hooks::*;
117#[cfg(feature = "interrupt")]
118pub use crate::isr::*;
119#[cfg(feature = "sync")]
120pub use crate::mutex::*;
121#[cfg(cortex_m)]
122pub use crate::os_traits_impls::*;
123#[cfg(feature = "sync")]
124pub use crate::queue::*;
125#[cfg(feature = "sync")]
126pub use crate::semaphore::*;
127#[cfg(any(feature = "time", feature = "sync"))]
128pub use crate::task::*;
129#[cfg(feature = "time")]
130pub use crate::timers::*;
131#[cfg(any(feature = "time", feature = "sync"))]
132pub use crate::units::*;
133#[cfg(feature = "cpu_clock")]
134pub use crate::utils::cpu_clock_hz;
135pub use crate::utils::shim_sanity_check;