Forráskód Böngészése

fix: lfs2在win32上挂载内存镜像报的错误, 修正之

Wendal Chen 4 éve
szülő
commit
fa595ebf72

+ 1 - 0
bsp/win32/port/luat_base_win32.c

@@ -37,6 +37,7 @@ static const luaL_Reg loadedlibs[] = {
 #endif
   {"crypto", luaopen_crypto},
   {"fatfs", luaopen_fatfs},
+  {"sfd",   luaopen_sfd},
   {"lfs2",   luaopen_lfs2},
   {NULL, NULL}
 };

+ 3 - 1
luat/modules/luat_lib_sfd.c

@@ -11,8 +11,9 @@
 #define LUAT_LOG_SDF
 #include "luat_log.h"
 
-
+#ifndef LUA_USE_WINDOWS
 extern const sdf_opts_t sfd_w25q_opts;
+#endif
 extern const sdf_opts_t sfd_mem_opts;
 
 /*
@@ -56,6 +57,7 @@ static int l_sfd_init(lua_State *L) {
         drv->type = 1;
         drv->cfg.zbuff = luaL_checkudata(L, 2, "ZBUFF*");
         drv->opts = &sfd_mem_opts;
+        drv->sector_count = drv->cfg.zbuff->len / 256;
 
         int re = drv->opts->initialize(drv);
         if (re == 0) {

+ 2 - 2
luat/modules/luat_sfd.c

@@ -12,7 +12,7 @@
 #define CS_L(pin) luat_gpio_set(pin, 0)
 
 // 针对drv的实现
-
+#ifndef LUA_USE_WINDOWS
 static int sfd_w25q_init (void* userdata);
 static int sfd_w25q_status (void* userdata);
 static int sfd_w25q_read (void* userdata, char* buff, size_t offset, size_t len);
@@ -124,7 +124,7 @@ static int sfd_w25q_erase (void* userdata, size_t offset, size_t len) {
 static int sfd_w25q_ioctl (void* userdata, size_t cmd, void* buff) {
     return -1;
 }
-
+#endif
 
 //--------------------------------------------------------------------
 // SFD at memory ,  for test

+ 9 - 3
luat/packages/lfs/lfs_sfd.c

@@ -13,7 +13,9 @@
 
 int lfs_sfd_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
     sfd_drv_t *drv = (sfd_drv_t *)c->context;
-    return drv->opts->read(drv, buffer, block*4096+off, size);
+    int ret = drv->opts->read(drv, buffer, block*4096+off, size);
+    if (ret >= 0 && size >= ret) return LFS_ERR_OK;
+    return LFS_ERR_IO;
 }
 
     // Program a region in a block. The block must have previously
@@ -21,7 +23,9 @@ int lfs_sfd_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, v
     // May return LFS_ERR_CORRUPT if the block should be considered bad.
 int lfs_sfd_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
     sfd_drv_t *drv = (sfd_drv_t *)c->context;
-    return drv->opts->write(drv, buffer, block*4096+off, size);
+    int ret =  drv->opts->write(drv, buffer, block*4096+off, size);
+    if (ret >= 0 && size >= ret) return LFS_ERR_OK;
+    return LFS_ERR_IO;
 }
 
     // Erase a block. A block must be erased before being programmed.
@@ -30,7 +34,9 @@ int lfs_sfd_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, c
     // May return LFS_ERR_CORRUPT if the block should be considered bad.
 int lfs_sfd_erase(const struct lfs_config *c, lfs_block_t block) {
     sfd_drv_t *drv = (sfd_drv_t *)c->context;
-    return drv->opts->erase(drv, block*4096, 4096);
+    int ret = drv->opts->erase(drv, block*4096, 4096);
+    if (ret == 0) return LFS_ERR_OK;
+    return LFS_ERR_IO;
 }
 
     // Sync the state of the underlying block device. Negative error codes

+ 2 - 2
luat/packages/lfs/luat_lib_lfs2.c

@@ -66,8 +66,8 @@ static int l_lfs2_mount(lua_State *L) {
             cfg->block_size = 4096;
             cfg->block_count = drv->sector_count / 16;
             cfg->block_cycles = 200;
-            cfg->cache_size = 16;
-            cfg->lookahead_size = 256;
+            cfg->cache_size = 256;
+            cfg->lookahead_size = 16;
 
             cfg->read_buffer = luat_heap_malloc(256);
             cfg->prog_buffer = luat_heap_malloc(256);