Expose get_sector in favor of is_eraseable_range

This commit is contained in:
Rasmus Melchior Jacobsen
2023-03-29 12:49:13 +02:00
parent 4ee3d15519
commit 69944675a3
7 changed files with 81 additions and 57 deletions

View File

@ -104,7 +104,7 @@ impl<'d> Flash<'d> {
let start_address = FLASH_BASE as u32 + from;
let end_address = FLASH_BASE as u32 + to;
if !family::is_eraseable_range(start_address, end_address) {
if !is_eraseable_range(start_address, end_address) {
return Err(Error::Unaligned);
}
trace!("Erasing from 0x{:x} to 0x{:x}", start_address, end_address);
@ -193,6 +193,18 @@ pub trait FlashRegion {
}
}
fn is_eraseable_range(start_address: u32, end_address: u32) -> bool {
let mut address = start_address;
while address < end_address {
let sector = family::get_sector(address);
if sector.start != address {
return false;
}
address += sector.size;
}
address == end_address
}
fn take_lock_spin() -> MutexGuard<'static, CriticalSectionRawMutex, ()> {
loop {
if let Ok(guard) = REGION_LOCK.try_lock() {