Skip to content

Commit 1e5d02f

Browse files
nashifgalak
authored andcommitted
flash_map: add function to iterate over areas
A new foreach iterator to go over all flash areas in a flash map. Signed-off-by: Anas Nashif <[email protected]>
1 parent 27c9791 commit 1e5d02f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/flash_map.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,24 @@ u8_t flash_area_align(const struct flash_area *fa);
172172
int flash_area_get_sectors(int fa_id, u32_t *count,
173173
struct flash_sector *sectors);
174174

175+
/**
176+
* Flash map iteration callback
177+
*
178+
* @param fa flash area
179+
* @param user_data User supplied data
180+
*
181+
*/
182+
typedef void (*flash_area_cb_t)(const struct flash_area *fa,
183+
void *user_data);
184+
185+
/**
186+
* Iterate over flash map
187+
*
188+
* @param user_cb User callback
189+
* @param user_data User supplied data
190+
*/
191+
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data);
192+
175193
/**
176194
* Check whether given flash area has supporting flash driver
177195
* in the system.

subsys/storage/flash_map/flash_map.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ static struct flash_area const *get_flash_area_from_id(int idx)
4141
return NULL;
4242
}
4343

44+
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data)
45+
{
46+
for (int i = 0; i < flash_map_entries; i++) {
47+
user_cb(&flash_map[i], user_data);
48+
}
49+
}
50+
4451
int flash_area_open(u8_t id, const struct flash_area **fap)
4552
{
4653
const struct flash_area *area;

0 commit comments

Comments
 (0)