pw_kvs: Add Address translation to FakeFlashMemory
For FakeFlashMemory add implementation of FlashAddressToMcuAddress
Change-Id: Ie4a1ab1ead93cd2c6555e44cbbd3e89d9e2bf691
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/13201
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: David Rogers <davidrogers@google.com>
diff --git a/pw_kvs/fake_flash_memory.cc b/pw_kvs/fake_flash_memory.cc
index 39f5590..217870c 100644
--- a/pw_kvs/fake_flash_memory.cc
+++ b/pw_kvs/fake_flash_memory.cc
@@ -131,4 +131,16 @@
return StatusWithSize(status, data.size());
}
+std::byte* FakeFlashMemory::FlashAddressToMcuAddress(Address address) const {
+ if (address > sector_count() * sector_size_bytes()) {
+ PW_LOG_ERROR(
+ "FlashAddressToMcuAddress beyond end of memory; address %x, max "
+ "address %x",
+ unsigned(address),
+ unsigned(sector_count() * sector_size_bytes()));
+ return nullptr;
+ }
+ return buffer_.data() + address;
+}
+
} // namespace pw::kvs
diff --git a/pw_kvs/public/pw_kvs/fake_flash_memory.h b/pw_kvs/public/pw_kvs/fake_flash_memory.h
index 5dc839c..a2f9bbb 100644
--- a/pw_kvs/public/pw_kvs/fake_flash_memory.h
+++ b/pw_kvs/public/pw_kvs/fake_flash_memory.h
@@ -116,6 +116,8 @@
StatusWithSize Write(Address address,
std::span<const std::byte> data) override;
+ std::byte* FlashAddressToMcuAddress(Address) const override;
+
// Testing API
// Access the underlying buffer for testing purposes. Not part of the