2021-12-25 17:59:19 +01:00
|
|
|
//! Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers.
|
2019-04-21 20:02:59 +02:00
|
|
|
//!
|
2020-06-11 19:18:29 +02:00
|
|
|
//! **IMPORTANT**: This crate is published as [`cortex-m-rtic`] on crates.io but the name of the
|
|
|
|
//! library is `rtic`.
|
2017-07-21 05:53:44 +02:00
|
|
|
//!
|
2020-06-11 19:18:29 +02:00
|
|
|
//! [`cortex-m-rtic`]: https://crates.io/crates/cortex-m-rtic
|
2017-07-21 05:53:44 +02:00
|
|
|
//!
|
2018-11-03 17:02:41 +01:00
|
|
|
//! The user level documentation can be found [here].
|
2017-07-21 05:53:44 +02:00
|
|
|
//!
|
2020-06-11 19:18:29 +02:00
|
|
|
//! [here]: https://rtic.rs
|
2017-07-21 05:53:44 +02:00
|
|
|
//!
|
2019-08-21 12:19:38 +02:00
|
|
|
//! Don't forget to check the documentation of the `#[app]` attribute (listed under the reexports
|
|
|
|
//! section), which is the main component of the framework.
|
2017-07-21 05:53:44 +02:00
|
|
|
//!
|
2019-02-12 11:08:39 +01:00
|
|
|
//! # Minimum Supported Rust Version (MSRV)
|
|
|
|
//!
|
2021-12-25 18:15:41 +01:00
|
|
|
//! This crate is compiled and tested with the latest toolchain (rolling) as of the release date.
|
|
|
|
//! If you run into compilation errors, try the latest stable release of the rust toolchain.
|
2019-02-12 11:08:39 +01:00
|
|
|
//!
|
|
|
|
//! # Semantic Versioning
|
|
|
|
//!
|
|
|
|
//! Like the Rust project, this crate adheres to [SemVer]: breaking changes in the API and semantics
|
2021-12-25 18:15:41 +01:00
|
|
|
//! require a *semver bump* (since 1.0.0 a new major version release), with the exception of breaking changes
|
2019-02-12 11:08:39 +01:00
|
|
|
//! that fix soundness issues -- those are considered bug fixes and can be landed in a new patch
|
|
|
|
//! release.
|
|
|
|
//!
|
|
|
|
//! [SemVer]: https://semver.org/spec/v2.0.0.html
|
2018-11-03 17:02:41 +01:00
|
|
|
|
2017-07-21 05:53:44 +02:00
|
|
|
#![deny(missing_docs)]
|
2021-12-25 13:10:10 +01:00
|
|
|
#![deny(rust_2021_compatibility)]
|
2019-06-13 23:56:59 +02:00
|
|
|
#![deny(rust_2018_compatibility)]
|
|
|
|
#![deny(rust_2018_idioms)]
|
2017-03-05 06:26:14 +01:00
|
|
|
#![no_std]
|
2021-11-25 10:04:37 +01:00
|
|
|
#![doc(
|
|
|
|
html_logo_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg",
|
|
|
|
html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg"
|
|
|
|
)]
|
2021-11-25 10:46:29 +01:00
|
|
|
//deny_warnings_placeholder_for_ci
|
2017-03-05 06:26:14 +01:00
|
|
|
|
2021-02-06 21:34:16 +01:00
|
|
|
use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC};
|
2020-06-11 19:18:29 +02:00
|
|
|
pub use cortex_m_rtic_macros::app;
|
2021-02-18 19:30:59 +01:00
|
|
|
pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex};
|
2021-10-31 10:09:40 +01:00
|
|
|
pub use rtic_monotonic::{self, Monotonic};
|
2018-11-03 17:02:41 +01:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub mod export;
|
2017-09-22 13:45:28 +02:00
|
|
|
#[doc(hidden)]
|
2018-11-03 17:02:41 +01:00
|
|
|
mod tq;
|
2017-09-22 13:45:28 +02:00
|
|
|
|
2018-11-03 17:02:41 +01:00
|
|
|
/// Sets the given `interrupt` as pending
|
2017-07-25 05:46:29 +02:00
|
|
|
///
|
2018-11-03 17:02:41 +01:00
|
|
|
/// This is a convenience function around
|
|
|
|
/// [`NVIC::pend`](../cortex_m/peripheral/struct.NVIC.html#method.pend)
|
|
|
|
pub fn pend<I>(interrupt: I)
|
2017-07-07 06:25:29 +02:00
|
|
|
where
|
2020-12-30 00:08:06 +01:00
|
|
|
I: InterruptNumber,
|
2017-07-07 06:25:29 +02:00
|
|
|
{
|
2018-11-03 17:02:41 +01:00
|
|
|
NVIC::pend(interrupt)
|
2017-07-07 06:25:29 +02:00
|
|
|
}
|
2021-04-08 18:25:09 +02:00
|
|
|
|
|
|
|
use core::cell::UnsafeCell;
|
|
|
|
|
|
|
|
/// Internal replacement for `static mut T`
|
2021-11-02 19:47:14 +01:00
|
|
|
///
|
|
|
|
/// Used to represent RTIC Resources
|
|
|
|
///
|
|
|
|
/// Soundness:
|
|
|
|
/// 1) Unsafe API for internal use only
|
|
|
|
/// 2) get_mut(&self) -> *mut T
|
|
|
|
/// returns a raw mutable pointer to the inner T
|
|
|
|
/// casting to &mut T is under control of RTIC
|
|
|
|
/// RTIC ensures &mut T to be unique under Rust aliasing rules.
|
|
|
|
///
|
|
|
|
/// Implementation uses the underlying UnsafeCell<T>
|
|
|
|
/// self.0.get() -> *mut T
|
|
|
|
///
|
|
|
|
/// 3) get(&self) -> *const T
|
|
|
|
/// returns a raw immutable (const) pointer to the inner T
|
|
|
|
/// casting to &T is under control of RTIC
|
|
|
|
/// RTIC ensures &T to be shared under Rust aliasing rules.
|
|
|
|
///
|
|
|
|
/// Implementation uses the underlying UnsafeCell<T>
|
|
|
|
/// self.0.get() -> *mut T, demoted to *const T
|
|
|
|
///
|
2021-04-08 18:25:09 +02:00
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct RacyCell<T>(UnsafeCell<T>);
|
|
|
|
|
|
|
|
impl<T> RacyCell<T> {
|
|
|
|
/// Create a RacyCell
|
|
|
|
#[inline(always)]
|
|
|
|
pub const fn new(value: T) -> Self {
|
|
|
|
RacyCell(UnsafeCell::new(value))
|
|
|
|
}
|
|
|
|
|
2021-11-02 13:41:12 +01:00
|
|
|
/// Get `*mut T`
|
2021-12-25 13:17:16 +01:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// See documentation notes for [`RacyCell`]
|
2021-04-08 18:25:09 +02:00
|
|
|
#[inline(always)]
|
2021-11-02 13:41:12 +01:00
|
|
|
pub unsafe fn get_mut(&self) -> *mut T {
|
|
|
|
self.0.get()
|
2021-04-08 18:25:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 13:41:12 +01:00
|
|
|
/// Get `*const T`
|
2021-12-25 13:17:16 +01:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// See documentation notes for [`RacyCell`]
|
2021-04-08 18:25:09 +02:00
|
|
|
#[inline(always)]
|
2021-11-02 13:41:12 +01:00
|
|
|
pub unsafe fn get(&self) -> *const T {
|
|
|
|
self.0.get()
|
2021-04-08 18:25:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<T> Sync for RacyCell<T> {}
|