Skip to content
Permalink
Browse files

drivers: flash: flash_simulator: added max erase calls param

Added a new runtime parameter to the Flash Simulator. It can be used to
ignore erases to the simulated flash memory after a certain number
of flash erase calls has been executed.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
  • Loading branch information...
kapi-no authored and carlescufi committed May 22, 2019
1 parent 04a5cee commit fefc62887c813211daf6b223a383c6bfc6a54ce0
Showing with 8 additions and 0 deletions.
  1. +8 −0 drivers/flash/flash_simulator.c
@@ -90,11 +90,13 @@ STATS_NAME_END(flash_sim_stats);
/* simulator dynamic thresholds */
STATS_SECT_START(flash_sim_thresholds)
STATS_SECT_ENTRY32(max_write_calls)
STATS_SECT_ENTRY32(max_erase_calls)
STATS_SECT_END;

STATS_SECT_DECL(flash_sim_thresholds) flash_sim_thresholds;
STATS_NAME_START(flash_sim_thresholds)
STATS_NAME(flash_sim_thresholds, max_write_calls)
STATS_NAME(flash_sim_thresholds, max_erase_calls)
STATS_NAME_END(flash_sim_thresholds);

static u8_t mock_flash[FLASH_SIZE];
@@ -246,6 +248,12 @@ static int flash_sim_erase(struct device *dev, const off_t offset,

STATS_INC(flash_sim_stats, flash_erase_calls);

if ((flash_sim_thresholds.max_erase_calls != 0) &&
(flash_sim_stats.flash_erase_calls >=
flash_sim_thresholds.max_erase_calls)){
return 0;
}

/* the first unit to be erased */
u32_t unit_start = (offset - FLASH_SIMULATOR_BASE_OFFSET) /
FLASH_SIMULATOR_ERASE_UNIT;

0 comments on commit fefc628

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