From 9a828b83e60c1f69bd2b379432f1b8ce5d9caaa3 Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Fri, 17 Nov 2017 22:03:16 +0100 Subject: [PATCH] did not work out --- .vscode/tasks.json | 12 ++++++++++++ examples/nested.rs | 2 ++ macros/src/trans.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4250bdd..6df5b99 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -39,6 +39,18 @@ "$rustc" ] }, + { + "label": "xargo build --release --example nested_noread", + "type": "shell", + "command": "xargo build --features \"wcet_bkpt\" --example nested_noread", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + "$rustc" + ] + }, { "label": "xargo build --release --example nested --features wcet_bkpt", "type": "shell", diff --git a/examples/nested.rs b/examples/nested.rs index fdbbb6f..0adef80 100644 --- a/examples/nested.rs +++ b/examples/nested.rs @@ -122,11 +122,13 @@ fn exti0( rtfm::bkpt(); } +#[inline(never)] fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { // C, J rtfm::bkpt(); } +#[inline(never)] fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) { // E, H rtfm::bkpt(); diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 96ff770..f82d03d 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -427,6 +427,27 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { ) } } + + fn claim_mut_noread<R, F>( + &mut self, + t: &mut #krate::Threshold, + f: F, + ) -> R + where + F: FnOnce( + &mut #krate::Static<#ty>, + &mut #krate::Threshold) -> R + { + unsafe { + #krate::claim_noread( + #krate::Static::ref_mut(&mut #res_rvalue), + #ceiling, + #device::NVIC_PRIO_BITS, + t, + f, + ) + } + } }); } else { impl_items.push(quote! { @@ -501,6 +522,30 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { ) } } + + thueothueoa + fn claim_mut_noread<R, F>( + &mut self, + t: &mut #krate::Threshold, + f: F, + ) -> R + where + F: FnOnce( + &mut #krate::Static<#device::#name>, + &mut #krate::Threshold) -> R + { + unsafe { + #krate::claim_noread( + #krate::Static::ref_mut( + &mut *#device::#name.get(), + ), + #ceiling, + #device::NVIC_PRIO_BITS, + t, + f, + ) + } + } }); } diff --git a/src/lib.rs b/src/lib.rs index b62bac3..d6273a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,9 +142,50 @@ where basepri::write(hw); if cfg!(feature = "wcet_bkpt") {bkpt();} else {nop();} + let ret = f(data, &mut Threshold::new(ceiling)); + if cfg!(feature = "wcet_bkpt") {bkpt();} else {nop();} + basepri::write(old); + ret + } + } + } + } else { + f(data, t) + } +} + +#[inline] +#[doc(hidden)] +pub unsafe fn claim_noread<T, R, F>( + data: T, + ceiling: u8, + _nvic_prio_bits: u8, + t: &mut Threshold, + f: F, +) -> R +where + F: FnOnce(T, &mut Threshold) -> R, +{ + if ceiling > t.value() { + match () { + #[cfg(armv6m)] + () => atomic(t, |t| f(data, t)), + + #[cfg(not(armv6m))] + () => { + let max_priority = 1 << _nvic_prio_bits; + + if ceiling == max_priority { + atomic(t, |t| f(data, t)) + } else { + //let old = basepri::read(); + let hw = (max_priority - ceiling) << (8 - _nvic_prio_bits); + basepri::write(hw); + if cfg!(feature = "wcet_bkpt") {bkpt();} else {nop();} let ret = f(data, &mut Threshold::new(ceiling)); if cfg!(feature = "wcet_bkpt") {bkpt();} else {nop();} + let old = (max_priority - t.value()) << (8 - _nvic_prio_bits); basepri::write(old); ret } -- GitLab