Skip to content

Commit

Permalink
Squashed updates do get Lua51 and Lua53 working (#3075)
Browse files Browse the repository at this point in the history
-  Lots of minor but nasty bugfixes to get all tests to run clean
-  core lua and test suite fixes to allow luac -F to run cleanly against test suite
-  next tranch to get LFS working
-  luac.cross -a options plus fixes from feedback
-  UART fixes and lua.c merge
-  commit of wip prior to rebaselining against current dev
-  more tweaks
  • Loading branch information
TerryE authored and marcelstoer committed Jun 9, 2020
1 parent 99aba34 commit bbeb09b
Show file tree
Hide file tree
Showing 248 changed files with 41,882 additions and 2,257 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ifneq (,$(findstring indows,$(OS)))
else
# It is gcc, may be cygwin
# Can we use -fdata-sections?
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections -fpack-struct=4
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
CXX = xtensa-lx106-elf-g++
Expand Down
17 changes: 12 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ TARGET = eagle
#FLAVOR = release
FLAVOR = debug

# Handle Lua Directory selector
ifeq ("$(LUA)","53")
LUA_DIR := lua53
else
LUA_DIR := lua
endif

ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
Expand All @@ -34,15 +41,15 @@ SUBDIRS= \
mbedtls \
platform \
libc \
lua \
$(LUA_DIR) \
lwip \
smart \
modules \
spiffs \
net \
net \
fatfs \
esp-gdbstub \
pm \
pm \
uzlib \
$(OPT_SEL_MKTARGETS)

Expand All @@ -65,7 +72,7 @@ COMPONENTS_eagle.app.v6 = \
driver/libdriver.a \
platform/libplatform.a \
libc/liblibc.a \
lua/liblua.a \
$(LUA_DIR)/liblua.a \
lwip/liblwip.a \
smart/smart.a \
spiffs/spiffs.a \
Expand Down Expand Up @@ -150,7 +157,7 @@ DDEFINES += \
#
# Required for each makefile to inherit from the parent
#
INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \
INCLUDES := -I $(PDIR)libc -I $(PDIR)$(LUA_DIR) -I $(PDIR)platform \
$(INCLUDES) -I $(PDIR) -I $(PDIR)include
PDIR := ../$(PDIR)

Expand Down
15 changes: 13 additions & 2 deletions app/coap/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,20 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{
char line[LUA_MAXINPUT+1];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload)) {
lua_State *L = lua_getstate();
int base = lua_gettop(L), n, status;
int l = strlen(line);
line[l] = '\n';
lua_input_string(line, l+1);
line[l++] = '\n';
/* compile and exec payload; any error or results will be left on the stack and printed */
/* TODO: consider returning output as result instead of printing */
luaL_dostring(L, line);
if ((n = lua_gettop(L) - base) > 0)
{
lua_getglobal(L, "print");
lua_insert(L, base);
lua_pcall(L, n, 0, 0);
lua_settop(L, base);
}
}
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
Expand Down
2 changes: 1 addition & 1 deletion app/driver/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ i2c_master_setDC(uint16 id, uint8 SDA, uint8 SCL)
while(!(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1)) {}; //read SCL value until SCL goes high
}else{
// dummy read operation and empty CPU cycles to maintain equal times for low and high state
READ_PERI_REG(RTC_GPIO_IN_DATA) & 1; asm volatile("nop;nop;nop;nop;");
(void) (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); asm volatile("nop;nop;nop;nop;");
}
}
else{
Expand Down
20 changes: 9 additions & 11 deletions app/driver/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <stdint.h>
#include "mem.h"

/**DEBUG**/extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));

static void input_handler(platform_task_param_t flag, uint8 priority);

static struct input_state {
Expand Down Expand Up @@ -63,7 +61,7 @@ static bool uart_getc(char *c){
** The ins.data check detects up the first task call which used to initialise
** everything.
*/
int lua_main (void);
extern int lua_main (void);
static bool input_readline(void);

static void input_handler(platform_task_param_t flag, uint8 priority) {
Expand All @@ -79,7 +77,7 @@ static void input_handler(platform_task_param_t flag, uint8 priority) {
/*
** The input state (ins) is private, so input_setup() exposes the necessary
** access to public properties and is called in user_init() before the Lua
** enviroment is initialised. The second routine input_setup_receive() is
** enviroment is initialised. The second routine input_setup_receive() is
** called in lua.c after the Lua environment is available to bind the Lua
** input handler. Any UART input before this receive setup is ignored.
*/
Expand Down Expand Up @@ -112,15 +110,15 @@ void input_setprompt (const char *prompt) {
}

/*
** input_readline() is called from the input_handler() event routine which is
** input_readline() is called from the input_handler() event routine which is
** posted by the UART Rx ISR posts. This works in one of two modes depending on
** the bool ins.run_input.
** - TRUE: it clears the UART FIFO up to EOL, doing any callback and sending
** the line to Lua.
** - FALSE: it clears the UART FIFO doing callbacks according to the data_len /
** end_char break.
** - FALSE: it clears the UART FIFO doing callbacks according to the data_len
** or end_char break.
*/
void lua_input_string (const char *line, int len);
extern void lua_input_string (const char *line, int len);

static bool input_readline(void) {
char ch = NUL;
Expand Down Expand Up @@ -182,9 +180,9 @@ static bool input_readline(void) {
} else {
while (uart_getc(&ch)) {
ins.data[ins.line_pos++] = ch;
if( ins.line_pos >= ins.len ||
(ins.data_len > 0 && ins.line_pos >= ins.data_len) ||
ch == ins.end_char ) {
if( ins.line_pos >= ins.len ||
(ins.data_len >= 0 && ins.line_pos >= ins.data_len) ||
(ins.data_len < 0 && ch == ins.end_char )) {
ins.uart_cb(ins.data, ins.line_pos);
ins.line_pos = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions app/driver/pwm2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Software PWM using soft-interrupt timer1.
* Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one.
*
* Nikolay Fiykov
Expand Down Expand Up @@ -204,7 +204,7 @@ void pwm2_setup_pin(
const uint32_t freqDivisor,
const uint32_t resolution,
const uint32_t initDuty
)
)
{
moduleData->setupData.pin[pin].pulseResolutions = resolution;
moduleData->setupData.pin[pin].divisableFrequency = divisableFreq;
Expand Down
20 changes: 14 additions & 6 deletions app/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,24 @@ uart0_tx_buffer(uint8 *buf, uint16 len)
* FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer
* uint16 len - buffer len
* Returns :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str)
{
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str) {
while(*str)
{
// uart_tx_one_char(UART0, *str++);
uart0_putc(*str++);
}
}

/******************************************************************************
* FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer
* size_t len - buffer len
* Returns :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStrn(const char *str, size_t len) {
size_t i;
for(i = 0; i < len; i++)
uart0_putc(*str++);
}

/******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion app/include/driver/pwm2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Software PWM using soft-interrupt timer1.
* Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one.
*
* Nikolay Fiykov
Expand Down
1 change: 1 addition & 0 deletions app/include/driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void uart_init_task(os_signal_t sig_input, uint8 *flag_input);
UartConfig uart_get_config(uint8 uart_no);
void uart0_alt(uint8 on);
void uart0_sendStr(const char *str);
void uart0_sendStrn(const char *str, size_t len);
void uart0_putc(const char c);
void uart0_tx_buffer(uint8 *buf, uint16 len);
void uart_setup(uint8 uart_no);
Expand Down
25 changes: 4 additions & 21 deletions app/include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __MODULE_H__

#include "user_modules.h"
#include "lrotable.h"
#include "lnodemcu.h"

/* Registering a module within NodeMCU is really easy these days!
*
Expand Down Expand Up @@ -38,23 +38,6 @@
#define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)

#ifdef LUA_CROSS_COMPILER
#ifdef _MSC_VER
//on msvc it is necessary to go through more pre-processor hoops to get the
//section name built; string merging does not happen in the _declspecs.
//NOTE: linker magic is invoked via the magical '$' character. Caveat editor.
#define __TOKIFY(s) .rodata1$##s
#define __TOTOK(s) __TOKIFY(s)
#define __STRINGIFY(x) #x
#define __TOSTRING(x) __STRINGIFY(x)
#define __ROSECNAME(s) __TOSTRING(__TOTOK(s))
#define LOCK_IN_SECTION(s) __declspec ( allocate( __ROSECNAME(s) ) )
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".rodata1." #s)))
#endif
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s)))
#endif
/* For the ROM table, we name the variable according to ( | denotes concat):
* cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
Expand All @@ -67,8 +50,8 @@
*/
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(libs) \
luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
ROTable_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
const LOCK_IN_SECTION(rotable) \
luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {luaname, LRO_ROVAL(map ## _map)}
ROTable_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {luaname, LRO_ROVAL(map)}
#endif
10 changes: 5 additions & 5 deletions app/include/task/task.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef _TASK_H_
#define _TASK_H_
/*
** The task interface is now part of the core platform interface.
** The task interface is now part of the core platform interface.
** This header is preserved for backwards compatability only.
*/
*/
#include "platform.h"

#define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW
#define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM
#define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH
#define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW
#define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM
#define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH

#define task_post(priority,handle,param) platform_post(priority,handle,param)
#define task_post_low(handle,param) platform_post_low(handle,param)
Expand Down
12 changes: 6 additions & 6 deletions app/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@
#define READLINE_INTERVAL 80
#define STRBUF_DEFAULT_INCREMENT 3
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()

#ifdef DEVELOPMENT_TOOLS
#if defined(LUA_CROSS_COMPILER) || !defined(DEVELOPMENT_USE_GDB)

#if defined(DEVELOPMENT_TOOLS) && defined(DEVELOPMENT_USE_GDB)
extern void LUA_DEBUG_HOOK (void);
#define lua_assert(x) ((x) ? (void) 0 : LUA_DEBUG_HOOK ())
#elif defined(DEVELOPMENT_TOOLS) && defined(LUA_CROSS_COMPILER)
extern void luaL_assertfail(const char *file, int line, const char *message);
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
#else
extern void luaL_dbgbreak(void);
#define lua_assert(x) ((x) ? (void) 0 : luaL_dbgbreak())
#endif
#define lua_assert(x) ((void) (x))
#endif

#if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES)
Expand Down
4 changes: 0 additions & 4 deletions app/libc/stdio.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <stdio.h>

int c_stdin = 999;
int c_stdout = 1000;
int c_stderr = 1001;

#if defined( LUA_NUMBER_INTEGRAL )

#include <stdarg.h>
Expand Down
Loading

0 comments on commit bbeb09b

Please sign in to comment.