From ce2e50c651cf13a034af08343c3451c77124d06d Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Sat, 20 Jul 2019 00:45:08 +0100 Subject: [PATCH] Updates following JM review --- app/driver/uart.c | 26 +------------------------ app/include/driver/input.h | 1 - app/lua/lflash.c | 5 +++-- app/lua/lnodemcu.c | 12 ++++-------- app/modules/node.c | 2 +- app/modules/uart.c | 2 +- lua_examples/telnet/telnet_fifosock.lua | 7 ++++--- lua_examples/telnet/telnet_pipe.lua | 13 +++++++------ 8 files changed, 21 insertions(+), 47 deletions(-) diff --git a/app/driver/uart.c b/app/driver/uart.c index 5b50d194..ff93f028 100644 --- a/app/driver/uart.c +++ b/app/driver/uart.c @@ -165,31 +165,7 @@ uart_tx_one_char(uint8 uart, uint8 TxChar) WRITE_PERI_REG(UART_FIFO(uart) , TxChar); return OK; } -#if 0 -/****************************************************************************** - * FunctionName : uart1_write_char - * Description : Internal used function - * Do some special deal while tx char is '\r' or '\n' - * Parameters : char c - character to tx - * Returns : NONE -*******************************************************************************/ -LOCAL void ICACHE_FLASH_ATTR -uart1_write_char(char c) -{ - if (c == '\n') - { - uart_tx_one_char(UART1, '\r'); - uart_tx_one_char(UART1, '\n'); - } - else if (c == '\r') - { - } - else - { - uart_tx_one_char(UART1, c); - } -} -#endif + /****************************************************************************** * FunctionName : uart0_tx_buffer * Description : use uart0 to transfer buffer diff --git a/app/include/driver/input.h b/app/include/driver/input.h index f18f48b6..6b445910 100644 --- a/app/include/driver/input.h +++ b/app/include/driver/input.h @@ -6,6 +6,5 @@ extern void input_setup(int bufsize, const char *prompt); extern void input_setup_receive(uart_cb_t uart_on_data_cb, int data_len, char end_char, bool run_input); extern void input_setecho (bool flag); extern void input_setprompt (const char *prompt); -extern void input_process_arm(void); #endif /* READLINE_APP_H */ diff --git a/app/lua/lflash.c b/app/lua/lflash.c index d2bf5cc2..340c1066 100644 --- a/app/lua/lflash.c +++ b/app/lua/lflash.c @@ -121,7 +121,7 @@ static char *flashSetPosition(uint32_t offset){ static char *flashBlock(const void* b, size_t size) { void *cur = flashPosition(); - NODE_DBG("flashBlock((%04x),%08x,%04x)\n", curOffset,b,size); + NODE_DBG("flashBlock((%04x),%p,%04x)\n", curOffset,b,size); lua_assert(ALIGN_BITS(b) == 0 && ALIGN_BITS(size) == 0); platform_flash_write(b, flashAddrPhys+curOffset, size); curOffset += size; @@ -451,7 +451,8 @@ void procSecondPass (void) { int i, len = (out->ndx > out->flashLen) ? (out->flashLen % WRITE_BLOCKSIZE) / WORDSIZE : WRITE_BLOCKSIZE / WORDSIZE; - uint32_t *buf = (uint32_t *) out->buffer.byte, flags = 0; + uint32_t *buf = (uint32_t *) out->buffer.byte; + uint32_t flags = 0; /* * Relocate all the addresses tagged in out->flags. This can't be done in * place because the out->blocks are still in use as dictionary content so diff --git a/app/lua/lnodemcu.c b/app/lua/lnodemcu.c index 6d8cf1a2..520ea02d 100644 --- a/app/lua/lnodemcu.c +++ b/app/lua/lnodemcu.c @@ -22,12 +22,6 @@ #include "platform.h" extern int debug_errorfb (lua_State *L); -#if 0 -extern int pipe_create(lua_State *L); -extern int pipe_read(lua_State *L); -extern int pipe_unread(lua_State *L); -extern int pipe_write(lua_State *L); -#endif /* ** Error Reporting Task. We can't pass a string parameter to the error reporter ** directly through the task interface the call is wrapped in a C closure with @@ -62,13 +56,15 @@ int luaN_traceback (lua_State *L) { ** an error handler which will catch any error and then post this to the ** registered reporter function as a separate follow-on task. */ -int luaN_call (lua_State *L, int narg, int res, int doGC) { // [-narg, +0, v] +int luaN_call (lua_State *L, int narg, int nres, int doGC) { // [-narg, +0, v] int status; int base = lua_gettop(L) - narg; lua_pushcfunction(L, luaN_traceback); lua_insert(L, base); /* put under args */ - status = lua_pcall(L, narg, (res < 0 ? LUA_MULTRET : res), base); + status = lua_pcall(L, narg, (nres < 0 ? LUA_MULTRET : nres), base); lua_remove(L, base); /* remove traceback function */ + if (status && nres >=0) + lua_settop(L, base + nres); /* balance the stack on error */ /* force a complete garbage collection if requested */ if (doGC) lua_gc(L, LUA_GCCOLLECT, 0); diff --git a/app/modules/node.c b/app/modules/node.c index c4f3151d..6714a6b8 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -271,7 +271,7 @@ static int node_output( lua_State* L ) lua_pushlightfunction(L, &pipe_create); lua_insert(L, 1); lua_pushinteger(L, LUA_TASK_MEDIUM); - lua_call(L, 2, 1); /* T[1] = pipe.create(dojob, low_priority) */ + lua_call(L, 2, 1); /* T[1] = pipe.create(CB, medium_priority) */ } else { // remove the stdout pipe lua_pop(L,1); lua_pushnil(L); /* T[1] = nil */ diff --git a/app/modules/uart.c b/app/modules/uart.c index a849095d..e67b1ea7 100644 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -31,7 +31,7 @@ static int l_uart_on( lua_State* L ) if (lua_type( L, stack ) == LUA_TNUMBER) { data_len = luaL_checkinteger( L, stack ); - luaL_argcheck(L, data_len >= 0 && data_len <= LUA_MAXINPUT, stack, "wrong arg range"); + luaL_argcheck(L, data_len >= 0 && data_len < LUA_MAXINPUT, stack, "wrong arg range"); stack++; } else if (lua_isstring(L, stack)) diff --git a/lua_examples/telnet/telnet_fifosock.lua b/lua_examples/telnet/telnet_fifosock.lua index 328d5cbc..318fe5da 100644 --- a/lua_examples/telnet/telnet_fifosock.lua +++ b/lua_examples/telnet/telnet_fifosock.lua @@ -27,10 +27,11 @@ concatenated into a 2nd level FIFO entry of upto 256 bytes, and the 1st level FI cleared down to any residue. ]] -local node, table, tmr, wifi, uwrite, tostring = - node, table, tmr, wifi, uart.write, tostring +--luacheck: no unused args -local function telnet_listener(socket) +local node, tmr, wifi, uwrite = node, tmr, wifi, uart.write + +local function telnet_listener(socket) local queueLine = (require "fifosock").wrap(socket) local function receiveLine(s, line) diff --git a/lua_examples/telnet/telnet_pipe.lua b/lua_examples/telnet/telnet_pipe.lua index 935f5837..e33be277 100644 --- a/lua_examples/telnet/telnet_pipe.lua +++ b/lua_examples/telnet/telnet_pipe.lua @@ -1,16 +1,17 @@ --[[ A telnet server T. Ellison, June 2019 -This version of the telnet server demonstrates the use of the new stdin and stout -pipes, which is a C implementation of the Lua fifosock concept moved into the +This version of the telnet server demonstrates the use of the new stdin and stout +pipes, which is a C implementation of the Lua fifosock concept moved into the Lua core. These two pipes are referenced in the Lua registry. ]] +--luacheck: no unused args local M = {} local modname = ... -local function telnet_session(socket) +local function telnet_session(socket) local node = node - local stdout, sending + local stdout local function output_CB(opipe) -- upval: socket stdout = opipe @@ -31,8 +32,8 @@ local function telnet_session(socket) node.output(output_CB, 0) socket:on("receive", function(_,rec) node.input(rec) end) - socket:on("sent", onsent_CB) - socket:on("disconnection", disconnect_CB) + socket:on("sent", onsent_CB) + socket:on("disconnection", disconnect_CB) print(("Welcome to NodeMCU world (%d mem free, %s)"):format( node.heap(), wifi.sta.getip())) end