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 <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-02-10 11:41:18 -05:00 committed by Kumar Gala
commit 1e5d02fcd2
2 changed files with 25 additions and 0 deletions

View file

@ -172,6 +172,24 @@ u8_t flash_area_align(const struct flash_area *fa);
int flash_area_get_sectors(int fa_id, u32_t *count, int flash_area_get_sectors(int fa_id, u32_t *count,
struct flash_sector *sectors); struct flash_sector *sectors);
/**
* Flash map iteration callback
*
* @param fa flash area
* @param user_data User supplied data
*
*/
typedef void (*flash_area_cb_t)(const struct flash_area *fa,
void *user_data);
/**
* Iterate over flash map
*
* @param user_cb User callback
* @param user_data User supplied data
*/
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data);
/** /**
* Check whether given flash area has supporting flash driver * Check whether given flash area has supporting flash driver
* in the system. * in the system.

View file

@ -41,6 +41,13 @@ static struct flash_area const *get_flash_area_from_id(int idx)
return NULL; return NULL;
} }
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data)
{
for (int i = 0; i < flash_map_entries; i++) {
user_cb(&flash_map[i], user_data);
}
}
int flash_area_open(u8_t id, const struct flash_area **fap) int flash_area_open(u8_t id, const struct flash_area **fap)
{ {
const struct flash_area *area; const struct flash_area *area;