diff --git a/app/include/user_config.h b/app/include/user_config.h index 4be67347..b600eaf7 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -47,6 +47,8 @@ // #define BUILD_WOFS 1 #define BUILD_SPIFFS 1 +#define SPIFFS_CACHE 1 + // #define LUA_NUMBER_INTEGRAL #define LUA_OPTRAM diff --git a/app/modules/file.c b/app/modules/file.c index d055ef87..b4a9cfa0 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -196,11 +196,10 @@ static int file_fsinfo( lua_State* L ) // g_read() static int file_g_read( lua_State* L, int n, int16_t end_char ) { - if(n< 0 || n>LUAL_BUFFERSIZE) + if(n <= 0 || n > LUAL_BUFFERSIZE) n = LUAL_BUFFERSIZE; if(end_char < 0 || end_char >255) end_char = EOF; - int ec = (int)end_char; luaL_Buffer b; if((FS_OPEN_OK - 1)==file_fd) @@ -208,27 +207,22 @@ static int file_g_read( lua_State* L, int n, int16_t end_char ) luaL_buffinit(L, &b); char *p = luaL_prepbuffer(&b); - int c = EOF; - int i = 0; + int i; - do{ - c = fs_getc(file_fd); - if(c==EOF){ + n = fs_read(file_fd, p, n); + for (i = 0; i < n; ++i) + if (p[i] == end_char) + { + ++i; break; } - p[i++] = (char)(0xFF & c); - }while((c!=EOF) && (c!=ec) && (i0 && p[i-1] == '\n') - i--; /* do not include `eol' */ -#endif - if(i==0){ luaL_pushresult(&b); /* close buffer */ return (lua_objlen(L, -1) > 0); /* check whether read something */ } + fs_seek(file_fd, -(n - i), SEEK_CUR); luaL_addsize(&b, i); luaL_pushresult(&b); /* close buffer */ return 1; /* read at least an `eol' */ diff --git a/app/spiffs/spiffs.c b/app/spiffs/spiffs.c index bcb11d5c..bae70860 100644 --- a/app/spiffs/spiffs.c +++ b/app/spiffs/spiffs.c @@ -8,7 +8,9 @@ spiffs fs; static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2]; static u8_t spiffs_fds[32*4]; -static u8_t spiffs_cache[(LOG_PAGE_SIZE+32)*4]; +#if SPIFFS_CACHE +static u8_t spiffs_cache[(LOG_PAGE_SIZE+32)*2]; +#endif static s32_t my_spiffs_read(u32_t addr, u32_t size, u8_t *dst) { platform_flash_read(dst, addr, size); @@ -62,8 +64,12 @@ void myspiffs_mount() { spiffs_work_buf, spiffs_fds, sizeof(spiffs_fds), +#if SPIFFS_CACHE spiffs_cache, sizeof(spiffs_cache), +#else + 0, 0, +#endif // myspiffs_check_callback); 0); NODE_DBG("mount res: %i\n", res); diff --git a/app/spiffs/spiffs_config.h b/app/spiffs/spiffs_config.h index 0dc19958..52d6b9d9 100644 --- a/app/spiffs/spiffs_config.h +++ b/app/spiffs/spiffs_config.h @@ -8,16 +8,10 @@ #ifndef SPIFFS_CONFIG_H_ #define SPIFFS_CONFIG_H_ -// ----------- 8< ------------ -// Following includes are for the linux test build of spiffs -// These may/should/must be removed/altered/replaced in your target -// #include "params_test.h" +#include "user_config.h" #include "c_stdio.h" -#include "c_stdlib.h" +#include "c_stdint.h" #include "c_string.h" -#include "c_stddef.h" -#include "c_types.h" -// ----------- >8 ------------ typedef sint32_t s32_t; typedef uint32_t u32_t; @@ -67,6 +61,8 @@ typedef uint8_t u8_t; #ifndef SPIFFS_CACHE_STATS #define SPIFFS_CACHE_STATS 0 #endif +#else +#define SPIFFS_CACHE_WR 0 #endif // Always check header of each accessed page to ensure consistent state. diff --git a/app/spiffs/spiffs_nucleus.h b/app/spiffs/spiffs_nucleus.h index 02ba7a96..65806d38 100644 --- a/app/spiffs/spiffs_nucleus.h +++ b/app/spiffs/spiffs_nucleus.h @@ -405,7 +405,7 @@ typedef struct { // page header, part of each page except object lookup pages // NB: this is always aligned when the data page is an object index, // as in this case struct spiffs_page_object_ix is used -typedef struct __attribute(( packed )) { +typedef struct __attribute(( packed, aligned(4) )) { // object id spiffs_obj_id obj_id; // object span index