Skip to content
Permalink
Browse files

drivers: flash: flash_simulator: added max write calls param

Added a new runtime parameter to the Flash Simulator. It can be used to
ignore any writes to the simulated flash memory after a certain number
of flash write calls has been executed. This behaviour is useful for
simulating power down during the flash write operation.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
  • Loading branch information...
kapi-no authored and carlescufi committed Apr 26, 2019
1 parent 6b772f9 commit 4054d2bacf71b8ca46da8037256f4a258918aa1b
Showing with 18 additions and 0 deletions.
  1. +18 −0 drivers/flash/flash_simulator.c
@@ -87,6 +87,16 @@ UTIL_EVAL(UTIL_REPEAT(FLASH_SIMULATOR_FLASH_PAGE_COUNT, STATS_NAME_EC))
UTIL_EVAL(UTIL_REPEAT(FLASH_SIMULATOR_FLASH_PAGE_COUNT, STATS_NAME_DIRTYR)) UTIL_EVAL(UTIL_REPEAT(FLASH_SIMULATOR_FLASH_PAGE_COUNT, STATS_NAME_DIRTYR))
STATS_NAME_END(flash_sim_stats); STATS_NAME_END(flash_sim_stats);


/* simulator dynamic thresholds */
STATS_SECT_START(flash_sim_thresholds)
STATS_SECT_ENTRY32(max_write_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_END(flash_sim_thresholds);

static u8_t mock_flash[FLASH_SIZE]; static u8_t mock_flash[FLASH_SIZE];
static bool write_protection; static bool write_protection;


@@ -178,6 +188,12 @@ static int flash_sim_write(struct device *dev, const off_t offset,
} }
} }


if ((flash_sim_thresholds.max_write_calls != 0) &&
(flash_sim_stats.flash_write_calls >
flash_sim_thresholds.max_write_calls)){
return 0;
}

for (u32_t i = 0; i < len; i++) { for (u32_t i = 0; i < len; i++) {
/* only pull bits to zero */ /* only pull bits to zero */
*(FLASH(offset + i)) &= *((u8_t *)data + i); *(FLASH(offset + i)) &= *((u8_t *)data + i);
@@ -279,6 +295,8 @@ static const struct flash_driver_api flash_sim_api = {
static int flash_init(struct device *dev) static int flash_init(struct device *dev)
{ {
STATS_INIT_AND_REG(flash_sim_stats, STATS_SIZE_32, "flash_sim_stats"); STATS_INIT_AND_REG(flash_sim_stats, STATS_SIZE_32, "flash_sim_stats");
STATS_INIT_AND_REG(flash_sim_thresholds, STATS_SIZE_32,
"flash_sim_thresholds");
memset(mock_flash, 0xFF, ARRAY_SIZE(mock_flash)); memset(mock_flash, 0xFF, ARRAY_SIZE(mock_flash));


return 0; return 0;

0 comments on commit 4054d2b

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