Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to new rtfm-core with mutex trait and common parts #304

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- [breaking-change] Now using new `mutex-trait` in `rtfm-core`
- [breaking-change] Common parts moved to `rtfm-core`

## [v0.5.1] - 2019-11-19
- Fixed arithmetic wrapping bug in src/cyccntr.rs
elapsed and duration could cause an internal overflow trap
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ required-features = ["__v7"]
[dependencies]
cortex-m = "0.6.2"
cortex-m-rtfm-macros = { path = "macros", version = "0.5.0" }
rtfm-core = "0.3.0"
rtfm-core = "0.4.0"
cortex-m-rt = "0.6.9"
heapless = "0.5.0"

Expand Down
4 changes: 2 additions & 2 deletions examples/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const APP: () = {
*c.resources.shared += 0;

// second argument has type `Exclusive<u32>`
advance(STATE, Exclusive(c.resources.shared));
advance(STATE, Exclusive::new(c.resources.shared));
}
};

// the second parameter is generic: it can be any type that implements the `Mutex` trait
fn advance(state: &mut u32, mut shared: impl Mutex<T = u32>) {
fn advance(state: &mut u32, mut shared: impl Mutex<Data = u32>) {
*state += 1;

let (old, new) = shared.lock(|shared: &mut u32| {
Expand Down
2 changes: 1 addition & 1 deletion macros/src/codegen/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn impl_mutex(
#(#cfgs)*
#cfg_core
impl<'a> rtfm::Mutex for #path<'a> {
type T = #ty;
type Data = #ty;

#[inline(always)]
fn lock<R>(&mut self, f: impl FnOnce(&mut #ty) -> R) -> R {
Expand Down
51 changes: 1 addition & 50 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@
#![deny(warnings)]
#![no_std]

use core::ops::Sub;

use cortex_m::{
interrupt::Nr,
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
};
#[cfg(all(not(feature = "heterogeneous"), not(feature = "homogeneous")))]
use cortex_m_rt as _; // vector table
pub use cortex_m_rtfm_macros::app;
pub use rtfm_core::{Exclusive, Mutex};
pub use rtfm_core::{Exclusive, Mutex, Fraction, Monotonic, MultiCore};

#[cfg(armv7m)]
pub mod cyccnt;
Expand Down Expand Up @@ -117,53 +115,6 @@ impl From<cortex_m::Peripherals> for Peripherals {
}
}

/// A fraction
pub struct Fraction {
/// The numerator
pub numerator: u32,

/// The denominator
pub denominator: u32,
}

/// A monotonic clock / counter
pub trait Monotonic {
/// A measurement of this clock, use `CYCCNT` as a reference implementation for `Instant`.
/// Note that the Instant must be a signed value such as `i32`.
type Instant: Copy + Ord + Sub;

/// The ratio between the system timer (SysTick) frequency and this clock frequency, i.e.
/// `Monotonic clock * Fraction = System clock`
///
/// The ratio must be expressed in *reduced* `Fraction` form to prevent overflows. That is
/// `2 / 3` instead of `4 / 6`
fn ratio() -> Fraction;

/// Returns the current time
///
/// # Correctness
///
/// This function is *allowed* to return nonsensical values if called before `reset` is invoked
/// by the runtime. Therefore application authors should *not* call this function during the
/// `#[init]` phase.
fn now() -> Self::Instant;

/// Resets the counter to *zero*
///
/// # Safety
///
/// This function will be called *exactly once* by the RTFM runtime after `#[init]` returns and
/// before tasks can start; this is also the case in multi-core applications. User code must
/// *never* call this function.
unsafe fn reset();

/// A `Self::Instant` that represents a count of *zero*
fn zero() -> Self::Instant;
}

/// A marker trait that indicates that it is correct to use this type in multi-core context
pub trait MultiCore {}

/// Sets the given `interrupt` as pending
///
/// This is a convenience function around
Expand Down