mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
mtd_mapper: implement pagewise functions
Implement functions to use the pagewise MTD API.
This commit is contained in:
parent
c6c0f6a180
commit
43ee53a059
@ -51,6 +51,11 @@ static uint32_t _byte_offset(mtd_mapper_region_t *region)
|
||||
region->sector;
|
||||
}
|
||||
|
||||
static uint32_t _page_offset(mtd_mapper_region_t *region)
|
||||
{
|
||||
return region->mtd.pages_per_sector * region->sector;
|
||||
}
|
||||
|
||||
static int _init_target(mtd_mapper_region_t *region)
|
||||
{
|
||||
mtd_mapper_parent_t *parent = region->parent;
|
||||
@ -100,6 +105,19 @@ static int _write(mtd_dev_t *mtd, const void *src, uint32_t addr,
|
||||
return res;
|
||||
}
|
||||
|
||||
static int _write_page(mtd_dev_t *mtd, const void *src, uint32_t page,
|
||||
uint32_t offset, uint32_t count)
|
||||
{
|
||||
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);
|
||||
_unlock(region);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int _read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
|
||||
{
|
||||
mtd_mapper_region_t *region = container_of(mtd, mtd_mapper_region_t, mtd);
|
||||
@ -114,6 +132,19 @@ static int _read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int _read_page(mtd_dev_t *mtd, void *dest, uint32_t page,
|
||||
uint32_t offset, uint32_t count)
|
||||
{
|
||||
mtd_mapper_region_t *region = container_of(mtd, mtd_mapper_region_t, mtd);
|
||||
|
||||
_lock(region);
|
||||
int res = mtd_read_page(region->parent->mtd, dest,
|
||||
page + _page_offset(region),
|
||||
offset, count);
|
||||
_unlock(region);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int _erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
|
||||
{
|
||||
mtd_mapper_region_t *region = container_of(mtd, mtd_mapper_region_t, mtd);
|
||||
@ -128,9 +159,22 @@ static int _erase(mtd_dev_t *mtd, uint32_t addr, uint32_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int _erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t count)
|
||||
{
|
||||
mtd_mapper_region_t *region = container_of(mtd, mtd_mapper_region_t, mtd);
|
||||
|
||||
_lock(region);
|
||||
int res = mtd_erase_sector(region->parent->mtd, region->sector + sector, count);
|
||||
_unlock(region);
|
||||
return res;
|
||||
}
|
||||
|
||||
const mtd_desc_t mtd_mapper_driver = {
|
||||
.init = _init,
|
||||
.read = _read,
|
||||
.read_page = _read_page,
|
||||
.write = _write,
|
||||
.write_page = _write_page,
|
||||
.erase = _erase,
|
||||
.erase_sector = _erase_sector,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user