Merge pull request #509 from jorgeig-space/v0.5.x

Use cortex-m `InterruptNumber` instead of bare_metal `Nr`
This commit is contained in:
Emil Fresk 2021-08-19 08:25:59 +02:00 committed by GitHub
commit 90f963e3bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 9 deletions

View file

@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
name = "cortex-m-rtic" name = "cortex-m-rtic"
readme = "README.md" readme = "README.md"
repository = "https://github.com/rtic-rs/cortex-m-rtic" repository = "https://github.com/rtic-rs/cortex-m-rtic"
version = "0.5.7" version = "0.5.8"
[lib] [lib]
name = "rtic" name = "rtic"
@ -51,12 +51,21 @@ name = "types"
required-features = ["__v7"] required-features = ["__v7"]
[dependencies] [dependencies]
cortex-m = "0.6.2"
cortex-m-rtic-macros = { path = "macros", version = "0.5.3" } cortex-m-rtic-macros = { path = "macros", version = "0.5.3" }
rtic-core = "0.3.0" rtic-core = "0.3.0"
cortex-m-rt = "0.6.9" cortex-m-rt = "0.6.9"
heapless = "0.6.1" heapless = "0.6.1"
[dependencies.cortex-m]
package = "cortex-m"
version = "0.6.2"
optional = true
[dependencies.cortex-m-7]
package = "cortex-m"
version = "0.7.3"
optional = true
[build-dependencies] [build-dependencies]
version_check = "0.9" version_check = "0.9"
@ -65,7 +74,9 @@ optional = true
version = "0.1.0-alpha.2" version = "0.1.0-alpha.2"
[dev-dependencies] [dev-dependencies]
lm3s6965 = "0.1.3" # The difference between this git version and the crates.io version is that this version implements Copy & Clone on Interrupt
# which is needed for the cortex-m-7 feature (to use InterruptNumber instead of Nr on interrups)
lm3s6965 = { git = "https://github.com/japaric/lm3s6965.git", version= "0.1.3", rev = "facf63aa0169c773175a143f6014a1d0977fb74f" }
cortex-m-semihosting = "0.3.3" cortex-m-semihosting = "0.3.3"
[dev-dependencies.panic-semihosting] [dev-dependencies.panic-semihosting]
@ -76,6 +87,7 @@ version = "0.5.2"
trybuild = "1" trybuild = "1"
[features] [features]
default = ["cortex-m"]
heterogeneous = ["cortex-m-rtic-macros/heterogeneous", "microamp"] heterogeneous = ["cortex-m-rtic-macros/heterogeneous", "microamp"]
homogeneous = ["cortex-m-rtic-macros/homogeneous"] homogeneous = ["cortex-m-rtic-macros/homogeneous"]
# used for testing this crate; do not use in applications # used for testing this crate; do not use in applications

View file

@ -7,12 +7,17 @@ publish = false
version = "0.0.0-alpha.0" version = "0.0.0-alpha.0"
[dependencies] [dependencies]
bare-metal = "0.2.4" cortex-m = { version = "0.7.3", optional = true }
bare-metal = { version = "0.2.4", optional = true }
[dependencies.cortex-m-rtic] [dependencies.cortex-m-rtic]
path = ".." path = ".."
features = ["heterogeneous"] features = ["heterogeneous"]
[features]
default = ["bare-metal"]
cortex-m-7 = ["cortex-m"]
[dev-dependencies] [dev-dependencies]
panic-halt = "0.2.0" panic-halt = "0.2.0"
microamp = "0.1.0-alpha.1" microamp = "0.1.0-alpha.1"

View file

@ -7,7 +7,10 @@ use core::{
ops::{Add, Sub}, ops::{Add, Sub},
}; };
#[cfg(feature = "bare-metal")]
use bare_metal::Nr; use bare_metal::Nr;
#[cfg(feature = "cortex-m-7")]
use cortex_m::interrupt::InterruptNumber;
use rtic::{Fraction, Monotonic, MultiCore}; use rtic::{Fraction, Monotonic, MultiCore};
// both cores have the exact same interrupts // both cores have the exact same interrupts
@ -16,7 +19,10 @@ pub use Interrupt_0 as Interrupt_1;
// Fake priority bits // Fake priority bits
pub const NVIC_PRIO_BITS: u8 = 3; pub const NVIC_PRIO_BITS: u8 = 3;
#[cfg(feature = "bare-metal")]
pub fn xpend(_core: u8, _interrupt: impl Nr) {} pub fn xpend(_core: u8, _interrupt: impl Nr) {}
#[cfg(feature = "cortex-m-7")]
pub fn xpend(_core: u8, _interrupt: impl InterruptNumber) {}
/// Fake monotonic timer /// Fake monotonic timer
pub struct MT; pub struct MT;
@ -92,8 +98,16 @@ pub enum Interrupt_0 {
I7 = 7, I7 = 7,
} }
#[cfg(feature = "bare-metal")]
unsafe impl Nr for Interrupt_0 { unsafe impl Nr for Interrupt_0 {
fn nr(&self) -> u8 { fn nr(&self) -> u8 {
*self as u8 *self as u8
} }
} }
#[cfg(feature = "cortex-m-7")]
unsafe impl InterruptNumber for Interrupt_0 {
fn number(self) -> u16 {
self as u16
}
}

View file

@ -7,11 +7,16 @@ publish = false
version = "0.0.0-alpha.0" version = "0.0.0-alpha.0"
[dependencies] [dependencies]
bare-metal = "0.2.4" cortex-m = { version = "0.7.3", optional = true }
bare-metal = { version = "0.2.4", optional = true }
[dependencies.cortex-m-rtic] [dependencies.cortex-m-rtic]
path = ".." path = ".."
features = ["homogeneous"] features = ["homogeneous"]
[features]
default = ["bare-metal"]
cortex-m-7 = ["cortex-m"]
[dev-dependencies] [dev-dependencies]
panic-halt = "0.2.0" panic-halt = "0.2.0"

View file

@ -7,7 +7,10 @@ use core::{
ops::{Add, Sub}, ops::{Add, Sub},
}; };
#[cfg(feature = "bare-metal")]
use bare_metal::Nr; use bare_metal::Nr;
#[cfg(feature = "cortex-m-7")]
use cortex_m::interrupt::InterruptNumber;
use rtic::{Fraction, Monotonic, MultiCore}; use rtic::{Fraction, Monotonic, MultiCore};
// both cores have the exact same interrupts // both cores have the exact same interrupts
@ -16,7 +19,10 @@ pub use Interrupt_0 as Interrupt_1;
// Fake priority bits // Fake priority bits
pub const NVIC_PRIO_BITS: u8 = 3; pub const NVIC_PRIO_BITS: u8 = 3;
#[cfg(feature = "bare-metal")]
pub fn xpend(_core: u8, _interrupt: impl Nr) {} pub fn xpend(_core: u8, _interrupt: impl Nr) {}
#[cfg(feature = "cortex-m-7")]
pub fn xpend(_core: u8, _interrupt: impl InterruptNumber) {}
/// Fake monotonic timer /// Fake monotonic timer
pub struct MT; pub struct MT;
@ -92,8 +98,16 @@ pub enum Interrupt_0 {
I7 = 7, I7 = 7,
} }
#[cfg(feature = "bare-metal")]
unsafe impl Nr for Interrupt_0 { unsafe impl Nr for Interrupt_0 {
fn nr(&self) -> u8 { fn nr(&self) -> u8 {
*self as u8 *self as u8
} }
} }
#[cfg(feature = "cortex-m-7")]
unsafe impl InterruptNumber for Interrupt_0 {
fn number(self) -> u16 {
self as u16
}
}

View file

@ -44,10 +44,15 @@
use core::ops::Sub; use core::ops::Sub;
use cortex_m::{ #[cfg(feature = "cortex-m")]
interrupt::Nr, use cortex_m::interrupt::Nr;
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
}; #[cfg(feature = "cortex-m-7")]
extern crate cortex_m_7 as cortex_m;
#[cfg(feature = "cortex-m-7")]
use cortex_m::interrupt::InterruptNumber;
use cortex_m::peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU};
#[cfg(all(not(feature = "heterogeneous"), not(feature = "homogeneous")))] #[cfg(all(not(feature = "heterogeneous"), not(feature = "homogeneous")))]
use cortex_m_rt as _; // vector table use cortex_m_rt as _; // vector table
pub use cortex_m_rtic_macros::app; pub use cortex_m_rtic_macros::app;
@ -168,9 +173,22 @@ pub trait MultiCore {}
/// ///
/// This is a convenience function around /// This is a convenience function around
/// [`NVIC::pend`](../cortex_m/peripheral/struct.NVIC.html#method.pend) /// [`NVIC::pend`](../cortex_m/peripheral/struct.NVIC.html#method.pend)
#[cfg(feature = "cortex-m")]
pub fn pend<I>(interrupt: I) pub fn pend<I>(interrupt: I)
where where
I: Nr, I: Nr,
{ {
NVIC::pend(interrupt) NVIC::pend(interrupt)
} }
/// Sets the given `interrupt` as pending
///
/// This is a convenience function around
/// [`NVIC::pend`](../cortex_m/peripheral/struct.NVIC.html#method.pend)
#[cfg(feature = "cortex-m-7")]
pub fn pend<I>(interrupt: I)
where
I: InterruptNumber,
{
NVIC::pend(interrupt)
}