From a6048005d7c7ee06b7956918589d381a9f41f159 Mon Sep 17 00:00:00 2001 From: David Saada Date: Tue, 20 Mar 2018 19:54:38 +0200 Subject: [PATCH] Add overloaded get_erase_size API with address parameter to all block devices --- .../TESTS/filesystem/util_block_device/main.cpp | 2 ++ features/filesystem/bd/BlockDevice.h | 15 +++++++++++++-- features/filesystem/bd/ChainingBlockDevice.cpp | 16 ++++++++++++++++ features/filesystem/bd/ChainingBlockDevice.h | 12 ++++++++++-- .../filesystem/bd/ExhaustibleBlockDevice.cpp | 5 +++++ features/filesystem/bd/ExhaustibleBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/HeapBlockDevice.cpp | 6 ++++++ features/filesystem/bd/HeapBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/MBRBlockDevice.cpp | 5 +++++ features/filesystem/bd/MBRBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/ObservingBlockDevice.cpp | 5 +++++ features/filesystem/bd/ObservingBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/ProfilingBlockDevice.cpp | 5 +++++ features/filesystem/bd/ProfilingBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/ReadOnlyBlockDevice.cpp | 5 +++++ features/filesystem/bd/ReadOnlyBlockDevice.h | 12 ++++++++++-- features/filesystem/bd/SlicingBlockDevice.cpp | 5 +++++ features/filesystem/bd/SlicingBlockDevice.h | 12 ++++++++++-- 18 files changed, 147 insertions(+), 18 deletions(-) diff --git a/features/TESTS/filesystem/util_block_device/main.cpp b/features/TESTS/filesystem/util_block_device/main.cpp index 1d1721a105..b4a104be0c 100644 --- a/features/TESTS/filesystem/util_block_device/main.cpp +++ b/features/TESTS/filesystem/util_block_device/main.cpp @@ -48,6 +48,7 @@ void test_slicing() { TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size()); + TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_SIZE)); TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size()); // Fill with random sequence @@ -142,6 +143,7 @@ void test_chaining() { TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size()); + TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT/2)*BLOCK_SIZE+1)); TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size()); // Fill with random sequence diff --git a/features/filesystem/bd/BlockDevice.h b/features/filesystem/bd/BlockDevice.h index 51118d7941..d540967099 100644 --- a/features/filesystem/bd/BlockDevice.h +++ b/features/filesystem/bd/BlockDevice.h @@ -135,9 +135,9 @@ public: */ virtual bd_size_t get_program_size() const = 0; - /** Get the size of a eraseable block + /** Get the size of an erasable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes * @note Must be a multiple of the program size */ virtual bd_size_t get_erase_size() const @@ -145,6 +145,17 @@ public: return get_program_size(); } + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const + { + return get_erase_size(); + } + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/ChainingBlockDevice.cpp b/features/filesystem/bd/ChainingBlockDevice.cpp index 20a5da1f54..f0be36b314 100644 --- a/features/filesystem/bd/ChainingBlockDevice.cpp +++ b/features/filesystem/bd/ChainingBlockDevice.cpp @@ -211,6 +211,22 @@ bd_size_t ChainingBlockDevice::get_erase_size() const return _erase_size; } +bd_size_t ChainingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + bd_addr_t bd_start_addr = 0; + for (size_t i = 0; i < _bd_count; i++) { + bd_size_t bdsize = _bds[i]->size(); + if (addr < (bd_start_addr + bdsize)) { + return _bds[i]->get_erase_size(addr - bd_start_addr); + } + bd_start_addr += bdsize; + } + + // Getting here implies an illegal address + MBED_ASSERT(0); + return 0; // satisfy compiler +} + int ChainingBlockDevice::get_erase_value() const { return _erase_value; diff --git a/features/filesystem/bd/ChainingBlockDevice.h b/features/filesystem/bd/ChainingBlockDevice.h index c3b79e6b58..ad3c6e884a 100644 --- a/features/filesystem/bd/ChainingBlockDevice.h +++ b/features/filesystem/bd/ChainingBlockDevice.h @@ -135,13 +135,21 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a eraseable block + /** Get the size of an eraseable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes * @note Must be a multiple of the program size */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/ExhaustibleBlockDevice.cpp b/features/filesystem/bd/ExhaustibleBlockDevice.cpp index e678cca8b5..cd949d6607 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.cpp +++ b/features/filesystem/bd/ExhaustibleBlockDevice.cpp @@ -107,6 +107,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t ExhaustibleBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(addr); +} + int ExhaustibleBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/ExhaustibleBlockDevice.h b/features/filesystem/bd/ExhaustibleBlockDevice.h index 5d6ff5568b..e55f662fe9 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.h +++ b/features/filesystem/bd/ExhaustibleBlockDevice.h @@ -119,12 +119,20 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a erasable block + /** Get the size of an erasable block * - * @return Size of a erasable block in bytes + * @return Size of an erasable block in bytes */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/HeapBlockDevice.cpp b/features/filesystem/bd/HeapBlockDevice.cpp index f5bb02de76..379fea8c75 100644 --- a/features/filesystem/bd/HeapBlockDevice.cpp +++ b/features/filesystem/bd/HeapBlockDevice.cpp @@ -81,6 +81,12 @@ bd_size_t HeapBlockDevice::get_erase_size() const return _erase_size; } +bd_size_t HeapBlockDevice::get_erase_size(bd_addr_t addr) const +{ + MBED_ASSERT(_blocks != NULL); + return _erase_size; +} + bd_size_t HeapBlockDevice::size() const { MBED_ASSERT(_blocks != NULL); diff --git a/features/filesystem/bd/HeapBlockDevice.h b/features/filesystem/bd/HeapBlockDevice.h index 8fc31cee46..8d65e82b3d 100644 --- a/features/filesystem/bd/HeapBlockDevice.h +++ b/features/filesystem/bd/HeapBlockDevice.h @@ -124,12 +124,20 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a eraseable block + /** Get the size of an erasable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/MBRBlockDevice.cpp b/features/filesystem/bd/MBRBlockDevice.cpp index 8799e1e3fd..675491623b 100644 --- a/features/filesystem/bd/MBRBlockDevice.cpp +++ b/features/filesystem/bd/MBRBlockDevice.cpp @@ -276,6 +276,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t MBRBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(_offset + addr); +} + int MBRBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/MBRBlockDevice.h b/features/filesystem/bd/MBRBlockDevice.h index bfb43d607c..c2ad5d5082 100644 --- a/features/filesystem/bd/MBRBlockDevice.h +++ b/features/filesystem/bd/MBRBlockDevice.h @@ -194,13 +194,21 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a eraseable block + /** Get the size of an erasable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes * @note Must be a multiple of the program size */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/ObservingBlockDevice.cpp b/features/filesystem/bd/ObservingBlockDevice.cpp index 71fc3f2931..d484a57213 100644 --- a/features/filesystem/bd/ObservingBlockDevice.cpp +++ b/features/filesystem/bd/ObservingBlockDevice.cpp @@ -96,6 +96,11 @@ bd_size_t ObservingBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t ObservingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(addr); +} + int ObservingBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/ObservingBlockDevice.h b/features/filesystem/bd/ObservingBlockDevice.h index b4b6aa87d8..9dce5fdf20 100644 --- a/features/filesystem/bd/ObservingBlockDevice.h +++ b/features/filesystem/bd/ObservingBlockDevice.h @@ -105,12 +105,20 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a erasable block + /** Get the size of an erasable block * - * @return Size of a erasable block in bytes + * @return Size of an erasable block in bytes */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/ProfilingBlockDevice.cpp b/features/filesystem/bd/ProfilingBlockDevice.cpp index d0a7d4a5e5..7077d28ad0 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.cpp +++ b/features/filesystem/bd/ProfilingBlockDevice.cpp @@ -82,6 +82,11 @@ bd_size_t ProfilingBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t ProfilingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(addr); +} + int ProfilingBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/ProfilingBlockDevice.h b/features/filesystem/bd/ProfilingBlockDevice.h index d8196ea45b..5d3a01323c 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.h +++ b/features/filesystem/bd/ProfilingBlockDevice.h @@ -121,13 +121,21 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a eraseable block + /** Get the size of an erasable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes * @note Must be a multiple of the program size */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/ReadOnlyBlockDevice.cpp b/features/filesystem/bd/ReadOnlyBlockDevice.cpp index 64e4e3bb4a..0b23694fa1 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.cpp +++ b/features/filesystem/bd/ReadOnlyBlockDevice.cpp @@ -82,6 +82,11 @@ bd_size_t ReadOnlyBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t ReadOnlyBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(addr); +} + int ReadOnlyBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/ReadOnlyBlockDevice.h b/features/filesystem/bd/ReadOnlyBlockDevice.h index 1813631655..c7c59e638f 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.h +++ b/features/filesystem/bd/ReadOnlyBlockDevice.h @@ -98,12 +98,20 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a erasable block + /** Get the size of an erasable block * - * @return Size of a erasable block in bytes + * @return Size of an erasable block in bytes */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying diff --git a/features/filesystem/bd/SlicingBlockDevice.cpp b/features/filesystem/bd/SlicingBlockDevice.cpp index 9065a30205..9d2d859ed5 100644 --- a/features/filesystem/bd/SlicingBlockDevice.cpp +++ b/features/filesystem/bd/SlicingBlockDevice.cpp @@ -102,6 +102,11 @@ bd_size_t SlicingBlockDevice::get_erase_size() const return _bd->get_erase_size(); } +bd_size_t SlicingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return _bd->get_erase_size(_start + addr); +} + int SlicingBlockDevice::get_erase_value() const { return _bd->get_erase_value(); diff --git a/features/filesystem/bd/SlicingBlockDevice.h b/features/filesystem/bd/SlicingBlockDevice.h index 0278413389..611fba2aba 100644 --- a/features/filesystem/bd/SlicingBlockDevice.h +++ b/features/filesystem/bd/SlicingBlockDevice.h @@ -127,13 +127,21 @@ public: */ virtual bd_size_t get_program_size() const; - /** Get the size of a eraseable block + /** Get the size of an erasable block * - * @return Size of a eraseable block in bytes + * @return Size of an erasable block in bytes * @note Must be a multiple of the program size */ virtual bd_size_t get_erase_size() const; + /** Get the size of an erasable block given address + * + * @param addr Address within the erasable block + * @return Size of an erasable block in bytes + * @note Must be a multiple of the program size + */ + virtual bd_size_t get_erase_size(bd_addr_t addr) const; + /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying