Skip to content

Commit

Permalink
unittests/tests-mtd: use .write_page()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Feb 28, 2023
1 parent 7b1f929 commit 3f358ca
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/unittests/tests-mtd/tests-mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,14 @@ static int _read(mtd_dev_t *dev, void *buff, uint32_t addr, uint32_t size)
return 0;
}

static int _write(mtd_dev_t *dev, const void *buff, uint32_t addr, uint32_t size)
static int _write_page(mtd_dev_t *dev, const void *buff, uint32_t page,
uint32_t offset, uint32_t size)
{
(void)dev;
uint32_t addr = page * dev->page_size + offset;

if (addr + size > sizeof(dummy_memory)) {
return -EOVERFLOW;
}
if (((addr % PAGE_SIZE) + size) > PAGE_SIZE) {
return -EOVERFLOW;
}
memcpy(dummy_memory + addr, buff, size);

return 0;
return size;
}

static int _erase(mtd_dev_t *dev, uint32_t addr, uint32_t size)
Expand Down Expand Up @@ -108,7 +103,7 @@ static int _power(mtd_dev_t *dev, enum mtd_power_state power)
static const mtd_desc_t driver = {
.init = _init,
.read = _read,
.write = _write,
.write_page = _write_page,
.erase = _erase,
.power = _power,
};
Expand Down

0 comments on commit 3f358ca

Please sign in to comment.