1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

mtd: allow to use non-pagewise functions

If the underlying driver implements 'plain' read/write/erase
fucntions, don't convert them to pagewise functions and back.

Just use the old direct functions.
This commit is contained in:
Benjamin Valentin 2020-09-02 22:50:24 +02:00
parent f68f19a73f
commit 9a4141880c

View File

@ -46,6 +46,10 @@ int mtd_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
return -ENODEV;
}
if (mtd->driver->read) {
return mtd->driver->read(mtd, dest, addr, count);
}
/* page size is always a power of two */
const uint32_t page_shift = bitarithm_msb(mtd->page_size);
const uint32_t page_mask = mtd->page_size - 1;
@ -110,6 +114,10 @@ int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
return -ENODEV;
}
if (mtd->driver->write) {
return mtd->driver->write(mtd, src, addr, count);
}
/* page size is always a power of two */
const uint32_t page_shift = bitarithm_msb(mtd->page_size);
const uint32_t page_mask = mtd->page_size - 1;
@ -174,6 +182,10 @@ int mtd_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
return -ENODEV;
}
if (mtd->driver->erase) {
mtd->driver->erase(mtd, addr, count);
}
uint32_t sector_size = mtd->pages_per_sector * mtd->page_size;
if (count % sector_size) {