From: Tilman Sauerbeck Date: Tue, 11 Feb 2020 18:54:06 +0000 (+0100) Subject: common: Implement Storage::erase() in Mx25l. X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=c42a04101a5635fb7557ebdf7b5c7f2dbcb12b54;p=gps-watch.git common: Implement Storage::erase() in Mx25l. --- diff --git a/src/common/mx25l.rs b/src/common/mx25l.rs index 56c2d44..6c28c5a 100644 --- a/src/common/mx25l.rs +++ b/src/common/mx25l.rs @@ -198,6 +198,10 @@ impl Storage for Mx25l { Ok(()) } + fn erase(&mut self, address: usize) -> Result<(), Error> { + self.erase_sector(address) + } + fn clear(&mut self) { self.erase_all(); } diff --git a/src/common/storage.rs b/src/common/storage.rs index ebebe79..36d77e3 100644 --- a/src/common/storage.rs +++ b/src/common/storage.rs @@ -32,5 +32,7 @@ pub trait Storage { fn write(&mut self, address: usize, buffer: &[u8; 4096]) -> Result<(), Error>; + fn erase(&mut self, address: usize) -> Result<(), Error>; + fn clear(&mut self); } diff --git a/test/logger_test.rs b/test/logger_test.rs index a030821..a254f50 100644 --- a/test/logger_test.rs +++ b/test/logger_test.rs @@ -68,6 +68,19 @@ impl Storage for FakeStorage { Ok(()) } + fn erase(&mut self, address: usize) -> Result<(), Error> { + if (address & 4095) != 0 { + return Err(Error::UnalignedAddress); + } + + for i in 0..4096 { + self.actual[address + i] = 0xff; + } + + Ok(()) + + } + fn clear(&mut self) { self.actual = vec![0xff; MEMORY_SIZE].into_boxed_slice(); }