mtd_nand.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * File : mtd_nand.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-12-05 Bernard the first version
  13. * 2011-04-02 prife add mark_badblock and check_block
  14. */
  15. /*
  16. * COPYRIGHT (C) 2012, Shanghai Real Thread
  17. */
  18. #ifndef __MTD_NAND_H__
  19. #define __MTD_NAND_H__
  20. #include <rtdevice.h>
  21. struct rt_mtd_nand_driver_ops;
  22. #define RT_MTD_NAND_DEVICE(device) ((struct rt_mtd_nand_device*)(device))
  23. #define RT_MTD_EOK 0
  24. #define RT_MTD_EECC 1
  25. #define RT_MTD_EBUSY 2
  26. #define RT_MTD_EIO 3
  27. #define RT_MTD_ENOMEM 4
  28. struct rt_mtd_nand_device
  29. {
  30. struct rt_device parent;
  31. rt_uint16_t page_size; /* The Page size in the flash */
  32. rt_uint16_t oob_size; /* Out of bank size */
  33. rt_uint16_t oob_free; /* the free area in oob that flash driver not use */
  34. rt_uint16_t plane_num; /* the number of plane in the NAND Flash */
  35. rt_uint32_t pages_per_block; /* The number of page a block */
  36. rt_uint16_t block_total;
  37. rt_uint32_t block_start; /* The start of available block*/
  38. rt_uint32_t block_end; /* The end of available block */
  39. /* operations interface */
  40. const struct rt_mtd_nand_driver_ops* ops;
  41. };
  42. struct rt_mtd_nand_driver_ops
  43. {
  44. rt_err_t (*read_id) (struct rt_mtd_nand_device* device);
  45. rt_err_t (*read_page)(struct rt_mtd_nand_device* device,
  46. rt_off_t page,
  47. rt_uint8_t* data, rt_uint32_t data_len,
  48. rt_uint8_t * spare, rt_uint32_t spare_len);
  49. rt_err_t (*write_page)(struct rt_mtd_nand_device * device,
  50. rt_off_t page,
  51. const rt_uint8_t * data, rt_uint32_t data_len,
  52. const rt_uint8_t * spare, rt_uint32_t spare_len);
  53. rt_err_t (*move_page) (struct rt_mtd_nand_device *device, rt_off_t src_page, rt_off_t dst_page);
  54. rt_err_t (*erase_block)(struct rt_mtd_nand_device* device, rt_uint32_t block);
  55. rt_err_t (*check_block)(struct rt_mtd_nand_device* device, rt_uint32_t block);
  56. rt_err_t (*mark_badblock)(struct rt_mtd_nand_device* device, rt_uint32_t block);
  57. };
  58. rt_err_t rt_mtd_nand_register_device(const char* name, struct rt_mtd_nand_device* device);
  59. rt_inline rt_uint32_t rt_mtd_nand_read_id(struct rt_mtd_nand_device* device)
  60. {
  61. return device->ops->read_id(device);
  62. }
  63. rt_inline rt_err_t rt_mtd_nand_read(
  64. struct rt_mtd_nand_device* device,
  65. rt_off_t page,
  66. rt_uint8_t* data, rt_uint32_t data_len,
  67. rt_uint8_t * spare, rt_uint32_t spare_len)
  68. {
  69. return device->ops->read_page(device, page, data, data_len, spare, spare_len);
  70. }
  71. rt_inline rt_err_t rt_mtd_nand_write(
  72. struct rt_mtd_nand_device* device,
  73. rt_off_t page,
  74. const rt_uint8_t* data, rt_uint32_t data_len,
  75. const rt_uint8_t * spare, rt_uint32_t spare_len)
  76. {
  77. return device->ops->write_page(device, page, data, data_len, spare, spare_len);
  78. }
  79. rt_inline rt_err_t rt_mtd_nand_move_page(struct rt_mtd_nand_device* device,
  80. rt_off_t src_page, rt_off_t dst_page)
  81. {
  82. return device->ops->move_page(device, src_page, dst_page);
  83. }
  84. rt_inline rt_err_t rt_mtd_nand_erase_block(struct rt_mtd_nand_device* device, rt_uint32_t block)
  85. {
  86. return device->ops->erase_block(device, block);
  87. }
  88. rt_inline rt_err_t rt_mtd_nand_check_block(struct rt_mtd_nand_device* device, rt_uint32_t block)
  89. {
  90. return device->ops->check_block(device, block);
  91. }
  92. rt_inline rt_err_t rt_mtd_nand_mark_badblock(struct rt_mtd_nand_device* device, rt_uint32_t block)
  93. {
  94. return device->ops->mark_badblock(device, block);
  95. }
  96. #endif /* MTD_NAND_H_ */