소스 검색

fix:非阻塞接口的返回值反了

alienwalker 3 년 전
부모
커밋
815edc93aa
3개의 변경된 파일25개의 추가작업 그리고 25개의 파일을 삭제
  1. 3 3
      demo/spi/Air105/no_block_test.lua
  2. 1 1
      luat/modules/luat_irq.c
  3. 21 21
      luat/modules/luat_lib_i2c.c

+ 3 - 3
demo/spi/Air105/no_block_test.lua

@@ -3,7 +3,7 @@ local function spiTest(id)
     local txbuff = zbuff.create(txlen)
     local rxbuff = zbuff.create(txlen)
     local cbTopic = "SPI" .. id .. "DONE"
-    local result, succ, errorCode
+    local result, devid, succ, errorCode
     if id ~= spi.HSPI_0 then
         spi.setup(id, nil, 0, 0, 8, 24000000)
     else
@@ -14,7 +14,7 @@ local function spiTest(id)
         log.info("spi"..id, "传输开始")
         result = spi.xfer(id,txbuff,rxbuff,txlen,cbTopic)
         if result then
-            result, succ, errorCode = sys.waitUntil(cbTopic, 1000)
+            result, devid, succ, errorCode = sys.waitUntil(cbTopic, 1000)
         end
         if not result or not succ then
             log.info("spi"..id, "传输失败")
@@ -32,4 +32,4 @@ end
 
 sys.taskInit(spiTest, spi.SPI_1)
 sys.taskInit(spiTest, spi.SPI_2)
-sys.taskInit(spiTest, spi.HSPI_0)
+sys.taskInit(spiTest, spi.HSPI_0)

+ 1 - 1
luat/modules/luat_irq.c

@@ -49,7 +49,7 @@ int32_t luat_irq_hardware_cb_handler(void *pdata, void *param)
     msg.handler = luat_irq_topic_cb_handler;
     msg.ptr = param;
     msg.arg1 = (uint32_t)pdata & 0x0000ffff;
-    msg.arg2 = !((uint32_t)pdata >> 16);
+    msg.arg2 = ((uint32_t)pdata >> 16);
     luat_msgbus_put(&msg, 0);
     return 0;
 }

+ 21 - 21
luat/modules/luat_lib_i2c.c

@@ -789,43 +789,43 @@ static int l_i2c_no_block_transfer(lua_State *L)
 {
 	size_t topic_len = 0;
 	const char *topic = luaL_checklstring(L, 6, &topic_len);
-
-	uint32_t timeout = luaL_optinteger(L, 7, 100);
+	int id = luaL_checkinteger(L, 1);
 	int addr = luaL_checkinteger(L, 2);
+
+
 	size_t tx_len = 0;
 	size_t rx_len = 0;
 	int result = -1;
 	uint8_t *tx_buff = NULL;
 	uint8_t *rx_buff = NULL;
-	if (lua_isnil(L, 3)) {
-		tx_len = 0;
-	}
-	else {
-		luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 3, LUAT_ZBUFF_TYPE));
+
+	luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_testudata(L, 3, LUAT_ZBUFF_TYPE));
+	if (buff) {
 		tx_buff = buff->addr;
 		tx_len = buff->used;
 	}
+
 	luat_zbuff_t *rbuff = ((luat_zbuff_t *)luaL_testudata(L, 4, LUAT_ZBUFF_TYPE));
 	if (lua_isinteger(L, 5) && rbuff) {
 		rx_len = luaL_checkinteger(L, 5);
 		rx_buff = rbuff->addr;
+		rbuff->used = rx_len;
 	}
 
-	int id = 0;
-	if (!lua_isuserdata(L, 1)) {
-		id = luaL_checkinteger(L, 1);
-		char *cb_topic = luat_heap_malloc(topic_len + 1);
-		memcpy(cb_topic, topic, topic_len);
-		cb_topic[topic_len] = 0;
-		if (rx_buff && rx_len) {
-			result = luat_i2c_no_block_transfer(id, addr, 1, tx_buff, tx_len, rx_buff, rx_len, timeout, luat_irq_hardware_cb_handler, cb_topic);
-		} else {
-			result = luat_i2c_no_block_transfer(id, addr, 0, NULL, 0, tx_buff, tx_len, timeout, luat_irq_hardware_cb_handler, cb_topic);
-		}
-		if (result) {
-			luat_heap_free(cb_topic);
-		}
+	uint32_t timeout = luaL_optinteger(L, 7, 100);
+
+	char *cb_topic = luat_heap_malloc(topic_len + 1);
+	memcpy(cb_topic, topic, topic_len);
+	cb_topic[topic_len] = 0;
+	if (rx_buff && rx_len) {
+		result = luat_i2c_no_block_transfer(id, addr, 1, tx_buff, tx_len, rx_buff, rx_len, timeout, luat_irq_hardware_cb_handler, cb_topic);
+	} else {
+		result = luat_i2c_no_block_transfer(id, addr, 0, NULL, 0, tx_buff, tx_len, timeout, luat_irq_hardware_cb_handler, cb_topic);
+	}
+	if (result) {
+		luat_heap_free(cb_topic);
 	}
+
 	lua_pushboolean(L, !result);
 	return 1;