diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4250bdde9019b4f73b6dff0107eccaf44a24a2f8..6df5b990f09f73a06b83ea81908120e2ffc98437 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 fdbbb6f11f0bd911e8bb1199ba61aabe6e611c26..0adef80c75c06219ef6775e4d24ca9f2896da061 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 96ff770b64f2982de7ae088fbf5ad0f646a68d21..f82d03d649ecbb7a62c5274aa306acd08034c7b6 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 b62bac37b21c77df15804aedcd6d714bd042779f..d6273a460dfe38d75b473a250545467207ffb1f3 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 }