luat_sfd.h 2.4 KB

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