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

Merge pull request #14933 from benpicco/drivers/mtd_shortcut

mtd: allow to use non-pagewise functions
This commit is contained in:
benpicco 2020-09-04 16:25:55 +02:00 committed by GitHub
commit c6c0f6a180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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) {