luat_sfd.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef LUAT_SFD_H
  2. #define LUAT_SFD_H
  3. #include "luat_base.h"
  4. #include "luat_spi.h"
  5. #ifdef __LUATOS__
  6. #include "luat_zbuff.h"
  7. #endif
  8. typedef struct sdf_opts {
  9. int (*initialize) (void* userdata);
  10. int (*status) (void* userdata);
  11. int (*read) (void* userdata, char* buff, size_t offset, size_t len);
  12. int (*write) (void* userdata, const char* buff, size_t offset, size_t len);
  13. int (*erase) (void* userdata, size_t offset, size_t len);
  14. int (*ioctl) (void* userdata, size_t cmd, void* buff);
  15. }sdf_opts_t;
  16. typedef struct sfd_drv {
  17. const sdf_opts_t* opts;
  18. uint8_t type;
  19. union
  20. {
  21. struct sfd_spi {
  22. int id;
  23. int cs;
  24. } spi;
  25. #ifdef __LUATOS__
  26. luat_zbuff_t* zbuff;
  27. #endif
  28. } cfg;
  29. size_t sector_size;
  30. size_t sector_count;
  31. size_t erase_size;
  32. char chip_id[8];
  33. void* userdata;
  34. } sfd_drv_t;
  35. typedef struct sfd_onchip {
  36. char name[8];
  37. size_t addr;
  38. size_t block_count;
  39. size_t block_size;
  40. //const sdf_opts_t* opts;
  41. }sfd_onchip_t;
  42. // int luat_sfd_init (sfd_drv_t* drv);
  43. int luat_sfd_status (sfd_drv_t* drv);
  44. int luat_sfd_read (sfd_drv_t* drv, char* buff, size_t offset, size_t len);
  45. int luat_sfd_write (sfd_drv_t* drv, const char* buff, size_t offset, size_t len);
  46. int luat_sfd_erase (sfd_drv_t* drv, size_t offset, size_t len);
  47. int luat_sfd_ioctl (sfd_drv_t* drv, size_t cmd, void* buff);
  48. int sfd_onchip_init (void* userdata);
  49. int sfd_onchip_status (void* userdata);
  50. int sfd_onchip_read (void* userdata, char* buff, size_t offset, size_t len);
  51. int sfd_onchip_write (void* userdata, const char* buff, size_t offset, size_t len);
  52. int sfd_onchip_erase (void* userdata, size_t offset, size_t len);
  53. int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff);
  54. int luat_sfd_onchip_init(void);
  55. // 临时声明
  56. #include "lfs.h"
  57. #define LFS_BLOCK_DEVICE_READ_SIZE (256)
  58. #define LFS_BLOCK_DEVICE_PROG_SIZE (256)
  59. #define LFS_BLOCK_DEVICE_CACHE_SIZE (256)
  60. #define LFS_BLOCK_DEVICE_ERASE_SIZE (4096) // one sector 4KB
  61. #define LFS_BLOCK_DEVICE_TOTOAL_SIZE (64 * 1024)
  62. #define LFS_BLOCK_DEVICE_LOOK_AHEAD (16)
  63. #define LUAT_sfd_lfs_MAX_SIZE (4096)
  64. typedef struct luat_sfd_lfs
  65. {
  66. char read_buffer[LFS_BLOCK_DEVICE_READ_SIZE];
  67. char prog_buffer[LFS_BLOCK_DEVICE_PROG_SIZE];
  68. // char cache_buffer[LFS_BLOCK_DEVICE_CACHE_SIZE];
  69. char lookahead_buffer[LFS_BLOCK_DEVICE_LOOK_AHEAD];
  70. lfs_t lfs;
  71. struct lfs_config conf;
  72. }luat_sfd_lfs_t;
  73. int luat_sfd_lfs_init(sfd_drv_t *drv);
  74. #endif