rtic/lib.rs
1//! Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers.
2//!
3//! The user level documentation can be found [here].
4//!
5//! [here]: https://rtic.rs
6//!
7//! Don't forget to check the documentation of the `#[app]` attribute (listed under the reexports
8//! section), which is the main component of the framework.
9//!
10//! # Minimum Supported Rust Version (MSRV)
11//!
12//! This crate is compiled and tested with the latest stable toolchain (rolling).
13//! If you run into compilation errors, try the latest stable release of the rust toolchain.
14//!
15//! # Semantic Versioning
16//!
17//! Like the Rust project, this crate adheres to [SemVer]: breaking changes in the API and semantics
18//! require a *semver bump* (since 1.0.0 a new major version release), with the exception of breaking changes
19//! that fix soundness issues -- those are considered bug fixes and can be landed in a new patch
20//! release.
21//!
22//! [SemVer]: https://semver.org/spec/v2.0.0.html
23
24#![deny(missing_docs)]
25#![deny(rust_2021_compatibility)]
26#![deny(rust_2018_compatibility)]
27#![deny(rust_2018_idioms)]
28#![no_std]
29#![doc(
30 html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg",
31 html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg"
32)]
33#![allow(clippy::inline_always)]
34
35pub use rtic_core::{Exclusive, Mutex, prelude as mutex_prelude};
36pub use rtic_macros::app;
37
38/// module `mutex::prelude` provides `Mutex` and multi-lock variants. Recommended over `mutex_prelude`
39pub mod mutex {
40 pub use rtic_core::Mutex;
41 pub use rtic_core::prelude;
42}
43
44#[doc(hidden)]
45pub mod export;
46
47pub use export::pend;
48
49use core::cell::UnsafeCell;
50
51/// Internal replacement for `static mut T`
52///
53/// Used to represent RTIC Resources
54///
55/// Soundness:
56/// 1) Unsafe API for internal use only
57/// 2) ``get_mut(&self) -> *mut T``
58/// returns a raw mutable pointer to the inner T
59/// casting to &mut T is under control of RTIC
60/// RTIC ensures &mut T to be unique under Rust aliasing rules.
61///
62/// Implementation uses the underlying ``UnsafeCell<T>``
63/// self.0.get() -> *mut T
64///
65/// 3) get(&self) -> *const T
66/// returns a raw immutable (const) pointer to the inner T
67/// casting to &T is under control of RTIC
68/// RTIC ensures &T to be shared under Rust aliasing rules.
69///
70/// Implementation uses the underlying ``UnsafeCell<T>``
71/// self.0.get() -> *mut T, demoted to *const T
72///
73#[repr(transparent)]
74pub struct RacyCell<T>(UnsafeCell<T>);
75
76impl<T> RacyCell<T> {
77 /// Create a ``RacyCell``
78 #[inline(always)]
79 pub const fn new(value: T) -> Self {
80 RacyCell(UnsafeCell::new(value))
81 }
82
83 /// Get `*mut T`
84 ///
85 /// # Safety
86 ///
87 /// See documentation notes for [`RacyCell`]
88 #[inline(always)]
89 pub unsafe fn get_mut(&self) -> *mut T {
90 self.0.get()
91 }
92
93 /// Get `*const T`
94 ///
95 /// # Safety
96 ///
97 /// See documentation notes for [`RacyCell`]
98 #[inline(always)]
99 pub unsafe fn get(&self) -> *const T {
100 self.0.get()
101 }
102}
103
104unsafe impl<T> Sync for RacyCell<T> {}