Explorar el Código

Merge branch 'master' of https://gitee.com/openLuat/LuatOS

alienwalker hace 1 año
padre
commit
9b94e2188c

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 346 - 157
components/lfs/lfs.c


+ 77 - 22
components/lfs/lfs.h

@@ -21,7 +21,7 @@ extern "C"
 // Software library version
 // Major (top-nibble), incremented on backwards incompatible changes
 // Minor (bottom-nibble), incremented on feature additions
-#define LFS_VERSION 0x00020007
+#define LFS_VERSION 0x00020009
 #define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
 #define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >>  0))
 
@@ -52,16 +52,15 @@ typedef uint32_t lfs_block_t;
 #endif
 
 // Maximum size of a file in bytes, may be redefined to limit to support other
-// drivers. Limited on disk to <= 4294967296. However, above 2147483647 the
-// functions lfs_file_seek, lfs_file_size, and lfs_file_tell will return
-// incorrect values due to using signed integers. Stored in superblock and
-// must be respected by other littlefs drivers.
+// drivers. Limited on disk to <= 2147483647. Stored in superblock and must be
+// respected by other littlefs drivers.
 #ifndef LFS_FILE_MAX
 #define LFS_FILE_MAX 2147483647
 #endif
 
 // Maximum size of custom attributes in bytes, may be redefined, but there is
-// no real benefit to using a smaller LFS_ATTR_MAX. Limited to <= 1022.
+// no real benefit to using a smaller LFS_ATTR_MAX. Limited to <= 1022. Stored
+// in superblock and must be respected by other littlefs drivers.
 #ifndef LFS_ATTR_MAX
 #define LFS_ATTR_MAX 1022
 #endif
@@ -205,7 +204,8 @@ struct lfs_config {
     // program sizes.
     lfs_size_t block_size;
 
-    // Number of erasable blocks on the device.
+    // Number of erasable blocks on the device. Defaults to block_count stored
+    // on disk when zero.
     lfs_size_t block_count;
 
     // Number of erase cycles before littlefs evicts metadata logs and moves
@@ -226,9 +226,20 @@ struct lfs_config {
     // Size of the lookahead buffer in bytes. A larger lookahead buffer
     // increases the number of blocks found during an allocation pass. The
     // lookahead buffer is stored as a compact bitmap, so each byte of RAM
-    // can track 8 blocks. Must be a multiple of 8.
+    // can track 8 blocks.
     lfs_size_t lookahead_size;
 
+    // Threshold for metadata compaction during lfs_fs_gc in bytes. Metadata
+    // pairs that exceed this threshold will be compacted during lfs_fs_gc.
+    // Defaults to ~88% block_size when zero, though the default may change
+    // in the future.
+    //
+    // Note this only affects lfs_fs_gc. Normal compactions still only occur
+    // when full.
+    //
+    // Set to -1 to disable metadata compaction during lfs_fs_gc.
+    lfs_size_t compact_thresh;
+
     // Optional statically allocated read buffer. Must be cache_size.
     // By default lfs_malloc is used to allocate this buffer.
     void *read_buffer;
@@ -237,25 +248,24 @@ struct lfs_config {
     // By default lfs_malloc is used to allocate this buffer.
     void *prog_buffer;
 
-    // Optional statically allocated lookahead buffer. Must be lookahead_size
-    // and aligned to a 32-bit boundary. By default lfs_malloc is used to
-    // allocate this buffer.
+    // Optional statically allocated lookahead buffer. Must be lookahead_size.
+    // By default lfs_malloc is used to allocate this buffer.
     void *lookahead_buffer;
 
     // Optional upper limit on length of file names in bytes. No downside for
     // larger names except the size of the info struct which is controlled by
-    // the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX when zero. Stored in
-    // superblock and must be respected by other littlefs drivers.
+    // the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX or name_max stored on
+    // disk when zero.
     lfs_size_t name_max;
 
     // Optional upper limit on files in bytes. No downside for larger files
-    // but must be <= LFS_FILE_MAX. Defaults to LFS_FILE_MAX when zero. Stored
-    // in superblock and must be respected by other littlefs drivers.
+    // but must be <= LFS_FILE_MAX. Defaults to LFS_FILE_MAX or file_max stored
+    // on disk when zero.
     lfs_size_t file_max;
 
     // Optional upper limit on custom attributes in bytes. No downside for
     // larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
-    // LFS_ATTR_MAX when zero.
+    // LFS_ATTR_MAX or attr_max stored on disk when zero.
     lfs_size_t attr_max;
 
     // Optional upper limit on total space given to metadata pairs in bytes. On
@@ -264,6 +274,15 @@ struct lfs_config {
     // Defaults to block_size when zero.
     lfs_size_t metadata_max;
 
+    // Optional upper limit on inlined files in bytes. Inlined files live in
+    // metadata and decrease storage requirements, but may be limited to
+    // improve metadata-related performance. Must be <= cache_size, <=
+    // attr_max, and <= block_size/8. Defaults to the largest possible
+    // inline_max when zero.
+    //
+    // Set to -1 to disable inlined files.
+    lfs_size_t inline_max;
+
 #ifdef LFS_MULTIVERSION
     // On-disk version to use when writing in the form of 16-bit major version
     // + 16-bit minor version. This limiting metadata to what is supported by
@@ -293,6 +312,12 @@ struct lfs_fsinfo {
     // On-disk version.
     uint32_t disk_version;
 
+    // Size of a logical block in bytes.
+    lfs_size_t block_size;
+
+    // Number of logical blocks in filesystem.
+    lfs_size_t block_count;
+
     // Upper limit on the length of file names in bytes.
     lfs_size_t name_max;
 
@@ -424,18 +449,20 @@ typedef struct lfs {
     lfs_gstate_t gdisk;
     lfs_gstate_t gdelta;
 
-    struct lfs_free {
-        lfs_block_t off;
+    struct lfs_lookahead {
+        lfs_block_t start;
         lfs_block_t size;
-        lfs_block_t i;
-        lfs_block_t ack;
-        uint32_t *buffer;
-    } free;
+        lfs_block_t next;
+        lfs_block_t ckpoint;
+        uint8_t *buffer;
+    } lookahead;
 
     const struct lfs_config *cfg;
+    lfs_size_t block_count;
     lfs_size_t name_max;
     lfs_size_t file_max;
     lfs_size_t attr_max;
+    lfs_size_t inline_max;
 
 #ifdef LFS_MIGRATE
     struct lfs1 *lfs1;
@@ -717,6 +744,34 @@ int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
 int lfs_fs_mkconsistent(lfs_t *lfs);
 #endif
 
+#ifndef LFS_READONLY
+// Attempt any janitorial work
+//
+// This currently:
+// 1. Calls mkconsistent if not already consistent
+// 2. Compacts metadata > compact_thresh
+// 3. Populates the block allocator
+//
+// Though additional janitorial work may be added in the future.
+//
+// Calling this function is not required, but may allow the offloading of
+// expensive janitorial work to a less time-critical code path.
+//
+// Returns a negative error code on failure. Accomplishing nothing is not
+// an error.
+int lfs_fs_gc(lfs_t *lfs);
+#endif
+
+#ifndef LFS_READONLY
+// Grows the filesystem to a new size, updating the superblock with the new
+// block count.
+//
+// Note: This is irreversible.
+//
+// Returns a negative error code on failure.
+int lfs_fs_grow(lfs_t *lfs, lfs_size_t block_count);
+#endif
+
 #ifndef LFS_READONLY
 #ifdef LFS_MIGRATE
 // Attempts to migrate a previous version of littlefs

+ 3 - 0
components/lfs/lfs_util.c

@@ -11,6 +11,8 @@
 #ifndef LFS_CONFIG
 
 
+// If user provides their own CRC impl we don't need this
+#ifndef LFS_CRC
 // Software CRC implementation with small lookup table
 uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
     static const uint32_t rtable[16] = {
@@ -29,6 +31,7 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
 
     return crc;
 }
+#endif
 
 
 #endif

+ 20 - 5
components/lfs/lfs_util.h

@@ -226,13 +226,26 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
 }
 
 // Calculate CRC-32 with polynomial = 0x04c11db7
+#ifdef LFS_CRC
+uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
+    return LFS_CRC(crc, buffer, size)
+}
+#else
 uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
+#endif
+
+#define LFS_MALLOC luat_heap_malloc
+#define LFS_FREE luat_heap_free
 
 // Allocate memory, only used if buffers are not provided to littlefs
-// Note, memory must be 64-bit aligned
+//
+// littlefs current has no alignment requirements, as it only allocates
+// byte-level buffers.
 static inline void *lfs_malloc(size_t size) {
-#ifndef LFS_NO_MALLOC
-    return luat_heap_malloc(size);
+#if defined(LFS_MALLOC)
+    return LFS_MALLOC(size);
+#elif !defined(LFS_NO_MALLOC)
+    return malloc(size);
 #else
     (void)size;
     return NULL;
@@ -241,8 +254,10 @@ static inline void *lfs_malloc(size_t size) {
 
 // Deallocate memory, only used if buffers are not provided to littlefs
 static inline void lfs_free(void *p) {
-#ifndef LFS_NO_MALLOC
-    luat_heap_free(p);
+#if defined(LFS_FREE)
+    LFS_FREE(p);
+#elif !defined(LFS_NO_MALLOC)
+    free(p);
 #else
     (void)p;
 #endif

+ 67 - 18
components/mobile/luat_lib_mobile.c

@@ -541,24 +541,82 @@ static int l_mobile_enbid(lua_State* L) {
     return 1;
 }
 
+
+static inline uint16_t u162bcd(uint16_t src) {
+    uint8_t high = (src >> 8) & 0xFF;
+    uint8_t low  = src & 0xFF;
+    uint16_t dst = 0;
+    dst += (low & 0x0F) + (low >> 4) * 10;
+    dst += ((high & 0x0F) + (high >> 4) * 10) * 100;
+    //LLOGD("src %04X dst %d", src, dst);
+    return dst;
+}
+
 /**
 获取当前服务小区更详细的信息
 @api mobile.scell()
-@return int 服务小区的MCC
-@return int 服务小区的MNC
-@return int 服务小区的下行earfcn
-@return int 服务小区的pci
+@return table 服务小区的信息
 @usage
 -- 本API于 2024.9.12 新增
+log.info("cell", json.encode(mobile.scell()))
+-- 返回值示例
+{
+    "mnc": 11,
+    "mcc": 460,
+    "rssi": -78,
+    "pci": 115,
+    "rsrp": -107,
+    "tac": 30005,
+    "eci": 124045360,
+    "rsrq": -9,
+    "snr": 15,
+    "earfcn": 1850
+}
  */
 static int l_mobile_scell_extern_info(lua_State* L) {
-	luat_mobile_scell_extern_info_t info;
-    luat_mobile_get_extern_service_cell_info(&info);
-    lua_pushinteger(L, info.mcc);
-    lua_pushinteger(L, info.mnc);
+	luat_mobile_scell_extern_info_t info = {0};
+    int ret = 0;
+    ret = luat_mobile_get_extern_service_cell_info(&info);
+    if (ret) {
+        return 0;
+    }
+    lua_newtable(L);
+
+    // 驻网信息相关
+    lua_pushinteger(L, u162bcd(info.mcc));
+    lua_setfield(L, -2, "mcc");
+    lua_pushinteger(L, u162bcd(info.mnc));
+    lua_setfield(L, -2, "mnc");
     lua_pushinteger(L, info.earfcn);
+    lua_setfield(L, -2, "earfcn");
     lua_pushinteger(L, info.pci);
-    return 4;
+    lua_setfield(L, -2, "pci");
+
+    // 基站相关
+    uint32_t eci = 0;
+    uint32_t tac = 0;
+    luat_mobile_get_service_cell_identifier(&eci);
+    lua_pushinteger(L, eci);
+    lua_setfield(L, -2, "eci");
+    
+    luat_mobile_get_service_tac_or_lac(&tac);
+    lua_pushinteger(L, tac);
+    lua_setfield(L, -2, "tac");
+
+    // 信号强度相关的值
+    luat_mobile_signal_strength_info_t sinfo = {0};
+    luat_mobile_get_signal_strength_info(&sinfo);
+
+    lua_pushinteger(L, sinfo.lte_signal_strength.snr);
+    lua_setfield(L, -2, "snr");
+    lua_pushinteger(L, sinfo.lte_signal_strength.rsrp);
+    lua_setfield(L, -2, "rsrp");
+    lua_pushinteger(L, sinfo.lte_signal_strength.rsrq);
+    lua_setfield(L, -2, "rsrq");
+    lua_pushinteger(L, sinfo.lte_signal_strength.rssi);
+    lua_setfield(L, -2, "rssi");
+
+    return 1;
 }
 
 /**
@@ -619,15 +677,6 @@ static int l_mobile_status(lua_State* L) {
     return 1;
 }
 
-static inline uint16_t u162bcd(uint16_t src) {
-    uint8_t high = (src >> 8) & 0xFF;
-    uint8_t low  = src & 0xFF;
-    uint16_t dst = 0;
-    dst += (low & 0x0F) + (low >> 4) * 10;
-    dst += ((high & 0x0F) + (high >> 4) * 10) * 100;
-    //LLOGD("src %04X dst %d", src, dst);
-    return dst;
-}
 
 /**
 获取基站信息

+ 19 - 20
demo/mobile/main.lua

@@ -26,8 +26,8 @@ sys.taskInit(function()
 
 	if rtos.bsp() == "UIS8850BM" then
 		sys.wait(2000)
-	end
-
+	end
+
 	log.info("status", mobile.status())
     local band = zbuff.create(40)
     local band1 = zbuff.create(40)
@@ -53,14 +53,14 @@ sys.taskInit(function()
     for i=0,band1:used()-1 do
         log.info("band", band1[i])
     end
-	-- mobile.vsimInit()
-	-- mobile.flymode(nil,true)
-	-- mobile.vsimOnOff(true)
+	-- mobile.vsimInit()
+	-- mobile.flymode(nil,true)
+	-- mobile.vsimOnOff(true)
 	-- mobile.flymode(nil,false)
     -- mobile.apn(0,2,"") -- 使用默认APN激活CID2
     -- mobile.rtime(3) -- 在无数据交互时,RRC 3秒后自动释放
     -- 下面是配置自动搜索小区间隔,和轮询搜索冲突,开启1个就可以了
-    -- mobile.setAuto(10000,30000, 5) -- SIM暂时脱离后自动恢复,30秒搜索一次周围小区信息
+    -- mobile.setAuto(10000,30000, 5) -- SIM暂时脱离后自动恢复,30秒搜索一次周围小区信息
 	log.info("status", mobile.status())
     sys.wait(2000)
     while 1 do
@@ -69,9 +69,9 @@ sys.taskInit(function()
         local sn = mobile.sn()
         if sn then
             log.info("sn",   sn:toHex())
-        end
+        end
 		log.info("status", mobile.status())
-        
+        
 
         log.info("iccid", mobile.iccid())
         log.info("csq", mobile.csq()) -- 4G模块的CSQ并不能完全代表强度
@@ -81,17 +81,16 @@ sys.taskInit(function()
         log.info("snr", mobile.snr())
         log.info("simid", mobile.simid()) -- 这里是获取当前SIM卡槽
         log.info("apn", mobile.apn(0,1))
-        log.info("ip", socket.localIP())
-		log.info("lua", rtos.meminfo())
-        -- sys内存
+        log.info("ip", socket.localIP())
+		log.info("lua", rtos.meminfo())
+        -- sys内存
         log.info("sys", rtos.meminfo("sys"))
         sys.wait(15000)
     end
 end)
--- 订阅式, 模块本身会周期性查询基站信息,但通常不包含临近小区
-sys.subscribe("SCELL_INFO", function()
-	local mcc,mnc,earfcn,pci = mobile.scell()
-    log.info("scell", mcu.x32(mcc), mcu.x32(mnc), earfcn, pci)
+-- 订阅式, 模块本身会周期性查询基站信息,但通常不包含临近小区
+sys.subscribe("SCELL_INFO", function()
+	log.info("cell", json.encode(mobile.scell()))
 end)
 -- 基站数据的查询
 
@@ -102,12 +101,12 @@ end)
 
 -- 轮询式, 包含临近小区信息,这是手动搜索,和上面的自动搜索冲突,开启一个就行
 sys.taskInit(function()
-    sys.wait(5000)
+    sys.wait(5000)
 	mobile.config(mobile.CONF_SIM_WC_MODE, 2)
     while 1 do
         mobile.reqCellInfo(10)
         sys.wait(11000)
-        log.info("cell", json.encode(mobile.getCellInfo()))
+        log.info("cell", json.encode(mobile.getCellInfo()))
 		mobile.config(mobile.CONF_SIM_WC_MODE, 2)
     end
 end)
@@ -118,9 +117,9 @@ sys.subscribe("SIM_IND", function(status, value)
     log.info("sim status", status)
     if status == 'GET_NUMBER' then
         log.info("number", mobile.number(0))
-    end
-	if status == "SIM_WC" then
-        log.info("sim", "write counter", value)
+    end
+	if status == "SIM_WC" then
+        log.info("sim", "write counter", value)
     end
 end)
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio