[driver][mtd_nand] Formatting code.|格式化代码。

This commit is contained in:
guozhanxin 2019-06-19 17:14:44 +08:00
parent d8702aa568
commit c421757cc4
2 changed files with 166 additions and 166 deletions

View File

@ -45,71 +45,71 @@ struct rt_mtd_nand_device
rt_uint32_t block_end; /* The end of available block */
/* operations interface */
const struct rt_mtd_nand_driver_ops* ops;
const struct rt_mtd_nand_driver_ops *ops;
};
struct rt_mtd_nand_driver_ops
{
rt_err_t (*read_id) (struct rt_mtd_nand_device* device);
rt_err_t (*read_id)(struct rt_mtd_nand_device *device);
rt_err_t (*read_page)(struct rt_mtd_nand_device* device,
rt_err_t (*read_page)(struct rt_mtd_nand_device *device,
rt_off_t page,
rt_uint8_t* data, rt_uint32_t data_len,
rt_uint8_t * spare, rt_uint32_t spare_len);
rt_uint8_t *data, rt_uint32_t data_len,
rt_uint8_t *spare, rt_uint32_t spare_len);
rt_err_t (*write_page)(struct rt_mtd_nand_device * device,
rt_err_t (*write_page)(struct rt_mtd_nand_device *device,
rt_off_t page,
const rt_uint8_t * data, rt_uint32_t data_len,
const rt_uint8_t * spare, rt_uint32_t spare_len);
rt_err_t (*move_page) (struct rt_mtd_nand_device *device, rt_off_t src_page, rt_off_t dst_page);
const rt_uint8_t *data, rt_uint32_t data_len,
const rt_uint8_t *spare, rt_uint32_t spare_len);
rt_err_t (*move_page)(struct rt_mtd_nand_device *device, rt_off_t src_page, rt_off_t dst_page);
rt_err_t (*erase_block)(struct rt_mtd_nand_device* device, rt_uint32_t block);
rt_err_t (*check_block)(struct rt_mtd_nand_device* device, rt_uint32_t block);
rt_err_t (*mark_badblock)(struct rt_mtd_nand_device* device, rt_uint32_t block);
rt_err_t (*erase_block)(struct rt_mtd_nand_device *device, rt_uint32_t block);
rt_err_t (*check_block)(struct rt_mtd_nand_device *device, rt_uint32_t block);
rt_err_t (*mark_badblock)(struct rt_mtd_nand_device *device, rt_uint32_t block);
};
rt_err_t rt_mtd_nand_register_device(const char* name, struct rt_mtd_nand_device* device);
rt_err_t rt_mtd_nand_register_device(const char *name, struct rt_mtd_nand_device *device);
rt_inline rt_uint32_t rt_mtd_nand_read_id(struct rt_mtd_nand_device* device)
rt_inline rt_uint32_t rt_mtd_nand_read_id(struct rt_mtd_nand_device *device)
{
return device->ops->read_id(device);
}
rt_inline rt_err_t rt_mtd_nand_read(
struct rt_mtd_nand_device* device,
struct rt_mtd_nand_device *device,
rt_off_t page,
rt_uint8_t* data, rt_uint32_t data_len,
rt_uint8_t * spare, rt_uint32_t spare_len)
rt_uint8_t *data, rt_uint32_t data_len,
rt_uint8_t *spare, rt_uint32_t spare_len)
{
return device->ops->read_page(device, page, data, data_len, spare, spare_len);
}
rt_inline rt_err_t rt_mtd_nand_write(
struct rt_mtd_nand_device* device,
struct rt_mtd_nand_device *device,
rt_off_t page,
const rt_uint8_t* data, rt_uint32_t data_len,
const rt_uint8_t * spare, rt_uint32_t spare_len)
const rt_uint8_t *data, rt_uint32_t data_len,
const rt_uint8_t *spare, rt_uint32_t spare_len)
{
return device->ops->write_page(device, page, data, data_len, spare, spare_len);
}
rt_inline rt_err_t rt_mtd_nand_move_page(struct rt_mtd_nand_device* device,
rt_off_t src_page, rt_off_t dst_page)
rt_inline rt_err_t rt_mtd_nand_move_page(struct rt_mtd_nand_device *device,
rt_off_t src_page, rt_off_t dst_page)
{
return device->ops->move_page(device, src_page, dst_page);
}
rt_inline rt_err_t rt_mtd_nand_erase_block(struct rt_mtd_nand_device* device, rt_uint32_t block)
rt_inline rt_err_t rt_mtd_nand_erase_block(struct rt_mtd_nand_device *device, rt_uint32_t block)
{
return device->ops->erase_block(device, block);
}
rt_inline rt_err_t rt_mtd_nand_check_block(struct rt_mtd_nand_device* device, rt_uint32_t block)
rt_inline rt_err_t rt_mtd_nand_check_block(struct rt_mtd_nand_device *device, rt_uint32_t block)
{
return device->ops->check_block(device, block);
}
rt_inline rt_err_t rt_mtd_nand_mark_badblock(struct rt_mtd_nand_device* device, rt_uint32_t block)
rt_inline rt_err_t rt_mtd_nand_mark_badblock(struct rt_mtd_nand_device *device, rt_uint32_t block)
{
return device->ops->mark_badblock(device, block);
}

View File

@ -56,7 +56,7 @@ static rt_err_t _mtd_control(rt_device_t dev, int cmd, void *args)
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops mtd_nand_ops =
const static struct rt_device_ops mtd_nand_ops =
{
_mtd_init,
_mtd_open,
@ -78,7 +78,7 @@ rt_err_t rt_mtd_nand_register_device(const char *name,
/* set device class and generic device interface */
dev->type = RT_Device_Class_MTD;
#ifdef RT_USING_DEVICE_OPS
dev->ops = &mtd_nand_ops;
dev->ops = &mtd_nand_ops;
#else
dev->init = _mtd_init;
dev->open = _mtd_open;
@ -101,186 +101,186 @@ rt_err_t rt_mtd_nand_register_device(const char *name,
static void mtd_dump_hex(const rt_uint8_t *ptr, rt_size_t buflen)
{
unsigned char *buf = (unsigned char*)ptr;
int i, j;
for (i=0; i<buflen; i+=16)
{
rt_kprintf("%06x: ", i);
for (j=0; j<16; j++)
if (i+j < buflen)
rt_kprintf("%02x ", buf[i+j]);
else
rt_kprintf(" ");
rt_kprintf(" ");
for (j=0; j<16; j++)
if (i+j < buflen)
rt_kprintf("%c", __is_print(buf[i+j]) ? buf[i+j] : '.');
rt_kprintf("\n");
}
unsigned char *buf = (unsigned char *)ptr;
int i, j;
for (i = 0; i < buflen; i += 16)
{
rt_kprintf("%06x: ", i);
for (j = 0; j < 16; j++)
if (i + j < buflen)
rt_kprintf("%02x ", buf[i + j]);
else
rt_kprintf(" ");
rt_kprintf(" ");
for (j = 0; j < 16; j++)
if (i + j < buflen)
rt_kprintf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
rt_kprintf("\n");
}
}
int mtd_nandid(const char* name)
int mtd_nandid(const char *name)
{
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
return rt_mtd_nand_read_id(nand);
return rt_mtd_nand_read_id(nand);
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nandid, nand_id, read ID - nandid(name));
int mtd_nand_read(const char* name, int block, int page)
int mtd_nand_read(const char *name, int block, int page)
{
rt_err_t result;
rt_uint8_t *page_ptr;
rt_uint8_t *oob_ptr;
struct rt_mtd_nand_device *nand;
rt_err_t result;
rt_uint8_t *page_ptr;
rt_uint8_t *oob_ptr;
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
page_ptr = rt_malloc(nand->page_size + nand->oob_size);
if (page_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
page_ptr = rt_malloc(nand->page_size + nand->oob_size);
if (page_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
oob_ptr = page_ptr + nand->page_size;
rt_memset(page_ptr, 0xff, nand->page_size + nand->oob_size);
oob_ptr = page_ptr + nand->page_size;
rt_memset(page_ptr, 0xff, nand->page_size + nand->oob_size);
/* calculate the page number */
page = block * nand->pages_per_block + page;
result = rt_mtd_nand_read(nand, page, page_ptr, nand->page_size,
oob_ptr, nand->oob_size);
/* calculate the page number */
page = block * nand->pages_per_block + page;
result = rt_mtd_nand_read(nand, page, page_ptr, nand->page_size,
oob_ptr, nand->oob_size);
rt_kprintf("read page, rc=%d\n", result);
mtd_dump_hex(page_ptr, nand->page_size);
mtd_dump_hex(oob_ptr, nand->oob_size);
rt_kprintf("read page, rc=%d\n", result);
mtd_dump_hex(page_ptr, nand->page_size);
mtd_dump_hex(oob_ptr, nand->oob_size);
rt_free(page_ptr);
return 0;
rt_free(page_ptr);
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_read, nand_read, read page in nand - nand_read(name, block, page));
int mtd_nand_readoob(const char* name, int block, int page)
int mtd_nand_readoob(const char *name, int block, int page)
{
struct rt_mtd_nand_device *nand;
rt_uint8_t *oob_ptr;
struct rt_mtd_nand_device *nand;
rt_uint8_t *oob_ptr;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
oob_ptr = rt_malloc(nand->oob_size);
if (oob_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
oob_ptr = rt_malloc(nand->oob_size);
if (oob_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
/* calculate the page number */
page = block * nand->pages_per_block + page;
rt_mtd_nand_read(nand, page, RT_NULL, nand->page_size,
oob_ptr, nand->oob_size);
mtd_dump_hex(oob_ptr, nand->oob_size);
/* calculate the page number */
page = block * nand->pages_per_block + page;
rt_mtd_nand_read(nand, page, RT_NULL, nand->page_size,
oob_ptr, nand->oob_size);
mtd_dump_hex(oob_ptr, nand->oob_size);
rt_free(oob_ptr);
return 0;
rt_free(oob_ptr);
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_readoob, nand_readoob, read spare data in nand - nand_readoob(name, block, page));
int mtd_nand_write(const char* name, int block, int page)
int mtd_nand_write(const char *name, int block, int page)
{
rt_err_t result;
rt_uint8_t *page_ptr;
rt_uint8_t *oob_ptr;
rt_uint32_t index;
struct rt_mtd_nand_device *nand;
rt_err_t result;
rt_uint8_t *page_ptr;
rt_uint8_t *oob_ptr;
rt_uint32_t index;
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
page_ptr = rt_malloc(nand->page_size + nand->oob_size);
if (page_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
page_ptr = rt_malloc(nand->page_size + nand->oob_size);
if (page_ptr == RT_NULL)
{
rt_kprintf("out of memory!\n");
return -RT_ENOMEM;
}
oob_ptr = page_ptr + nand->page_size;
/* prepare page data */
for (index = 0; index < nand->page_size; index ++)
{
page_ptr[index] = index & 0xff;
}
/* prepare oob data */
for (index = 0; index < nand->oob_size; index ++)
{
oob_ptr[index] = index & 0xff;
}
oob_ptr = page_ptr + nand->page_size;
/* prepare page data */
for (index = 0; index < nand->page_size; index ++)
{
page_ptr[index] = index & 0xff;
}
/* prepare oob data */
for (index = 0; index < nand->oob_size; index ++)
{
oob_ptr[index] = index & 0xff;
}
/* calculate the page number */
page = block * nand->pages_per_block + page;
result = rt_mtd_nand_write(nand, page, page_ptr, nand->page_size,
oob_ptr, nand->oob_size);
if (result != RT_MTD_EOK)
{
rt_kprintf("write page failed!, rc=%d\n", result);
}
/* calculate the page number */
page = block * nand->pages_per_block + page;
result = rt_mtd_nand_write(nand, page, page_ptr, nand->page_size,
oob_ptr, nand->oob_size);
if (result != RT_MTD_EOK)
{
rt_kprintf("write page failed!, rc=%d\n", result);
}
rt_free(page_ptr);
return 0;
rt_free(page_ptr);
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_write, nand_write, write dump data to nand - nand_write(name, block, page));
int mtd_nand_erase(const char* name, int block)
int mtd_nand_erase(const char *name, int block)
{
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
return rt_mtd_nand_erase_block(nand, block);
return rt_mtd_nand_erase_block(nand, block);
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase, nand_erase, nand_erase(name, block));
int mtd_nand_erase_all(const char* name)
int mtd_nand_erase_all(const char *name)
{
rt_uint32_t index = 0;
struct rt_mtd_nand_device *nand;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
rt_uint32_t index = 0;
struct rt_mtd_nand_device *nand;
for (index = 0; index < (nand->block_end - nand->block_start); index ++)
{
rt_mtd_nand_erase_block(nand, index);
}
return 0;
nand = RT_MTD_NAND_DEVICE(rt_device_find(name));
if (nand == RT_NULL)
{
rt_kprintf("no nand device found!\n");
return -RT_ERROR;
}
for (index = 0; index < (nand->block_end - nand->block_start); index ++)
{
rt_mtd_nand_erase_block(nand, index);
}
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase_all, nand_erase_all, erase all of nand device - nand_erase_all(name, block));
#endif