1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

LPC288x platform conversion + other changes

- LPC288x platform converted to the new build system
- changed generation for the 'extmem' attribute
- added combined attributes (validated against two or more possible types)
This commit is contained in:
Bogdan Marinescu 2012-07-14 16:46:31 +03:00
parent 5cf6f2b8f3
commit 449716c477
6 changed files with 88 additions and 106 deletions

View File

@ -0,0 +1,20 @@
-- LPC-H2888 build configuration
return {
cpu = 'lpc2888',
components = {
sercon = { uart = 0, speed = 115200, timer = 0 },
romfs = true,
shell = true,
term = { lines = 25, cols = 80 },
xmodem = true,
rpc = { uart = 0, speed = 115200 }
},
config = {
extmem = { start = { "SDRAM_BASE_ADDR" }, size = { "SDRAM_SIZE" } }
},
modules = {
generic = { 'pio', 'tmr', 'pd', 'uart', 'term', 'pack', 'bit', 'elua', 'cpu', 'rpc', 'math' }
}
}

View File

@ -58,7 +58,6 @@ end
-- Return the string if OK, (false, errmsg) for error
-- Needs: attrmaxsize - maximum size of the string
local function _validate_string( adesc, aname, aval, elname, sectname )
aval = tostring( aval )
if type( aval ) ~= "string" then
return false, sf( "value of attribute '%s' for element '%s' in section '%s' must be a string", aname, elname, sectname )
end
@ -113,6 +112,16 @@ local validate_log2 = build_validator( _validate_log2 )
local validate_string = build_validator( _validate_string )
local validate_ip = build_validator( _validate_ip )
-- Composite validator: run each validator in turn
local function composite_validator( adesc, aname, aval, elname, sectname )
for _, onedesc in pairs( adesc.attrs ) do
onedesc.is_array = adesc.is_array
local res, err = onedesc.validator( onedesc, aname, aval, elname, sectname )
if res then return res end
end
return false, sf( "Invalid value '%s' for attribute '%s' of element '%s' in section '%s'", tostring( aval ), aname, elname, sectname )
end
-------------------------------------------------------------------------------
-- Public interface
@ -167,6 +176,11 @@ function ip_attr( macro, default )
return { macro = macro, default = default, validator = validate_ip, is_ip = true }
end
-- Returns a new combined attribute
function combine_attr( macro, attrs )
return { macro = macro, validator = composite_validator, attrs = attrs }
end
-- Make the given attribute optional
function make_optional( attr )
attr.optional = true

View File

@ -72,18 +72,14 @@ local function mem_generator( desc, vals, generated )
generated.MEM_END_ADDRESS = true
return gstr
end
local function fmtval( s ) return tonumber( s ) and tostring( s ) .. "UL" or ( "( u32 )( " .. s .. " )" ) end
local startvals = vals.MEM_START_ADDRESS.value
local sizevals = vals.MEM_END_ADDRESS.value
table.insert( startvals, 1, "INTERNAL_RAM_FIRST_FREE" )
table.insert( sizevals, 1, "INTERNAL_RAM_LAST_FREE" )
-- Transform the data in 'sizevals' to 'last address' (the format accepted by eLua)
table.insert( startvals, 1, "( u32 )( INTERNAL_RAM_FIRST_FREE )" )
table.insert( sizevals, 1, "( u32 )( INTERNAL_RAM_LAST_FREE )" )
for i = 2, #sizevals do
sizevals[ i ] = tonumber( startvals[ i ] ) + tonumber( sizevals[ i ] ) - 1
end
-- Prefix all the values in the 'start' and 'size' arrays with 'u32'
for i = 1, #sizevals do
startvals[ i ] = "( u32 )( " .. tostring( startvals[ i ] ) .. ( i > 1 and "u" or "" ) .. " )"
sizevals[ i ] = "( u32 )( " .. tostring( sizevals[ i ] ) .. ( i > 1 and "u" or "" ) .. " )"
sizevals[ i ] = sf( "( %s + %s - 1 )", fmtval( startvals[ i ] ), fmtval( sizevals[ i ] ) )
startvals[ i ] = sf( "( %s )", fmtval( startvals[ i ] ) )
end
local gstr = gen.simple_gen( "MEM_START_ADDRESS", vals, generated )
gstr = gstr .. gen.simple_gen( "MEM_END_ADDRESS", vals, generated )
@ -148,8 +144,8 @@ function init()
gen = mem_generator,
confcheck = mem_checker,
attrs = {
start = at.array_of( at.int_attr( 'MEM_START_ADDRESS' ) ),
size = at.array_of( at.int_attr( 'MEM_END_ADDRESS', 1 ) )
start = at.array_of( at.combine_attr( 'MEM_START_ADDRESS', { at.int_attr( '' ), at.string_attr( '' ) } ) ),
size = at.array_of( at.combine_attr( 'MEM_END_ADDRESS', { at.int_attr( '', 1 ), at.string_attr( '' ) } ) ),
},
required = {}
}

View File

@ -0,0 +1,37 @@
// LPC2888 CPU definition
#ifndef __CPU_LPC2888_H__
#define __CPU_LPC2888_H__
#include "stacks.h"
#include "target.h"
// Number of resources (0 if not available/not implemented)
#define NUM_PIO 8
#define NUM_SPI 0
#define NUM_UART 1
#define NUM_TIMER 2
#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 Fcclk
// PIO prefix ('0' for P0, P1, ... or 'A' for PA, PB, ...)
#define PIO_PREFIX '0'
// 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_PIN_ARRAY { 32, 20, 4, 6, 12, 6, 4, 1 }
// Allocator data: define your free memory zones here in two arrays
// (start address and end address)
#define SRAM_ORIGIN 0x00400000
#define SRAM_SIZE 0x10000
#define INTERNAL_RAM_FIRST_FREE end
#define INTERNAL_RAM_LAST_FREE ( SRAM_ORIGIN + SRAM_SIZE - STACK_SIZE_TOTAL - 1 )
#endif // #ifndef __CPU_LPC2888_H__

View File

@ -1,94 +0,0 @@
// eLua platform configuration
#ifndef __PLATFORM_CONF_H__
#define __PLATFORM_CONF_H__
#include "auxmods.h"
#include "stacks.h"
#include "target.h"
// *****************************************************************************
// Define here what components you want for this platform
#define BUILD_XMODEM
#define BUILD_SHELL
#define BUILD_ROMFS
#define BUILD_TERM
#define BUILD_CON_GENERIC
//#define BUILD_RPC
// *****************************************************************************
// UART/Timer IDs configuration data (used in main.c)
#define CON_UART_ID 0
#define CON_UART_SPEED 115200
#define CON_TIMER_ID 0
#define TERM_LINES 25
#define TERM_COLS 80
#define PLATFORM_TMR_COUNTS_DOWN
// *****************************************************************************
// 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 8
#define NUM_SPI 0
#define NUM_UART 1
#define NUM_TIMER 2
#define NUM_PWM 0
#define NUM_ADC 0
#define NUM_CAN 0
// RPC boot options
#define RPC_UART_ID CON_UART_ID
#define RPC_TIMER_ID CON_TIMER_ID
#define RPC_UART_SPEED CON_UART_SPEED
// CPU frequency (needed by the CPU module and MMCFS code, 0 if not used)
#define CPU_FREQUENCY Fcclk
// PIO prefix ('0' for P0, P1, ... or 'A' for PA, PB, ...)
#define PIO_PREFIX '0'
// 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_PIN_ARRAY { 32, 20, 4, 6, 12, 6, 4, 1 }
// Allocator data: define your free memory zones here in two arrays
// (start address and end address)
#define SRAM_ORIGIN 0x00400000
#define SRAM_SIZE 0x10000
#define MEM_START_ADDRESS { ( void* )end, ( void* )SDRAM_BASE_ADDR }
#define MEM_END_ADDRESS { ( void* )( SRAM_ORIGIN + SRAM_SIZE - STACK_SIZE_TOTAL - 1 ), ( void* )( SDRAM_BASE_ADDR + SDRAM_SIZE - 1 ) }
// *****************************************************************************
// Auxiliary libraries that will be compiled for this platform
#if defined( ELUA_BOOT_RPC ) && !defined( BUILD_RPC )
#define BUILD_RPC
#endif
#if defined( BUILD_RPC )
#define RPCLINE _ROM( AUXLIB_RPC, luaopen_rpc, rpc_map )
#else
#define RPCLINE
#endif
#define LUA_PLATFORM_LIBS_ROM\
_ROM( AUXLIB_PIO, luaopen_pio, pio_map )\
_ROM( AUXLIB_TMR, luaopen_tmr, tmr_map )\
_ROM( AUXLIB_PD, luaopen_pd, pd_map )\
_ROM( AUXLIB_UART, luaopen_uart, uart_map )\
_ROM( AUXLIB_TERM, luaopen_term, term_map )\
_ROM( AUXLIB_PACK, luaopen_pack, pack_map )\
_ROM( AUXLIB_BIT, luaopen_bit, bit_map )\
_ROM( AUXLIB_ELUA, luaopen_elua, elua_map )\
RPCLINE\
_ROM( LUA_MATHLIBNAME, luaopen_math, math_map )
#endif // #ifndef __PLATFORM_CONF_H__

View File

@ -0,0 +1,9 @@
// Platform customization header
#ifndef __PLATFORM_GENERIC_H__
#define __PLATFORM_GENERIC_H__
#define PLATFORM_TMR_COUNTS_DOWN
#endif // #ifndef __PLATFORM_GENERIC_H__