Skip to content
Permalink
Browse files

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>
  • Loading branch information...
nashif authored and galak committed Feb 10, 2019
1 parent 27c9791 commit 1e5d02fcd20c9dbb5cecec5e9c588150a5c39560
Showing with 25 additions and 0 deletions.
  1. +18 −0 include/flash_map.h
  2. +7 −0 subsys/storage/flash_map/flash_map.c
@@ -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,
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
* in the system.
@@ -41,6 +41,13 @@ static struct flash_area const *get_flash_area_from_id(int idx)
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)
{
const struct flash_area *area;

0 comments on commit 1e5d02f

Please sign in to comment.
You can’t perform that action at this time.