subsys: storage: flash_map: devices bindings fetch optimalization
Moved fetch of flash device bindings to early initialization of the application. Device bindings are constant while the application is running so it is better to fetch it at startup, and not every time flash_map procedures are called. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
ae9560636f
commit
f8a674b45e
2 changed files with 13 additions and 8 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <flash_map.h>
|
||||
#include <flash.h>
|
||||
#include <soc.h>
|
||||
#include <init.h>
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
struct layout_data {
|
||||
|
@ -41,6 +42,7 @@ static const struct driver_map_entry flash_drivers_map[] = {
|
|||
|
||||
const struct flash_area *flash_map;
|
||||
extern const int flash_map_entries;
|
||||
static struct device *flash_dev[ARRAY_SIZE(flash_drivers_map)];
|
||||
|
||||
int flash_area_open(u8_t id, const struct flash_area **fap)
|
||||
{
|
||||
|
@ -71,7 +73,7 @@ static struct device *get_flah_dev_from_id(u8_t id)
|
|||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(flash_drivers_map); i++) {
|
||||
if (flash_drivers_map[i].id == id) {
|
||||
return device_get_binding(flash_drivers_map[i].name);
|
||||
return flash_dev[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,6 +267,15 @@ u8_t flash_area_align(const struct flash_area *fa)
|
|||
return flash_get_write_block_size(dev);
|
||||
}
|
||||
|
||||
void flash_map_init(void)
|
||||
static int flash_map_init(struct device *dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(flash_dev); i++) {
|
||||
flash_dev[i] = device_get_binding(flash_drivers_map[i].name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(flash_map_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue