Commit fe6289a6 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Switch Lua input to event driven instead of polled.

The Lua input timer has been the thorn in the side which prevents a lot of
potential sleeping, unnecessarily.
parent 67a71193
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "osapi.h" #include "osapi.h"
#include "driver/uart.h" #include "driver/uart.h"
#include "user_config.h" #include "user_config.h"
#include "user_interface.h"
#define UART0 0 #define UART0 0
#define UART1 1 #define UART1 1
...@@ -21,6 +22,10 @@ ...@@ -21,6 +22,10 @@
#define FUNC_U0RXD 0 #define FUNC_U0RXD 0
#endif #endif
// For event signalling
static uint8 task = USER_TASK_PRIO_MAX;
static os_signal_t sig;
// UartDev is defined and initialized in rom code. // UartDev is defined and initialized in rom code.
extern UartDevice UartDev; extern UartDevice UartDev;
...@@ -187,6 +192,7 @@ uart0_rx_intr_handler(void *para) ...@@ -187,6 +192,7 @@ uart0_rx_intr_handler(void *para)
*/ */
RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
uint8 RcvChar; uint8 RcvChar;
bool got_input = false;
if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) { if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
return; return;
...@@ -220,7 +226,12 @@ uart0_rx_intr_handler(void *para) ...@@ -220,7 +226,12 @@ uart0_rx_intr_handler(void *para)
pRxBuff->pReadPos++; pRxBuff->pReadPos++;
} }
} }
got_input = true;
} }
if (got_input && task != USER_TASK_PRIO_MAX)
system_os_post (task, sig, UART0);
} }
/****************************************************************************** /******************************************************************************
...@@ -228,11 +239,16 @@ uart0_rx_intr_handler(void *para) ...@@ -228,11 +239,16 @@ uart0_rx_intr_handler(void *para)
* Description : user interface for init uart * Description : user interface for init uart
* Parameters : UartBautRate uart0_br - uart0 bautrate * Parameters : UartBautRate uart0_br - uart0 bautrate
* UartBautRate uart1_br - uart1 bautrate * UartBautRate uart1_br - uart1 bautrate
* uint8 task_prio - task priority to signal on input
* os_signal_t sig_input - signal to post
* Returns : NONE * Returns : NONE
*******************************************************************************/ *******************************************************************************/
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br) uart_init(UartBautRate uart0_br, UartBautRate uart1_br, uint8 task_prio, os_signal_t sig_input)
{ {
task = task_prio;
sig = sig_input;
// rom use 74880 baut_rate, here reinitialize // rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br; UartDev.baut_rate = uart0_br;
uart_config(UART0); uart_config(UART0);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "uart_register.h" #include "uart_register.h"
#include "eagle_soc.h" #include "eagle_soc.h"
#include "c_types.h" #include "c_types.h"
#include "os_type.h"
#define RX_BUFF_SIZE 0x100 #define RX_BUFF_SIZE 0x100
#define TX_BUFF_SIZE 100 #define TX_BUFF_SIZE 100
...@@ -100,7 +101,7 @@ typedef struct { ...@@ -100,7 +101,7 @@ typedef struct {
int buff_uart_no; //indicate which uart use tx/rx buffer int buff_uart_no; //indicate which uart use tx/rx buffer
} UartDevice; } UartDevice;
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, uint8 task_prio, os_signal_t sig_input);
void uart0_sendStr(const char *str); void uart0_sendStr(const char *str);
void uart0_putc(const char c); void uart0_putc(const char c);
void uart0_tx_buffer(uint8 *buf, uint16 len); void uart0_tx_buffer(uint8 *buf, uint16 len);
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "os_type.h" #include "os_type.h"
os_timer_t lua_timer; os_timer_t lua_timer;
LOCAL os_timer_t readline_timer;
lua_State *globalL = NULL; lua_State *globalL = NULL;
...@@ -477,15 +476,15 @@ int lua_main (int argc, char **argv) { ...@@ -477,15 +476,15 @@ int lua_main (int argc, char **argv) {
return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
} }
void lua_handle_input (void)
{
readline (&gLoad);
}
void donejob(lua_Load *load){ void donejob(lua_Load *load){
lua_close(load->L); lua_close(load->L);
} }
#if 0
int log_fd = -1;
int noparse = 0;
#endif
void dojob(lua_Load *load){ void dojob(lua_Load *load){
size_t l, rs; size_t l, rs;
int status; int status;
...@@ -542,9 +541,6 @@ void dojob(lua_Load *load){ ...@@ -542,9 +541,6 @@ void dojob(lua_Load *load){
load->done = 0; load->done = 0;
load->line_position = 0; load->line_position = 0;
c_memset(load->line, 0, load->len); c_memset(load->line, 0, load->len);
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
c_puts(load->prmt); c_puts(load->prmt);
// NODE_DBG("dojob() is called with firstline.\n"); // NODE_DBG("dojob() is called with firstline.\n");
} }
...@@ -648,9 +644,6 @@ void readline(lua_Load *load){ ...@@ -648,9 +644,6 @@ void readline(lua_Load *load){
{ {
/* Get a empty line, then go to get a new line */ /* Get a empty line, then go to get a new line */
c_puts(load->prmt); c_puts(load->prmt);
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
} else { } else {
load->done = 1; load->done = 1;
os_timer_disarm(&lua_timer); os_timer_disarm(&lua_timer);
...@@ -697,8 +690,4 @@ void readline(lua_Load *load){ ...@@ -697,8 +690,4 @@ void readline(lua_Load *load){
uart_on_data_cb(load->line, load->line_position); uart_on_data_cb(load->line, load->line_position);
load->line_position = 0; load->line_position = 0;
} }
// if there is no input from user, repeat readline()
os_timer_disarm(&readline_timer);
os_timer_setfn(&readline_timer, (os_timer_func_t *)readline, load);
os_timer_arm(&readline_timer, READLINE_INTERVAL, 0); // no repeat
} }
...@@ -382,6 +382,8 @@ typedef struct __lua_load{ ...@@ -382,6 +382,8 @@ typedef struct __lua_load{
int lua_main( int argc, char **argv ); int lua_main( int argc, char **argv );
void lua_handle_input (void);
/****************************************************************************** /******************************************************************************
* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
* *
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#endif #endif
#define SIG_LUA 0 #define SIG_LUA 0
#define SIG_UARTINPUT 1
#define TASK_QUEUE_LEN 4 #define TASK_QUEUE_LEN 4
os_event_t *taskQueue; os_event_t *taskQueue;
...@@ -58,6 +59,9 @@ void task_lua(os_event_t *e){ ...@@ -58,6 +59,9 @@ void task_lua(os_event_t *e){
NODE_DBG("SIG_LUA received.\n"); NODE_DBG("SIG_LUA received.\n");
lua_main( 2, lua_argv ); lua_main( 2, lua_argv );
break; break;
case SIG_UARTINPUT:
lua_handle_input ();
break;
default: default:
break; break;
} }
...@@ -158,12 +162,13 @@ void user_init(void) ...@@ -158,12 +162,13 @@ void user_init(void)
// os_printf("Heap size::%d.\n",system_get_free_heap_size()); // os_printf("Heap size::%d.\n",system_get_free_heap_size());
// os_delay_us(50*1000); // delay 50ms before init uart // os_delay_us(50*1000); // delay 50ms before init uart
UartBautRate br =
#ifdef DEVELOP_VERSION #ifdef DEVELOP_VERSION
uart_init(BIT_RATE_74880, BIT_RATE_74880); BIT_RATE_74880;
#else #else
uart_init(BIT_RATE_9600, BIT_RATE_9600); BIT_RATE_9600;
#endif #endif
// uart_init(BIT_RATE_115200, BIT_RATE_115200); uart_init (br, br, USER_TASK_PRIO_0, SIG_UARTINPUT);
#ifndef NODE_DEBUG #ifndef NODE_DEBUG
system_set_os_print(0); system_set_os_print(0);
......
...@@ -78,6 +78,33 @@ SECTIONS ...@@ -78,6 +78,33 @@ SECTIONS
*(.literal.* .text.*) *(.literal.* .text.*)
*(.rodata*) *(.rodata*)
*(.sdk.version) *(.sdk.version)
/* These are *only* pulled in by Lua, and therefore safe to put in flash */
*/libc.a:lib_a-isalnum.o(.text* .literal*)
*/libc.a:lib_a-isalpha.o(.text* .literal*)
*/libc.a:lib_a-iscntrl.o(.text* .literal*)
*/libc.a:lib_a-isspace.o(.text* .literal*)
*/libc.a:lib_a-islower.o(.text* .literal*)
*/libc.a:lib_a-isupper.o(.text* .literal*)
*/libc.a:lib_a-ispunct.o(.text* .literal*)
*/libc.a:lib_a-isxdigit.o(.text* .literal*)
*/libc.a:lib_a-locale.o(.text* .literal*)
*/libc.a:lib_a-tolower.o(.text* .literal*)
*/libc.a:lib_a-toupper.o(.text* .literal*)
*/libc.a:lib_a-strcasecmp.o(.text* .literal*)
*/libc.a:lib_a-strcoll.o(.text* .literal*)
*/libc.a:lib_a-strchr.o(.text* .literal*)
*/libc.a:lib_a-strrchr.o(.text* .literal*)
*/libc.a:lib_a-strcat.o(.text* .literal*)
*/libc.a:lib_a-strncat.o(.text* .literal*)
*/libc.a:lib_a-strcspn.o(.text* .literal*)
*/libc.a:lib_a-strtol.o(.text* .literal*)
*/libc.a:lib_a-strtoul.o(.text* .literal*)
*/libc.a:lib_a-strpbrk.o(.text* .literal*)
*/libc.a:lib_a-memchr.o(.text* .literal*)
*/libc.a:lib_a-setjmp.o(.text* .literal*)
/* end Lua C lib functions */
_irom0_text_end = ABSOLUTE(.); _irom0_text_end = ABSOLUTE(.);
_flash_used_end = ABSOLUTE(.); _flash_used_end = ABSOLUTE(.);
} >irom0_0_seg :irom0_0_phdr } >irom0_0_seg :irom0_0_phdr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment