Multilock support

This commit is contained in:
Emil Fresk 2020-11-14 16:02:36 +01:00
parent 2ebd81fee2
commit 243668df54
7 changed files with 85 additions and 2 deletions

View file

@ -57,7 +57,8 @@ required-features = ["__v7"]
[dependencies] [dependencies]
cortex-m = "0.6.2" cortex-m = "0.6.2"
cortex-m-rtic-macros = { path = "macros", version = "0.6.0-alpha.0" } cortex-m-rtic-macros = { path = "macros", version = "0.6.0-alpha.0" }
rtic-core = "0.3.0" # rtic-core = "0.3.0"
rtic-core = { git = "https://github.com/rtic-rs/rtic-core.git", branch = "multilock", version = "0.3.1" }
cortex-m-rt = "0.6.9" cortex-m-rt = "0.6.9"
heapless = "0.5.0" heapless = "0.5.0"
bare-metal = "1.0.0" bare-metal = "1.0.0"

77
examples/multilock.rs Normal file
View file

@ -0,0 +1,77 @@
//! examples/mutlilock.rs
//!
//! The multi-lock feature example.
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
mod app {
use cortex_m_semihosting::{debug, hprintln};
#[resources]
struct Resources {
#[init(0)]
shared1: u32,
#[init(0)]
shared2: u32,
#[init(0)]
shared3: u32,
}
#[init]
fn init(_: init::Context) -> init::LateResources {
locks::spawn().ok();
init::LateResources {}
}
// when omitted priority is assumed to be `1`
#[task(resources = [shared1, shared2, shared3])]
fn locks(c: locks::Context) {
let mut s1 = c.resources.shared1;
let mut s2 = c.resources.shared2;
let mut s3 = c.resources.shared3;
hprintln!("Multiple single locks").unwrap();
s1.lock(|s1| {
s2.lock(|s2| {
s3.lock(|s3| {
*s1 += 1;
*s2 += 1;
*s3 += 1;
hprintln!(
"Multiple single locks, s1: {}, s2: {}, s3: {}",
*s1,
*s2,
*s3
)
.unwrap();
})
})
});
hprintln!("Multilock!").unwrap();
(s1, s2, s3).lock(|s1, s2, s3| {
*s1 += 1;
*s2 += 1;
*s3 += 1;
hprintln!(
"Multiple single locks, s1: {}, s2: {}, s3: {}",
*s1,
*s2,
*s3
)
.unwrap();
});
debug::exit(debug::EXIT_SUCCESS);
}
}

View file

@ -105,6 +105,7 @@ pub fn codegen(
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn #name(#(#locals_pat,)* #context: #name::Context) { fn #name(#(#locals_pat,)* #context: #name::Context) {
use rtic::Mutex as _; use rtic::Mutex as _;
use rtic::mutex_prelude::*;
#(#stmts)* #(#stmts)*
} }

View file

@ -68,6 +68,7 @@ pub fn codegen(
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn #name(#(#locals_pat,)* #context: #name::Context) -> ! { fn #name(#(#locals_pat,)* #context: #name::Context) -> ! {
use rtic::Mutex as _; use rtic::Mutex as _;
use rtic::mutex_prelude::*;
#(#stmts)* #(#stmts)*
} }

View file

@ -219,6 +219,7 @@ pub fn codegen(
pub fn spawn(#(#args,)*) -> Result<(), #ty> { pub fn spawn(#(#args,)*) -> Result<(), #ty> {
// #let_instant // do we need it? // #let_instant // do we need it?
use rtic::Mutex as _; use rtic::Mutex as _;
use rtic::mutex_prelude::*;
let input = #tupled; let input = #tupled;
@ -258,6 +259,7 @@ pub fn codegen(
) -> Result<(), #ty> { ) -> Result<(), #ty> {
unsafe { unsafe {
use rtic::Mutex as _; use rtic::Mutex as _;
use rtic::mutex_prelude::*;
let input = #tupled; let input = #tupled;
if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) {

View file

@ -111,6 +111,7 @@ pub fn codegen(
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
use rtic::Mutex as _; use rtic::Mutex as _;
use rtic::mutex_prelude::*;
#(#stmts)* #(#stmts)*
} }

View file

@ -43,7 +43,7 @@ use cortex_m::{
}; };
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;
pub use rtic_core::{Exclusive, Mutex}; pub use rtic_core::{Exclusive, Mutex, prelude as mutex_prelude};
#[cfg(armv7m)] #[cfg(armv7m)]
pub mod cyccnt; pub mod cyccnt;