mtd_nor.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * COPYRIGHT (C) 2011-2023, 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 <rtthread.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_ssize_t (*read) (struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint8_t* data, rt_size_t length);
  28. rt_ssize_t (*write) (struct rt_mtd_nor_device* device, rt_off_t offset, const rt_uint8_t* data, rt_size_t length);
  29. rt_err_t (*erase_block)(struct rt_mtd_nor_device* device, rt_off_t offset, rt_size_t length);
  30. };
  31. rt_err_t rt_mtd_nor_register_device(const char* name, struct rt_mtd_nor_device* device);
  32. rt_uint32_t rt_mtd_nor_read_id(struct rt_mtd_nor_device* device);
  33. rt_ssize_t rt_mtd_nor_read(struct rt_mtd_nor_device* device,
  34. rt_off_t offset, rt_uint8_t* data, rt_size_t length);
  35. rt_ssize_t rt_mtd_nor_write(struct rt_mtd_nor_device* device,
  36. rt_off_t offset, const rt_uint8_t* data, rt_size_t length);
  37. rt_err_t rt_mtd_nor_erase_block(struct rt_mtd_nor_device* device,
  38. rt_off_t offset, rt_size_t length);
  39. #endif