luat_sdio_air101.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "luat_base.h"
  2. #include "luat_sdio.h"
  3. #define LUAT_LOG_TAG "luat.sdio"
  4. #include "luat_log.h"
  5. #include "wm_sdio_host.h"
  6. #include "luat_fs.h"
  7. #include "ff.h"
  8. FATFS fs;
  9. BYTE work[FF_MAX_SS];
  10. #ifdef LUAT_USE_FS_VFS
  11. extern const struct luat_vfs_filesystem vfs_fs_fatfs;
  12. #endif
  13. int luat_sdio_init(int id){
  14. if (id == 0) {
  15. wm_sdio_host_config(0);
  16. return 0;
  17. }
  18. #ifdef AIR103
  19. else if (id == 1) {
  20. wm_sdio_host_config(1);
  21. return 0;
  22. }
  23. #endif
  24. return -1;
  25. }
  26. int luat_sdio_sd_read(int id, int rca, char* buff, size_t offset, size_t len){
  27. return wm_sd_card_blocks_read(rca, offset, buff, len);
  28. }
  29. int luat_sdio_sd_write(int id, int rca, char* buff, size_t offset, size_t len){
  30. return wm_sd_card_blocks_write(rca, offset, buff, len);
  31. }
  32. int luat_sdio_sd_mount(int id, int *rca, char* path,int auto_format){
  33. FRESULT res_sd;
  34. res_sd = f_mount(&fs, "/", 1);
  35. if (res_sd) {
  36. LLOGD("mount ret = %d", res_sd);
  37. if (res_sd == FR_NO_FILESYSTEM && auto_format) {
  38. res_sd = f_mkfs("/", 0, work, sizeof(work));
  39. if(res_sd == FR_OK){
  40. res_sd = f_mount(NULL, "/", 1);
  41. res_sd = f_mount(&fs, "/", 1);
  42. }
  43. else {
  44. LLOGD("format ret = %d", res_sd);
  45. }
  46. }
  47. }
  48. if (res_sd != FR_OK) {
  49. return res_sd;
  50. }
  51. #ifdef LUAT_USE_FS_VFS
  52. luat_vfs_reg(&vfs_fs_fatfs);
  53. luat_fs_conf_t conf = {
  54. .busname = &fs,
  55. .type = "fatfs",
  56. .filesystem = "fatfs",
  57. .mount_point = path,
  58. };
  59. luat_fs_mount(&conf);
  60. #endif
  61. return 0;
  62. }
  63. int luat_sdio_sd_unmount(int id, int rca){
  64. return f_mount(NULL, "/", 1);
  65. }
  66. int luat_sdio_sd_format(int id, int rca){
  67. f_mkfs("/", 0, work, sizeof(work));
  68. return 0;
  69. }