Skip to content

Commit

Permalink
Merge pull request tock#4069 from alistair23/alistair/tickv
Browse files Browse the repository at this point in the history
tickv: Remove the offset from read_region()
  • Loading branch information
alevy authored Jul 17, 2024
2 parents 403be95 + 3054b46 commit 8b9d425
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 37 deletions.
1 change: 0 additions & 1 deletion capsules/extra/src/tickv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ impl<'a, F: Flash, const PAGE_SIZE: usize> tickv::flash_controller::FlashControl
fn read_region(
&self,
region_number: usize,
_offset: usize,
_buf: &mut [u8; PAGE_SIZE],
) -> Result<(), tickv::error_codes::ErrorCode> {
if self
Expand Down
2 changes: 1 addition & 1 deletion libraries/tickv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "tickv"
description = "TicKV (Tiny Circular Key Value) is a small file system allowing key value pairs to be stored in Flash Memory."
repository = "https://github.com/tock/tock"
documentation = "https://github.com/tock/tock/blob/master/libraries/tickv/README.md"
version = "1.0.0"
version = "2.0.0"
license = "MIT OR Apache-2.0"
authors = ["Alistair Francis <[email protected]>"]
edition = "2021"
Expand Down
4 changes: 1 addition & 3 deletions libraries/tickv/src/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
//! fn read_region(
//! &self,
//! region_number: usize,
//! offset: usize,
//! buf: &mut [u8; 1024],
//! ) -> Result<(), ErrorCode> {
//! // We aren't ready yet, launch the async operation
Expand Down Expand Up @@ -533,10 +532,9 @@ mod tests {
fn read_region(
&self,
region_number: usize,
offset: usize,
_buf: &mut [u8; S],
) -> Result<(), ErrorCode> {
println!("Read from region: {}, offset: {offset}", region_number);
println!("Read from region: {}", region_number);

// Pretend that we aren't ready
self.async_read_region.set(region_number);
Expand Down
1 change: 1 addition & 0 deletions libraries/tickv/src/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ const fn crc32(poly: u32, mut byte: u8) -> u32 {
///
/// We keep this seperate to clearly show the CRC implementation
/// details (such as initial state and xorout).
#[derive(Default)]
struct Crc {}

impl Crc {
Expand Down
12 changes: 3 additions & 9 deletions libraries/tickv/src/flash_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::error_codes::ErrorCode;
/// }
///
/// impl FlashController<1024> for FlashCtrl {
/// fn read_region(&self, region_number: usize, offset: usize, buf: &mut [u8; 1024]) -> Result<(), ErrorCode> {
/// fn read_region(&self, region_number: usize, buf: &mut [u8; 1024]) -> Result<(), ErrorCode> {
/// unimplemented!()
/// }
///
Expand All @@ -56,8 +56,7 @@ use crate::error_codes::ErrorCode;
pub trait FlashController<const S: usize> {
/// This function must read the data from the flash region specified by
/// `region_number` into `buf`. The length of the data read should be the
/// same length as buf. `offset` indicates an offset into the region that
/// should be read.
/// same length as buf.
///
/// On success it should return nothing, on failure it
/// should return ErrorCode::ReadFail.
Expand All @@ -71,12 +70,7 @@ pub trait FlashController<const S: usize> {
/// `read_region()` has returned `ErrorCode::ReadNotReady(region_number)`
/// the `read_region()` function will be called again and this time should
/// return the data.
fn read_region(
&self,
region_number: usize,
offset: usize,
buf: &mut [u8; S],
) -> Result<(), ErrorCode>;
fn read_region(&self, region_number: usize, buf: &mut [u8; S]) -> Result<(), ErrorCode>;

/// This function must write the length of `buf` to the specified address
/// in flash.
Expand Down
4 changes: 2 additions & 2 deletions libraries/tickv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@
//! }
//!
//! impl FlashController<1024> for FlashCtrl {
//! fn read_region(&self, region_number: usize, offset: usize, buf: &mut [u8; 1024]) -> Result<(), ErrorCode> {
//! fn read_region(&self, region_number: usize, buf: &mut [u8; 1024]) -> Result<(), ErrorCode> {
//! // TODO: Read the specified flash region
//! for (i, b) in buf.iter_mut().enumerate() {
//! *b = self.buf.borrow()[region_number][offset + i]
//! *b = self.buf.borrow()[region_number][i]
//! }
//! Ok(())
//! }
Expand Down
20 changes: 4 additions & 16 deletions libraries/tickv/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ mod simple_flash_ctrl {
fn read_region(
&self,
_region_number: usize,
_offset: usize,
buf: &mut [u8; 2048],
) -> Result<(), ErrorCode> {
for b in buf.iter_mut() {
Expand Down Expand Up @@ -202,7 +201,6 @@ mod single_erase_flash_ctrl {
fn read_region(
&self,
_region_number: usize,
_offset: usize,
buf: &mut [u8; 2048],
) -> Result<(), ErrorCode> {
for b in buf.iter_mut() {
Expand Down Expand Up @@ -262,16 +260,11 @@ mod store_flast_ctrl {
}

impl FlashController<1024> for FlashCtrl {
fn read_region(
&self,
region_number: usize,
offset: usize,
buf: &mut [u8; 1024],
) -> Result<(), ErrorCode> {
fn read_region(&self, region_number: usize, buf: &mut [u8; 1024]) -> Result<(), ErrorCode> {
println!("Read from region: {}", region_number);

for (i, b) in buf.iter_mut().enumerate() {
*b = self.buf.borrow()[region_number][offset + i]
*b = self.buf.borrow()[region_number][i]
}

Ok(())
Expand Down Expand Up @@ -552,16 +545,11 @@ mod no_check_store_flast_ctrl {
}

impl FlashController<256> for FlashCtrl {
fn read_region(
&self,
region_number: usize,
offset: usize,
buf: &mut [u8; 256],
) -> Result<(), ErrorCode> {
fn read_region(&self, region_number: usize, buf: &mut [u8; 256]) -> Result<(), ErrorCode> {
println!("Read from region: {}", region_number);

for (i, b) in buf.iter_mut().enumerate() {
*b = self.buf.borrow()[region_number][offset + i]
*b = self.buf.borrow()[region_number][i]
}

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions libraries/tickv/src/tickv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S> {
if self.state.get() != State::AppendKey(KeyState::ReadRegion(new_region))
&& self.state.get() != State::Init(InitState::AppendKeyReadRegion(new_region))
{
match self.controller.read_region(new_region, 0, region_data) {
match self.controller.read_region(new_region, region_data) {
Ok(()) => {}
Err(e) => {
self.read_buffer.replace(Some(region_data));
Expand Down Expand Up @@ -693,7 +693,7 @@ impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S> {
if self.state.get() != State::GetKey(KeyState::ReadRegion(new_region))
&& self.state.get() != State::Init(InitState::GetKeyReadRegion(new_region))
{
match self.controller.read_region(new_region, 0, region_data) {
match self.controller.read_region(new_region, region_data) {
Ok(()) => {}
Err(e) => {
self.read_buffer.replace(Some(region_data));
Expand Down Expand Up @@ -818,7 +818,7 @@ impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S> {
// Get the data from that region
let region_data = self.read_buffer.take().unwrap();
if self.state.get() != State::InvalidateKey(KeyState::ReadRegion(new_region)) {
match self.controller.read_region(new_region, 0, region_data) {
match self.controller.read_region(new_region, region_data) {
Ok(()) => {}
Err(e) => {
self.read_buffer.replace(Some(region_data));
Expand Down Expand Up @@ -917,7 +917,7 @@ impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S> {
// Get the data from that region
let region_data = self.read_buffer.take().unwrap();
if self.state.get() != State::ZeroiseKey(KeyState::ReadRegion(new_region)) {
match self.controller.read_region(new_region, 0, region_data) {
match self.controller.read_region(new_region, region_data) {
Ok(()) => {}
Err(e) => {
self.read_buffer.replace(Some(region_data));
Expand Down Expand Up @@ -992,7 +992,7 @@ impl<'a, C: FlashController<S>, const S: usize> TicKV<'a, C, S> {
let region_data = self.read_buffer.take().unwrap();
if self.state.get() != State::GarbageCollect(RubbishState::ReadRegion(region, flash_freed))
{
match self.controller.read_region(region, 0, region_data) {
match self.controller.read_region(region, region_data) {
Ok(()) => {}
Err(e) => {
self.read_buffer.replace(Some(region_data));
Expand Down

0 comments on commit 8b9d425

Please sign in to comment.