lfs_sfd.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. #include "luat_base.h"
  3. #include "luat_sfd.h"
  4. #include "luat_spi.h"
  5. #include "luat_gpio.h"
  6. #include "luat_malloc.h"
  7. #include "lfs.h"
  8. #define LUAT_LOG_TAG "lfs2"
  9. #include "luat_log.h"
  10. int lfs_sfd_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
  11. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  12. int ret = drv->opts->read(drv, buffer, block*4096+off, size);
  13. if (ret >= 0 && size >= ret) return LFS_ERR_OK;
  14. return LFS_ERR_IO;
  15. }
  16. // Program a region in a block. The block must have previously
  17. // been erased. Negative error codes are propogated to the user.
  18. // May return LFS_ERR_CORRUPT if the block should be considered bad.
  19. int lfs_sfd_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
  20. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  21. int ret = drv->opts->write(drv, buffer, block*4096+off, size);
  22. if (ret >= 0 && size >= ret) return LFS_ERR_OK;
  23. return LFS_ERR_IO;
  24. }
  25. // Erase a block. A block must be erased before being programmed.
  26. // The state of an erased block is undefined. Negative error codes
  27. // are propogated to the user.
  28. // May return LFS_ERR_CORRUPT if the block should be considered bad.
  29. int lfs_sfd_erase(const struct lfs_config *c, lfs_block_t block) {
  30. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  31. int ret = drv->opts->erase(drv, block*4096, 4096);
  32. if (ret == 0) return LFS_ERR_OK;
  33. return LFS_ERR_IO;
  34. }
  35. // Sync the state of the underlying block device. Negative error codes
  36. // are propogated to the user.
  37. int lfs_sfd_sync(const struct lfs_config *c) {
  38. // sfd_drv_t *drv = (sfd_drv_t *)c->context;
  39. //drv->opts->ioctl(drv, ???);
  40. return 0;
  41. }