Add overloaded get_erase_size API with address parameter to all block devices

pull/6408/head
David Saada 2018-03-20 19:54:38 +02:00
parent 7c30faf69d
commit a6048005d7
18 changed files with 147 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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