Merge pull request #6408 from davidsaada/david_erase_size_addr

Add overloaded get_erase_size API with address parameter to BlockDevice
pull/6518/head
Jimmy Brisson 2018-03-29 11:59:28 -05:00 committed by GitHub
commit 64df0ddee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size()); 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()); TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());
// Fill with random sequence // Fill with random sequence
@ -142,6 +143,7 @@ void test_chaining() {
TEST_ASSERT_EQUAL(0, err); TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size()); 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()); TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
// Fill with random sequence // Fill with random sequence

View File

@ -135,9 +135,9 @@ public:
*/ */
virtual bd_size_t get_program_size() const = 0; 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 * @note Must be a multiple of the program size
*/ */
virtual bd_size_t get_erase_size() const virtual bd_size_t get_erase_size() const
@ -145,6 +145,17 @@ public:
return get_program_size(); 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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; 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 int ChainingBlockDevice::get_erase_value() const
{ {
return _erase_value; return _erase_value;

View File

@ -135,13 +135,21 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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 * @note Must be a multiple of the program size
*/ */
virtual bd_size_t get_erase_size() const; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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(); 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 int ExhaustibleBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -119,12 +119,20 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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; 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 bd_size_t HeapBlockDevice::size() const
{ {
MBED_ASSERT(_blocks != NULL); MBED_ASSERT(_blocks != NULL);

View File

@ -124,12 +124,20 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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; 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 /** Get the total size of the underlying device
* *
* @return Size of the underlying device in bytes * @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(); 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 int MBRBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -194,13 +194,21 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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 * @note Must be a multiple of the program size
*/ */
virtual bd_size_t get_erase_size() const; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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(); 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 int ObservingBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -105,12 +105,20 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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(); 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 int ProfilingBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -121,13 +121,21 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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 * @note Must be a multiple of the program size
*/ */
virtual bd_size_t get_erase_size() const; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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(); 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 int ReadOnlyBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -98,12 +98,20 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * 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(); 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 int SlicingBlockDevice::get_erase_value() const
{ {
return _bd->get_erase_value(); return _bd->get_erase_value();

View File

@ -127,13 +127,21 @@ public:
*/ */
virtual bd_size_t get_program_size() const; 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 * @note Must be a multiple of the program size
*/ */
virtual bd_size_t get_erase_size() const; 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 /** Get the value of storage when erased
* *
* If get_erase_value returns a non-negative byte value, the underlying * If get_erase_value returns a non-negative byte value, the underlying