aboutsummaryrefslogtreecommitdiff
path: root/embassy-extras
diff options
context:
space:
mode:
authorLiam Murphy <[email protected]>2021-07-29 15:19:57 +1000
committerLiam Murphy <[email protected]>2021-07-29 15:19:57 +1000
commitcd1a3fcff34943117f446e1afeb9e6d531ee577b (patch)
tree6b3572d8c580a7e968ab59760a8aa51c21969952 /embassy-extras
parentd5ba35424d7eef2cc0c501758d214ce3a6febfc1 (diff)
Don't bother supporting creating a `PeripheralMutex` in an exception handler
Diffstat (limited to 'embassy-extras')
-rw-r--r--embassy-extras/build.rs11
-rw-r--r--embassy-extras/src/peripheral.rs36
2 files changed, 5 insertions, 42 deletions
diff --git a/embassy-extras/build.rs b/embassy-extras/build.rs
deleted file mode 100644
index e3388da26..000000000
--- a/embassy-extras/build.rs
+++ /dev/null
@@ -1,11 +0,0 @@
1use std::env;
2
3fn main() {
4 let target = env::var("TARGET").unwrap();
5
6 if target.starts_with("thumbv6m-") {
7 println!("cargo:rustc-cfg=armv6m");
8 } else if target.starts_with("thumbv8m.") {
9 println!("cargo:rustc-cfg=armv8m");
10 }
11}
diff --git a/embassy-extras/src/peripheral.rs b/embassy-extras/src/peripheral.rs
index 1868edd7d..92512a0f6 100644
--- a/embassy-extras/src/peripheral.rs
+++ b/embassy-extras/src/peripheral.rs
@@ -2,7 +2,7 @@ use core::cell::UnsafeCell;
2use core::marker::{PhantomData, PhantomPinned}; 2use core::marker::{PhantomData, PhantomPinned};
3use core::pin::Pin; 3use core::pin::Pin;
4 4
5use cortex_m::peripheral::scb::{Exception, SystemHandler, VectActive}; 5use cortex_m::peripheral::scb::VectActive;
6use cortex_m::peripheral::{NVIC, SCB}; 6use cortex_m::peripheral::{NVIC, SCB};
7use embassy::interrupt::{Interrupt, InterruptExt}; 7use embassy::interrupt::{Interrupt, InterruptExt};
8 8
@@ -29,40 +29,14 @@ pub struct PeripheralMutex<S: PeripheralState> {
29 _pinned: PhantomPinned, 29 _pinned: PhantomPinned,
30} 30}
31 31
32fn exception_to_system_handler(exception: Exception) -> Option<SystemHandler> {
33 match exception {
34 Exception::NonMaskableInt | Exception::HardFault => None,
35 #[cfg(not(armv6m))]
36 Exception::MemoryManagement => Some(SystemHandler::MemoryManagement),
37 #[cfg(not(armv6m))]
38 Exception::BusFault => Some(SystemHandler::BusFault),
39 #[cfg(not(armv6m))]
40 Exception::UsageFault => Some(SystemHandler::UsageFault),
41 #[cfg(any(armv8m, target_arch = "x86_64"))]
42 Exception::SecureFault => Some(SystemHandler::SecureFault),
43 Exception::SVCall => Some(SystemHandler::SVCall),
44 #[cfg(not(armv6m))]
45 Exception::DebugMonitor => Some(SystemHandler::DebugMonitor),
46 Exception::PendSV => Some(SystemHandler::PendSV),
47 Exception::SysTick => Some(SystemHandler::SysTick),
48 }
49}
50
51/// Whether `irq` can be preempted by the current interrupt. 32/// Whether `irq` can be preempted by the current interrupt.
52pub(crate) fn can_be_preempted(irq: &impl Interrupt) -> bool { 33pub(crate) fn can_be_preempted(irq: &impl Interrupt) -> bool {
53 match SCB::vect_active() { 34 match SCB::vect_active() {
54 // Thread mode can't preempt anything 35 // Thread mode can't preempt anything.
55 VectActive::ThreadMode => false, 36 VectActive::ThreadMode => false,
56 VectActive::Exception(exception) => { 37 // Exceptions don't always preempt interrupts,
57 // `SystemHandler` is a subset of `Exception` for those with configurable priority. 38 // but there isn't much of a good reason to be keeping a `PeripheralMutex` in an exception anyway.
58 // There's no built in way to convert between them, so `exception_to_system_handler` was necessary. 39 VectActive::Exception(_) => true,
59 if let Some(system_handler) = exception_to_system_handler(exception) {
60 SCB::get_priority(system_handler) < irq.get_priority().into()
61 } else {
62 // There's no safe way I know of to maintain `!Send` state across invocations of HardFault or NMI, so that should be fine.
63 false
64 }
65 }
66 VectActive::Interrupt { irqn } => { 40 VectActive::Interrupt { irqn } => {
67 #[derive(Clone, Copy)] 41 #[derive(Clone, Copy)]
68 struct NrWrap(u16); 42 struct NrWrap(u16);