Move new async to asynch module to guard for models without flash interrupt

This commit is contained in:
Rasmus Melchior Jacobsen
2023-05-25 23:51:10 +02:00
parent 74104aafda
commit e08267df54
9 changed files with 36 additions and 55 deletions

View File

@ -1,5 +1,9 @@
use core::marker::PhantomData;
use atomic_polyfill::{fence, Ordering};
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::into_ref;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::mutex::Mutex;
@ -7,10 +11,28 @@ use super::{
blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE,
MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE,
};
use crate::peripherals::FLASH;
use crate::{interrupt, Peripheral};
pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
impl<'d> Flash<'d, Async> {
pub fn new(
p: impl Peripheral<P = FLASH> + 'd,
_irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
) -> Self {
into_ref!(p);
let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
flash_irq.unpend();
flash_irq.enable();
Self {
inner: p,
_mode: PhantomData,
}
}
pub fn into_regions(self) -> FlashLayout<'d, Async> {
family::set_default_layout();
FlashLayout::new(self.inner)
@ -25,6 +47,15 @@ impl<'d> Flash<'d, Async> {
}
}
/// Interrupt handler
pub struct InterruptHandler;
impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
unsafe fn on_interrupt() {
family::on_interrupt();
}
}
impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> {
const READ_SIZE: usize = READ_SIZE;