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