mtd_nor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * File : mtd_nor.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012, Shanghai Real-Thread Technology Co., Ltd
  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. * 2012-5-30 Bernard the first version
  13. */
  14. #ifndef __MTD_NOR_H__
  15. #define __MTD_NOR_H__
  16. #include <rtdevice.h>
  17. struct rt_mtd_nor_driver_ops;
  18. #define RT_MTD_NOR_DEVICE(device) ((struct rt_mtd_nor_device*)(device))
  19. struct rt_mtd_nor_device
  20. {
  21. struct rt_device parent;
  22. rt_uint32_t block_size; /* The Block size in the flash */
  23. rt_uint32_t block_start; /* The start of available block*/
  24. rt_uint32_t block_end; /* The end of available block */
  25. /* operations interface */
  26. const struct rt_mtd_nor_driver_ops* ops;
  27. };
  28. struct rt_mtd_nor_driver_ops
  29. {
  30. rt_err_t (*read_id) (struct rt_mtd_nor_device* device);
  31. rt_size_t (*read) (struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint8_t* data, rt_uint32_t length);
  32. rt_size_t (*write) (struct rt_mtd_nor_device* device, rt_off_t offset, const rt_uint8_t* data, rt_uint32_t length);
  33. rt_err_t (*erase_block)(struct rt_mtd_nor_device* device, rt_off_t offset, rt_uint32_t length);
  34. };
  35. rt_err_t rt_mtd_nor_register_device(const char* name, struct rt_mtd_nor_device* device);
  36. rt_inline rt_uint32_t rt_mtd_nor_read_id(struct rt_mtd_nor_device* device)
  37. {
  38. return device->ops->read_id(device);
  39. }
  40. rt_inline rt_size_t rt_mtd_nor_read(
  41. struct rt_mtd_nor_device* device,
  42. rt_off_t offset, rt_uint8_t* data, rt_uint32_t length)
  43. {
  44. return device->ops->read(device, offset, data, length);
  45. }
  46. rt_inline rt_size_t rt_mtd_nor_write(
  47. struct rt_mtd_nor_device* device,
  48. rt_off_t offset, const rt_uint8_t* data, rt_uint32_t length)
  49. {
  50. return device->ops->write(device, offset, data, length);
  51. }
  52. rt_inline rt_err_t rt_mtd_nor_erase_block(struct rt_mtd_nor_device* device, rt_off_t offset, rt_size_t length)
  53. {
  54. return device->ops->erase_block(device, offset, length);
  55. }
  56. #endif