diff options
| author | Liam Murphy <[email protected]> | 2021-07-29 15:19:57 +1000 |
|---|---|---|
| committer | Liam Murphy <[email protected]> | 2021-07-29 15:19:57 +1000 |
| commit | cd1a3fcff34943117f446e1afeb9e6d531ee577b (patch) | |
| tree | 6b3572d8c580a7e968ab59760a8aa51c21969952 /embassy-extras | |
| parent | d5ba35424d7eef2cc0c501758d214ce3a6febfc1 (diff) | |
Don't bother supporting creating a `PeripheralMutex` in an exception handler
Diffstat (limited to 'embassy-extras')
| -rw-r--r-- | embassy-extras/build.rs | 11 | ||||
| -rw-r--r-- | embassy-extras/src/peripheral.rs | 36 |
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 @@ | |||
| 1 | use std::env; | ||
| 2 | |||
| 3 | fn 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; | |||
| 2 | use core::marker::{PhantomData, PhantomPinned}; | 2 | use core::marker::{PhantomData, PhantomPinned}; |
| 3 | use core::pin::Pin; | 3 | use core::pin::Pin; |
| 4 | 4 | ||
| 5 | use cortex_m::peripheral::scb::{Exception, SystemHandler, VectActive}; | 5 | use cortex_m::peripheral::scb::VectActive; |
| 6 | use cortex_m::peripheral::{NVIC, SCB}; | 6 | use cortex_m::peripheral::{NVIC, SCB}; |
| 7 | use embassy::interrupt::{Interrupt, InterruptExt}; | 7 | use 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 | ||
| 32 | fn 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. |
| 52 | pub(crate) fn can_be_preempted(irq: &impl Interrupt) -> bool { | 33 | pub(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); |
