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

mtd: rename mtd_write_page() -> mtd_write_page_raw()

The function will not abstract away the behavior of the underlying media
(e.g. whether only 1 -> 0 writes are possible without erase), thus rename it.
This commit is contained in:
Benjamin Valentin 2021-01-26 11:27:57 +01:00
parent 57f40e5afb
commit 60eb75da3c
7 changed files with 22 additions and 20 deletions

View File

@ -285,8 +285,9 @@ int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
* The MTD layer will take care of splitting up the transaction into multiple
* writes if it is required by the underlying storage media.
*
* @p offset must be smaller than the page size
* This performs a raw write, no automatic read-modify-write cycle is performed.
*
* @p offset must be smaller than the page size
*
* @param mtd the device to write to
* @param[in] src the buffer to write
@ -302,7 +303,8 @@ int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count);
* @return -EIO if I/O error occurred
* @return -EINVAL if parameters are invalid
*/
int mtd_write_page(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset, uint32_t size);
int mtd_write_page_raw(mtd_dev_t *mtd, const void *src, uint32_t page,
uint32_t offset, uint32_t size);
/**
* @brief Erase sectors of a MTD device

View File

@ -122,11 +122,11 @@ int mtd_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t count)
const uint32_t page_shift = bitarithm_msb(mtd->page_size);
const uint32_t page_mask = mtd->page_size - 1;
return mtd_write_page(mtd, src, addr >> page_shift, addr & page_mask, count);
return mtd_write_page_raw(mtd, src, addr >> page_shift, addr & page_mask, count);
}
int mtd_write_page(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset,
uint32_t count)
int mtd_write_page_raw(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset,
uint32_t count)
{
if (!mtd || !mtd->driver) {
return -ENODEV;

View File

@ -112,9 +112,9 @@ static int _write_page(mtd_dev_t *mtd, const void *src, uint32_t page,
mtd_mapper_region_t *region = container_of(mtd, mtd_mapper_region_t, mtd);
_lock(region);
int res = mtd_write_page(region->parent->mtd, src,
page + _page_offset(region),
offset, count);
int res = mtd_write_page_raw(region->parent->mtd, src,
page + _page_offset(region),
offset, count);
_unlock(region);
return res;
}

View File

@ -135,8 +135,8 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
uint32_t sector_size = fatfs_mtd_devs[pdrv]->page_size
* fatfs_mtd_devs[pdrv]->pages_per_sector;
res = mtd_write_page(fatfs_mtd_devs[pdrv], buff,
sector, 0, count * sector_size);
res = mtd_write_page_raw(fatfs_mtd_devs[pdrv], buff,
sector, 0, count * sector_size);
if (res != 0) {
return RES_ERROR;

View File

@ -85,8 +85,8 @@ static int _dev_write(const struct lfs_config *c, lfs_block_t block,
DEBUG("lfs_write: c=%p, block=%" PRIu32 ", off=%" PRIu32 ", buf=%p, size=%" PRIu32 "\n",
(void *)c, block, off, buffer, size);
return mtd_write_page(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
return mtd_write_page_raw(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
}
static int _dev_erase(const struct lfs_config *c, lfs_block_t block)

View File

@ -85,8 +85,8 @@ static int _dev_write(const struct lfs_config *c, lfs_block_t block,
DEBUG("lfs_write: c=%p, block=%" PRIu32 ", off=%" PRIu32 ", buf=%p, size=%" PRIu32 "\n",
(void *)c, block, off, buffer, size);
return mtd_write_page(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
return mtd_write_page_raw(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
}
static int _dev_erase(const struct lfs_config *c, lfs_block_t block)

View File

@ -187,7 +187,7 @@ static int cmd_write_page(int argc, char **argv)
offset = atoi(argv[3]);
len = strlen(argv[4]);
int res = mtd_write_page(dev, argv[4], page, offset, len);
int res = mtd_write_page_raw(dev, argv[4], page, offset, len);
if (res) {
printf("error: %i\n", res);
@ -376,8 +376,8 @@ static int cmd_test(int argc, char **argv)
/* write dummy data to sectors */
memset(buffer, 0x23, dev->page_size);
assert(mtd_write_page(dev, buffer, page_0, 0, page_size) == 0);
assert(mtd_write_page(dev, buffer, page_1, 0, page_size) == 0);
assert(mtd_write_page_raw(dev, buffer, page_0, 0, page_size) == 0);
assert(mtd_write_page_raw(dev, buffer, page_1, 0, page_size) == 0);
/* erase two sectors and check if they have been erase */
assert(mtd_erase_sector(dev, sector, 2) == 0);
@ -389,20 +389,20 @@ static int cmd_test(int argc, char **argv)
/* write test data & read it back */
const char test_str[] = "0123456789";
uint32_t offset = 5;
assert(mtd_write_page(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_write_page_raw(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_read_page(dev, buffer, page_0, offset, sizeof(test_str)) == 0);
assert(memcmp(test_str, buffer, sizeof(test_str)) == 0);
/* write across page boundary */
offset = page_size - sizeof(test_str) / 2;
assert(mtd_write_page(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_write_page_raw(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_read_page(dev, buffer, page_0, offset, sizeof(test_str)) == 0);
assert(memcmp(test_str, buffer, sizeof(test_str)) == 0);
/* write across sector boundary */
offset = page_size - sizeof(test_str) / 2
+ (dev->pages_per_sector - 1) * page_size;
assert(mtd_write_page(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_write_page_raw(dev, test_str, page_0, offset, sizeof(test_str)) == 0);
assert(mtd_read_page(dev, buffer, page_0, offset, sizeof(test_str)) == 0);
assert(memcmp(test_str, buffer, sizeof(test_str)) == 0);