Skip to content

Commit 64df0dd

Browse files
Merge pull request #6408 from davidsaada/david_erase_size_addr
Add overloaded get_erase_size API with address parameter to BlockDevice
2 parents 8978859 + a604800 commit 64df0dd

18 files changed

+147
-18
lines changed

features/TESTS/filesystem/util_block_device/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void test_slicing() {
4848
TEST_ASSERT_EQUAL(0, err);
4949

5050
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
51+
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_SIZE));
5152
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());
5253

5354
// Fill with random sequence
@@ -142,6 +143,7 @@ void test_chaining() {
142143
TEST_ASSERT_EQUAL(0, err);
143144

144145
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
146+
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT/2)*BLOCK_SIZE+1));
145147
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
146148

147149
// Fill with random sequence

features/filesystem/bd/BlockDevice.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,27 @@ class BlockDevice
135135
*/
136136
virtual bd_size_t get_program_size() const = 0;
137137

138-
/** Get the size of a eraseable block
138+
/** Get the size of an erasable block
139139
*
140-
* @return Size of a eraseable block in bytes
140+
* @return Size of an erasable block in bytes
141141
* @note Must be a multiple of the program size
142142
*/
143143
virtual bd_size_t get_erase_size() const
144144
{
145145
return get_program_size();
146146
}
147147

148+
/** Get the size of an erasable block given address
149+
*
150+
* @param addr Address within the erasable block
151+
* @return Size of an erasable block in bytes
152+
* @note Must be a multiple of the program size
153+
*/
154+
virtual bd_size_t get_erase_size(bd_addr_t addr) const
155+
{
156+
return get_erase_size();
157+
}
158+
148159
/** Get the value of storage when erased
149160
*
150161
* If get_erase_value returns a non-negative byte value, the underlying

features/filesystem/bd/ChainingBlockDevice.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
211211
return _erase_size;
212212
}
213213

214+
bd_size_t ChainingBlockDevice::get_erase_size(bd_addr_t addr) const
215+
{
216+
bd_addr_t bd_start_addr = 0;
217+
for (size_t i = 0; i < _bd_count; i++) {
218+
bd_size_t bdsize = _bds[i]->size();
219+
if (addr < (bd_start_addr + bdsize)) {
220+
return _bds[i]->get_erase_size(addr - bd_start_addr);
221+
}
222+
bd_start_addr += bdsize;
223+
}
224+
225+
// Getting here implies an illegal address
226+
MBED_ASSERT(0);
227+
return 0; // satisfy compiler
228+
}
229+
214230
int ChainingBlockDevice::get_erase_value() const
215231
{
216232
return _erase_value;

features/filesystem/bd/ChainingBlockDevice.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,21 @@ class ChainingBlockDevice : public BlockDevice
135135
*/
136136
virtual bd_size_t get_program_size() const;
137137

138-
/** Get the size of a eraseable block
138+
/** Get the size of an eraseable block
139139
*
140-
* @return Size of a eraseable block in bytes
140+
* @return Size of an erasable block in bytes
141141
* @note Must be a multiple of the program size
142142
*/
143143
virtual bd_size_t get_erase_size() const;
144144

145+
/** Get the size of an erasable block given address
146+
*
147+
* @param addr Address within the erasable block
148+
* @return Size of an erasable block in bytes
149+
* @note Must be a multiple of the program size
150+
*/
151+
virtual bd_size_t get_erase_size(bd_addr_t addr) const;
152+
145153
/** Get the value of storage when erased
146154
*
147155
* If get_erase_value returns a non-negative byte value, the underlying

features/filesystem/bd/ExhaustibleBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const
107107
return _bd->get_erase_size();
108108
}
109109

110+
bd_size_t ExhaustibleBlockDevice::get_erase_size(bd_addr_t addr) const
111+
{
112+
return _bd->get_erase_size(addr);
113+
}
114+
110115
int ExhaustibleBlockDevice::get_erase_value() const
111116
{
112117
return _bd->get_erase_value();

features/filesystem/bd/ExhaustibleBlockDevice.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,20 @@ class ExhaustibleBlockDevice : public BlockDevice
119119
*/
120120
virtual bd_size_t get_program_size() const;
121121

122-
/** Get the size of a erasable block
122+
/** Get the size of an erasable block
123123
*
124-
* @return Size of a erasable block in bytes
124+
* @return Size of an erasable block in bytes
125125
*/
126126
virtual bd_size_t get_erase_size() const;
127127

128+
/** Get the size of an erasable block given address
129+
*
130+
* @param addr Address within the erasable block
131+
* @return Size of an erasable block in bytes
132+
* @note Must be a multiple of the program size
133+
*/
134+
virtual bd_size_t get_erase_size(bd_addr_t addr) const;
135+
128136
/** Get the value of storage when erased
129137
*
130138
* If get_erase_value returns a non-negative byte value, the underlying

features/filesystem/bd/HeapBlockDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ bd_size_t HeapBlockDevice::get_erase_size() const
8181
return _erase_size;
8282
}
8383

84+
bd_size_t HeapBlockDevice::get_erase_size(bd_addr_t addr) const
85+
{
86+
MBED_ASSERT(_blocks != NULL);
87+
return _erase_size;
88+
}
89+
8490
bd_size_t HeapBlockDevice::size() const
8591
{
8692
MBED_ASSERT(_blocks != NULL);

features/filesystem/bd/HeapBlockDevice.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,20 @@ class HeapBlockDevice : public BlockDevice
124124
*/
125125
virtual bd_size_t get_program_size() const;
126126

127-
/** Get the size of a eraseable block
127+
/** Get the size of an erasable block
128128
*
129-
* @return Size of a eraseable block in bytes
129+
* @return Size of an erasable block in bytes
130130
*/
131131
virtual bd_size_t get_erase_size() const;
132132

133+
/** Get the size of an erasable block given address
134+
*
135+
* @param addr Address within the erasable block
136+
* @return Size of an erasable block in bytes
137+
* @note Must be a multiple of the program size
138+
*/
139+
virtual bd_size_t get_erase_size(bd_addr_t addr) const;
140+
133141
/** Get the total size of the underlying device
134142
*
135143
* @return Size of the underlying device in bytes

features/filesystem/bd/MBRBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const
276276
return _bd->get_erase_size();
277277
}
278278

279+
bd_size_t MBRBlockDevice::get_erase_size(bd_addr_t addr) const
280+
{
281+
return _bd->get_erase_size(_offset + addr);
282+
}
283+
279284
int MBRBlockDevice::get_erase_value() const
280285
{
281286
return _bd->get_erase_value();

features/filesystem/bd/MBRBlockDevice.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,21 @@ class MBRBlockDevice : public BlockDevice
194194
*/
195195
virtual bd_size_t get_program_size() const;
196196

197-
/** Get the size of a eraseable block
197+
/** Get the size of an erasable block
198198
*
199-
* @return Size of a eraseable block in bytes
199+
* @return Size of an erasable block in bytes
200200
* @note Must be a multiple of the program size
201201
*/
202202
virtual bd_size_t get_erase_size() const;
203203

204+
/** Get the size of an erasable block given address
205+
*
206+
* @param addr Address within the erasable block
207+
* @return Size of an erasable block in bytes
208+
* @note Must be a multiple of the program size
209+
*/
210+
virtual bd_size_t get_erase_size(bd_addr_t addr) const;
211+
204212
/** Get the value of storage when erased
205213
*
206214
* If get_erase_value returns a non-negative byte value, the underlying

0 commit comments

Comments
 (0)