diff --git a/boards/known/sim.lua b/boards/known/sim.lua new file mode 100644 index 00000000..8b31bcfe --- /dev/null +++ b/boards/known/sim.lua @@ -0,0 +1,16 @@ +-- eLua simulator running on linux + +return { + cpu = 'linux', + components = { + sercon = { uart = 0, speed = 0 }, + wofs = true, + romfs = true, + shell = true, + term = { lines = 25, cols = 80 }, + }, + modules = { + generic = { 'pd', 'math', 'term', 'elua' } + } +} + diff --git a/config/config.lua b/config/config.lua index f409674b..2101aca8 100644 --- a/config/config.lua +++ b/config/config.lua @@ -134,10 +134,6 @@ local sanity_code = [[ #define VTMR_NUM_TIMERS 0 #endif // #ifndef VTMR_NUM_TIMERS -#ifndef CON_BUF_SIZE -#define CON_BUF_SIZE 0 -#endif // #ifndef CON_BUF_SIZE - #ifndef SERMUX_FLOW_TYPE #define SERMUX_FLOW_TYPE PLATFORM_UART_FLOW_NONE #endif @@ -152,15 +148,15 @@ local sanity_code = [[ #ifdef ELUA_BOOT_RPC #ifndef RPC_UART_ID - #define RPC_UART_ID CON_UART_ID + #define RPC_UART_ID CON_UART_ID #endif #ifndef RPC_TIMER_ID - #define RPC_TIMER_ID PLATFORM_TIMER_SYS_ID + #define RPC_TIMER_ID PLATFORM_TIMER_SYS_ID #endif #ifndef RPC_UART_SPEED - #define RPC_UART_SPEED CON_UART_SPEED + #define RPC_UART_SPEED CON_UART_SPEED #endif #endif // #ifdef ELUA_BOOT_RPC @@ -172,6 +168,10 @@ local sanity_code = [[ #define BUF_ENABLE_ADC #endif +#ifndef CPU_FREQUENCY +#define CPU_FREQUENCY 0 +#endif + ]] ------------------------------------------------------------------------------- diff --git a/run_elua_sim.sh b/run_elua_sim.sh index 0bd80940..1bf08e12 100755 --- a/run_elua_sim.sh +++ b/run_elua_sim.sh @@ -4,7 +4,7 @@ stty -echo raw -igncr # Run simulator -./elua_lua$1_linux.elf +./elua_lua$1_sim.elf # Restore terminal to default settings stty echo cooked diff --git a/src/common.c b/src/common.c index 079d561e..f80c9b58 100644 --- a/src/common.c +++ b/src/common.c @@ -24,6 +24,10 @@ extern const elua_int_descriptor elua_int_table[ INT_ELUA_LAST ]; #endif // #ifdef BUILD_INT_HANDLERS +#ifndef CON_BUF_SIZE +#define CON_BUF_SIZE 0 +#endif // #ifndef CON_BUF_SIZE + // **************************************************************************** // XMODEM support code diff --git a/src/platform/sim/cpu_linux.h b/src/platform/sim/cpu_linux.h new file mode 100644 index 00000000..cfb22173 --- /dev/null +++ b/src/platform/sim/cpu_linux.h @@ -0,0 +1,32 @@ +// Linux "CPU" description for the eLua simulator + +#ifndef __CPU_LINUX_H__ +#define __CPU_LINUX_H__ + +// Number of resources (0 if not available/not implemented) +#define NUM_PIO 0 +#define NUM_SPI 0 +#define NUM_UART 0 +#define NUM_TIMER 0 +#define NUM_PWM 0 +#define NUM_ADC 0 +#define NUM_CAN 0 + +// PIO prefix ('0' for P0, P1, ... or 'A' for PA, PB, ...) +#define PIO_PREFIX 'A' +// Pins per port configuration: +// #define PIO_PINS_PER_PORT (n) if each port has the same number of pins, or +// #define PIO_PIN_ARRAY { n1, n2, ... } to define pins per port in an array +// Use #define PIO_PINS_PER_PORT 0 if this isn't needed +#define PIO_PINS_PER_PORT 0 + +// Allocator data: define your free memory zones here in two arrays +// (start address and end address) +extern void *memory_start_address; +extern void *memory_end_address; +#define MEM_LENGTH (1024 * 1024) +#define INTERNAL_RAM_FIRST_FREE ( void* )memory_start_address +#define INTERNAL_RAM_LAST_FREE ( void* )memory_end_address + +#endif + diff --git a/src/platform/sim/platform_conf.h b/src/platform/sim/platform_conf.h deleted file mode 100644 index 7677a580..00000000 --- a/src/platform/sim/platform_conf.h +++ /dev/null @@ -1,78 +0,0 @@ -// eLua platform configuration - -#ifndef __PLATFORM_CONF_H__ -#define __PLATFORM_CONF_H__ - -#include "auxmods.h" -#include "type.h" -#include "stacks.h" -#include "buf.h" - -// ***************************************************************************** -// Define here what components you want for this platform - -#define BUILD_SHELL -#define BUILD_ROMFS -#define BUILD_CON_GENERIC -#define BUILD_TERM -//#define BUILD_RFS -#define BUILD_WOFS - -#define TERM_LINES 25 -#define TERM_COLS 80 - -#define PLATFORM_HAS_SYSTIMER - -// ***************************************************************************** -// Auxiliary libraries that will be compiled for this platform - -#define LUA_PLATFORM_LIBS_ROM\ - _ROM( AUXLIB_PD, luaopen_pd, pd_map )\ - _ROM( LUA_MATHLIBNAME, luaopen_math, math_map )\ - _ROM( AUXLIB_TERM, luaopen_term, term_map )\ - _ROM( AUXLIB_ELUA, luaopen_elua, elua_map )\ - _ROM( AUXLIB_TMR, luaopen_tmr, tmr_map )\ - -// Bogus defines for common.c -#define CON_UART_ID 0 -#define CON_UART_SPEED 0 - -// ***************************************************************************** -// Configuration data - -// Virtual timers (0 if not used) -#define VTMR_NUM_TIMERS 0 - -// Number of resources (0 if not available/not implemented) -#define NUM_PIO 0 -#define NUM_SPI 0 -#define NUM_UART 0 -#define NUM_TIMER 0 -#define NUM_PWM 0 -#define NUM_ADC 0 -#define NUM_CAN 0 - -// CPU frequency (needed by the CPU module and MMCFS code, 0 if not used) -#define CPU_FREQUENCY 0 - -// PIO prefix ('0' for P0, P1, ... or 'A' for PA, PB, ...) -#define PIO_PREFIX 'A' -// Pins per port configuration: -// #define PIO_PINS_PER_PORT (n) if each port has the same number of pins, or -// #define PIO_PIN_ARRAY { n1, n2, ... } to define pins per port in an array -// Use #define PIO_PINS_PER_PORT 0 if this isn't needed -#define PIO_PINS_PER_PORT 0 - -// Allocator data: define your free memory zones here in two arrays -// (start address and end address) -extern void *memory_start_address; -extern void *memory_end_address; -#define MEM_LENGTH (1024 * 1024) -#define MEM_START_ADDRESS { ( void* )memory_start_address } -#define MEM_END_ADDRESS { ( void* )memory_end_address } - -// RFS configuration -#define RFS_TIMEOUT 0 // dummy, always blocking by implementation -#define RFS_BUFFER_SIZE BUF_SIZE_512 - -#endif // #ifndef __PLATFORM_CONF_H__ diff --git a/src/platform/sim/platform_generic.h b/src/platform/sim/platform_generic.h new file mode 100644 index 00000000..a632f6a0 --- /dev/null +++ b/src/platform/sim/platform_generic.h @@ -0,0 +1,9 @@ +// Included by platform_conf.h for platform customizations + +#ifndef __PLATFORM_GENERIC_H__ +#define __PLATFORM_GENERIC_H__ + +#define PLATFORM_HAS_SYSTIMER + +#endif // #ifndef __PLATFORM_GENERIC_H__ + diff --git a/src/platform/stm32/cpu_stm32f103re.h b/src/platform/stm32/cpu_stm32f103re.h index 5e23a3d1..3bbab727 100644 --- a/src/platform/stm32/cpu_stm32f103re.h +++ b/src/platform/stm32/cpu_stm32f103re.h @@ -1,7 +1,7 @@ // CPU definition file for STM32F103RE -#ifndef __STM32F103RE_H__ -#define __STM32F103RE_H__ +#ifndef __CPU_STM32F103RE_H__ +#define __CPU_STM32F103RE_H__ #include "type.h" #include "stacks.h" @@ -47,5 +47,5 @@ u32 platform_s_cpu_get_frequency(); _C( INT_TMR_MATCH ), \ _C( INT_UART_RX ), -#endif // #ifndef __STM32F103RE_H__ +#endif // #ifndef __CPU_STM32F103RE_H__ diff --git a/src/platform/stm32/cpu_stm32f103ze.h b/src/platform/stm32/cpu_stm32f103ze.h index 17bb2c5b..aab57355 100644 --- a/src/platform/stm32/cpu_stm32f103ze.h +++ b/src/platform/stm32/cpu_stm32f103ze.h @@ -1,8 +1,8 @@ // CPU definition file for STM32F103ZE // Use the STM32F103RE description as a base -#ifndef __STM32F103ZE_H__ -#define __STM32F103ZE_H__ +#ifndef __CPU_STM32F103ZE_H__ +#define __CPU_STM32F103ZE_H__ #include "cpu_stm32f103re.h" @@ -10,5 +10,5 @@ #undef NUM_ADC #define NUM_ADC 21 -#endif // #ifndef __STM32F103ZE_H__ +#endif // #ifndef __CPU_STM32F103ZE_H__