Skip to content

Commit

Permalink
Relax the MultiwriteNorFlash to only need clearing of words
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Aug 4, 2024
1 parent 163dfc5 commit 259cfc6
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub(crate) trait PrivateCacheImpl: Invalidate {
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
) {
self.mark_dirty();
self.page_pointers()
Expand All @@ -108,7 +108,7 @@ pub(crate) trait PrivateCacheImpl: Invalidate {
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
) {
self.mark_dirty();
self.page_pointers()
Expand Down
16 changes: 8 additions & 8 deletions src/cache/page_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub(crate) trait PagePointersCache: Debug {
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
);
fn notice_item_erased<S: NorFlash>(
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
);

fn notice_page_state(&mut self, page_index: usize, new_state: PageState);
Expand Down Expand Up @@ -89,11 +89,11 @@ impl<const PAGE_COUNT: usize> PagePointersCache for CachedPagePointers<PAGE_COUN
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
) {
let page_index = calculate_page_index::<S>(flash_range, item_address);

let next_item_address = item_header.next_item_address::<S>(item_address);
let next_item_address = item_header.next_item_address(item_address);

// We only care about the furthest written item, so discard if this is an earlier item
if let Some(first_item_after_written) = self.first_item_after_written(page_index) {
Expand All @@ -109,7 +109,7 @@ impl<const PAGE_COUNT: usize> PagePointersCache for CachedPagePointers<PAGE_COUN
&mut self,
flash_range: Range<u32>,
item_address: u32,
item_header: &ItemHeader,
item_header: &ItemHeader<S>,
) {
let page_index = calculate_page_index::<S>(flash_range.clone(), item_address);

Expand All @@ -120,7 +120,7 @@ impl<const PAGE_COUNT: usize> PagePointersCache for CachedPagePointers<PAGE_COUN

if item_address == next_unerased_item {
self.after_erased_pointers[page_index] =
NonZeroU32::new(item_header.next_item_address::<S>(item_address));
NonZeroU32::new(item_header.next_item_address(item_address));
}
}

Expand Down Expand Up @@ -155,15 +155,15 @@ impl PagePointersCache for UncachedPagePointers {
&mut self,
_flash_range: Range<u32>,
_item_address: u32,
_item_header: &ItemHeader,
_item_header: &ItemHeader<S>,
) {
}

fn notice_item_erased<S: NorFlash>(
&mut self,
_flash_range: Range<u32>,
_item_address: u32,
_item_header: &ItemHeader,
_item_header: &ItemHeader<S>,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/cache/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod queue_tests {
reads: 594934,
writes: 6299,
bytes_read: 2766058,
bytes_written: 53299
bytes_written: 45299,
}
);
}
Expand All @@ -37,7 +37,7 @@ mod queue_tests {
reads: 308740,
writes: 6299,
bytes_read: 2479864,
bytes_written: 53299
bytes_written: 45299
}
);
}
Expand All @@ -51,7 +51,7 @@ mod queue_tests {
reads: 211172,
writes: 6299,
bytes_read: 1699320,
bytes_written: 53299
bytes_written: 45299
}
);
}
Expand Down
Loading

0 comments on commit 259cfc6

Please sign in to comment.