mtd_nor.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-5-30 Bernard the first version
  9. */
  10. #ifndef __MTD_NOR_H__
  11. #define __MTD_NOR_H__
  12. #include <rtdevice.h>
  13. struct rt_mtd_nor_driver_ops;
  14. #define RT_MTD_NOR_DEVICE(device) ((struct rt_mtd_nor_device*)(device))
  15. struct rt_mtd_nor_device
  16. {
  17. struct rt_device parent;
  18. rt_uint32_t block_size; /* The Block size in the flash */
  19. rt_uint32_t block_start; /* The start of available block*/
  20. rt_uint32_t block_end; /* The end of available block */
  21. /* operations interface */
  22. const struct rt_mtd_nor_driver_ops* ops;
  23. };
  24. struct rt_mtd_nor_driver_ops
  25. {
  26. rt_err_t (*read_id) (struct rt_mtd_nor_device* device);
  27. rt_size_t (*read) (struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint8_t* data, rt_uint32_t length);
  28. rt_size_t (*write) (struct rt_mtd_nor_device* device, rt_off_t offset, const rt_uint8_t* data, rt_uint32_t length);
  29. rt_err_t (*erase_block)(struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint32_t length);
  30. };
  31. rt_err_t rt_mtd_nor_register_device(const char* name, struct rt_mtd_nor_device* device);
  32. rt_inline rt_uint32_t rt_mtd_nor_read_id(struct rt_mtd_nor_device* device)
  33. {
  34. return device->ops->read_id(device);
  35. }
  36. rt_inline rt_size_t rt_mtd_nor_read(
  37. struct rt_mtd_nor_device* device,
  38. rt_off_t offset, rt_uint8_t* data, rt_uint32_t length)
  39. {
  40. return device->ops->read(device, offset, data, length);
  41. }
  42. rt_inline rt_size_t rt_mtd_nor_write(
  43. struct rt_mtd_nor_device* device,
  44. rt_off_t offset, const rt_uint8_t* data, rt_uint32_t length)
  45. {
  46. return device->ops->write(device, offset, data, length);
  47. }
  48. rt_inline rt_err_t rt_mtd_nor_erase_block(struct rt_mtd_nor_device* device, rt_off_t offset, rt_size_t length)
  49. {
  50. return device->ops->erase_block(device, offset, length);
  51. }
  52. #endif