Don't bother supporting creating a PeripheralMutex in an exception handler

This commit is contained in:
Liam Murphy 2021-07-29 15:19:57 +10:00
parent d5ba35424d
commit cd1a3fcff3
2 changed files with 5 additions and 42 deletions

View File

@ -1,11 +0,0 @@
use std::env;
fn main() {
let target = env::var("TARGET").unwrap();
if target.starts_with("thumbv6m-") {
println!("cargo:rustc-cfg=armv6m");
} else if target.starts_with("thumbv8m.") {
println!("cargo:rustc-cfg=armv8m");
}
}

View File

@ -2,7 +2,7 @@ use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned}; use core::marker::{PhantomData, PhantomPinned};
use core::pin::Pin; use core::pin::Pin;
use cortex_m::peripheral::scb::{Exception, SystemHandler, VectActive}; use cortex_m::peripheral::scb::VectActive;
use cortex_m::peripheral::{NVIC, SCB}; use cortex_m::peripheral::{NVIC, SCB};
use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::interrupt::{Interrupt, InterruptExt};
@ -29,40 +29,14 @@ pub struct PeripheralMutex<S: PeripheralState> {
_pinned: PhantomPinned, _pinned: PhantomPinned,
} }
fn exception_to_system_handler(exception: Exception) -> Option<SystemHandler> {
match exception {
Exception::NonMaskableInt | Exception::HardFault => None,
#[cfg(not(armv6m))]
Exception::MemoryManagement => Some(SystemHandler::MemoryManagement),
#[cfg(not(armv6m))]
Exception::BusFault => Some(SystemHandler::BusFault),
#[cfg(not(armv6m))]
Exception::UsageFault => Some(SystemHandler::UsageFault),
#[cfg(any(armv8m, target_arch = "x86_64"))]
Exception::SecureFault => Some(SystemHandler::SecureFault),
Exception::SVCall => Some(SystemHandler::SVCall),
#[cfg(not(armv6m))]
Exception::DebugMonitor => Some(SystemHandler::DebugMonitor),
Exception::PendSV => Some(SystemHandler::PendSV),
Exception::SysTick => Some(SystemHandler::SysTick),
}
}
/// Whether `irq` can be preempted by the current interrupt. /// Whether `irq` can be preempted by the current interrupt.
pub(crate) fn can_be_preempted(irq: &impl Interrupt) -> bool { pub(crate) fn can_be_preempted(irq: &impl Interrupt) -> bool {
match SCB::vect_active() { match SCB::vect_active() {
// Thread mode can't preempt anything // Thread mode can't preempt anything.
VectActive::ThreadMode => false, VectActive::ThreadMode => false,
VectActive::Exception(exception) => { // Exceptions don't always preempt interrupts,
// `SystemHandler` is a subset of `Exception` for those with configurable priority. // but there isn't much of a good reason to be keeping a `PeripheralMutex` in an exception anyway.
// There's no built in way to convert between them, so `exception_to_system_handler` was necessary. VectActive::Exception(_) => true,
if let Some(system_handler) = exception_to_system_handler(exception) {
SCB::get_priority(system_handler) < irq.get_priority().into()
} else {
// There's no safe way I know of to maintain `!Send` state across invocations of HardFault or NMI, so that should be fine.
false
}
}
VectActive::Interrupt { irqn } => { VectActive::Interrupt { irqn } => {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct NrWrap(u16); struct NrWrap(u16);