Skip to content
Permalink
Browse files

drivers: flash: flash_simulator: added max len param

Added a new runtime parameter to the Flash Simulator. It can be used to
ignore part of the data that is written to the simulated flash memory.
This parameter works together with max write calls parameter.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
  • Loading branch information...
kapi-no authored and carlescufi committed May 22, 2019
1 parent fefc628 commit 42b3bd91e7435bab0bed37201c9f06d6efd2f219
Showing with 22 additions and 4 deletions.
  1. +22 −4 drivers/flash/flash_simulator.c
@@ -91,12 +91,14 @@ STATS_NAME_END(flash_sim_stats);
STATS_SECT_START(flash_sim_thresholds)
STATS_SECT_ENTRY32(max_write_calls)
STATS_SECT_ENTRY32(max_erase_calls)
STATS_SECT_ENTRY32(max_len)
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(flash_sim_thresholds, max_len)
STATS_NAME_END(flash_sim_thresholds);

static u8_t mock_flash[FLASH_SIZE];
@@ -190,13 +192,29 @@ 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;
bool data_part_ignored = false;

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

data_part_ignored = true;
}
}

for (u32_t i = 0; i < len; i++) {
if (data_part_ignored) {
if (i >= flash_sim_thresholds.max_len) {
return 0;
}
}

/* only pull bits to zero */
*(FLASH(offset + i)) &= *((u8_t *)data + i);
}

0 comments on commit 42b3bd9

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