From 90c6e86872a2529083c391f68438e9ca229fadc4 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Mon, 3 Oct 2016 19:19:20 +1100 Subject: [PATCH] Fix start-up race between UART & start_lua. (#1522) Input during startup (especially while doing initial filesystem format) ran the risk of filling up the task queue, preventing the start_lua task from being queued, and hence NodeMCU would not start up that time. --- app/driver/uart.c | 1 - app/user/user_main.c | 20 ++++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/driver/uart.c b/app/driver/uart.c index 688dcd2d..56676499 100755 --- a/app/driver/uart.c +++ b/app/driver/uart.c @@ -330,7 +330,6 @@ uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input) uart_config(UART0); UartDev.baut_rate = uart1_br; uart_config(UART1); - ETS_UART_INTR_ENABLE(); #ifdef BIT_RATE_AUTOBAUD uart_init_autobaud(0); #endif diff --git a/app/user/user_main.c b/app/user/user_main.c index 3c0189b4..dd7c9d75 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -29,11 +29,8 @@ #include "rtc/rtctime.h" #endif -#define SIG_LUA 0 -#define SIG_UARTINPUT 1 -#define TASK_QUEUE_LEN 4 +static task_handle_t input_sig; -static os_event_t *taskQueue; /* Note: the trampoline *must* be explicitly put into the .text segment, since * by the time it is invoked the irom has not yet been mapped. This naturally @@ -58,19 +55,17 @@ static void start_lua(task_param_t param, uint8 priority) { char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL }; NODE_DBG("Task task_lua started.\n"); lua_main( 2, lua_argv ); + // Only enable UART interrupts once we've successfully started up, + // otherwise the task queue might fill up with input events and prevent + // the start_lua task from being posted. + ETS_UART_INTR_ENABLE(); } static void handle_input(task_param_t flag, uint8 priority) { -// c_printf("HANDLE_INPUT: %u %u\n", flag, priority); REMOVE + (void)priority; lua_handle_input (flag); } -static task_handle_t input_sig; - -task_handle_t user_get_input_sig(void) { - return input_sig; -} - bool user_process_input(bool force) { return task_post_low(input_sig, force); } @@ -118,7 +113,8 @@ void nodemcu_init(void) #endif // endpoint_setup(); - task_post_low(task_get_id(start_lua),'s'); + if (!task_post_low(task_get_id(start_lua),'s')) + NODE_ERR("Failed to post the start_lua task!\n"); } #ifdef LUA_USE_MODULES_WIFI