Skip to content

Commit ac8492b

Browse files
committed
Change from address to offset argument naming, as these are offsets from peripheral base address
1 parent 931eb63 commit ac8492b

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ pub trait ReadStorage {
2424
type Error;
2525

2626
/// Read a slice of data from the storage peripheral, starting the read
27-
/// operation at the given address, and reading until end address
28-
/// (`self.range().1`) or buffer length, whichever comes first.
29-
fn try_read(&mut self, address: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
27+
/// operation at the given address offset, and reading `bytes.len()` bytes.
28+
///
29+
/// This should throw an error in case `bytes.len()` will be larger than
30+
/// `self.capacity()`.
31+
fn try_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
3032

3133
/// The capacity of the storage peripheral in bytes.
3234
fn capacity(&self) -> usize;
@@ -35,13 +37,10 @@ pub trait ReadStorage {
3537
/// Transparent read/write storage trait
3638
pub trait Storage: ReadStorage {
3739
/// Write a slice of data to the storage peripheral, starting the write
38-
/// operation at the given address.
40+
/// operation at the given address offset (between 0 and `self.capacity()`).
3941
///
4042
/// **NOTE:**
4143
/// This function will automatically erase any pages necessary to write the given data,
4244
/// and might as such do RMW operations at an undesirable performance impact.
43-
///
44-
/// CONSIDERATIONS:
45-
/// - Should the address here be normalized (always start from zero?)
46-
fn try_write(&mut self, address: u32, bytes: &[u8]) -> Result<(), Self::Error>;
45+
fn try_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
4746
}

src/nor_flash.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ pub trait ReadNorFlash {
99
const READ_SIZE: usize;
1010

1111
/// Read a slice of data from the storage peripheral, starting the read
12-
/// operation at the given address, and reading `bytes.len()` bytes.
12+
/// operation at the given address offset, and reading `bytes.len()` bytes.
1313
///
1414
/// This should throw an error in case `bytes.len()` will be larger than
1515
/// the peripheral end address.
16-
fn try_read(&mut self, address: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
16+
fn try_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
1717

1818
/// The capacity of the peripheral in bytes.
1919
fn capacity(&self) -> usize;
@@ -41,8 +41,8 @@ pub trait NorFlash: ReadNorFlash {
4141
/// If power is lost during write, the contents of the written words are undefined.
4242
/// The rest of the page is guaranteed to be unchanged.
4343
/// It is not allowed to write to the same word twice.
44-
/// `address` and `bytes.len()` must both be multiples of `write_size()` and properly aligned.
45-
fn try_write(&mut self, address: u32, bytes: &[u8]) -> Result<(), Self::Error>;
44+
/// `offset` and `bytes.len()` must both be multiples of `write_size()` and properly aligned.
45+
fn try_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
4646
}
4747

4848
/// Marker trait for NorFlash relaxing the restrictions on `write`.
@@ -115,9 +115,9 @@ where
115115
{
116116
type Error = S::Error;
117117

118-
fn try_read(&mut self, address: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
118+
fn try_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
119119
// Nothing special to be done for reads
120-
self.storage.try_read(address, bytes)
120+
self.storage.try_read(offset, bytes)
121121
}
122122

123123
fn capacity(&self) -> usize {
@@ -129,15 +129,15 @@ impl<'a, S> Storage for RmwNorFlashStorage<'a, S>
129129
where
130130
S: NorFlash,
131131
{
132-
fn try_write(&mut self, address: u32, bytes: &[u8]) -> Result<(), Self::Error> {
132+
fn try_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
133133
// Perform read/modify/write operations on the byte slice.
134134
let last_page = (self.storage.capacity() / S::ERASE_SIZE) - 1;
135135

136136
// `data` is the part of `bytes` contained within `page`,
137137
// and `addr` in the address offset of `page` + any offset into the page as requested by `address`
138138
for (data, page, addr) in (0..last_page as u32)
139139
.map(move |i| Page::new(i, S::ERASE_SIZE))
140-
.overlaps(bytes, address)
140+
.overlaps(bytes, offset)
141141
{
142142
let offset_into_page = addr.saturating_sub(page.start) as usize;
143143

@@ -188,9 +188,9 @@ where
188188
{
189189
type Error = S::Error;
190190

191-
fn try_read(&mut self, address: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
191+
fn try_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
192192
// Nothing special to be done for reads
193-
self.storage.try_read(address, bytes)
193+
self.storage.try_read(offset, bytes)
194194
}
195195

196196
fn capacity(&self) -> usize {
@@ -202,15 +202,15 @@ impl<'a, S> Storage for RmwMultiwriteNorFlashStorage<'a, S>
202202
where
203203
S: MultiwriteNorFlash,
204204
{
205-
fn try_write(&mut self, address: u32, bytes: &[u8]) -> Result<(), Self::Error> {
205+
fn try_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
206206
// Perform read/modify/write operations on the byte slice.
207207
let last_page = (self.storage.capacity() / S::ERASE_SIZE) - 1;
208208

209209
// `data` is the part of `bytes` contained within `page`,
210210
// and `addr` in the address offset of `page` + any offset into the page as requested by `address`
211211
for (data, page, addr) in (0..last_page as u32)
212212
.map(move |i| Page::new(i, S::ERASE_SIZE))
213-
.overlaps(bytes, address)
213+
.overlaps(bytes, offset)
214214
{
215215
let offset_into_page = addr.saturating_sub(page.start) as usize;
216216

0 commit comments

Comments
 (0)