This should really be more than one commit, but I wrote everything in one
shot and I don't feel like arranging the changes logically into different
commits. So, these are the changes:
- added WOFS (Write Once File System). This is a writeable file system that
exists in the MCU's internal Flash memory and allows files to be written,
but only once, in a single shot. More details to follow.
- the platform interface has a new MCU flash access interface.
- added WOFS "reference implementations" for two CPUs: LM3S8962 and
STM32F103RE. They are easily extendable to other CPUs in the same platform
and can be taken as a model for other platforms.
- the ROMFS file layout in memory was slightly changed.
- the simulator (src/platform/sim) got a new function (lseek).
- shell: now each shell command receives its arguments in a C-main-style
(argc, argv) pair. This was originally Marcelo's idea and it finally
made it to the master (although this particular implementation is mine),
after I got fed up with all the argument parsing in the shell functions.
- new shell command: wofmt ("formats" a WOFS, effectively clearing it).
- a couple of small fixes in the shell code
1. the filename for 'recv <filename>' was not set correctly
2. error messages for 'cp' were not always correct
3. check for copy errors and issue a message accordingly
All the functions that implement a FS receive the instance data
of the FS (given at registration time to dm_register) as their
last argument. ROMFS was changed to take advantage of this.
Now it's possible to have more than one instance of a given file
system. For example, one could use more that one ROM file system
in different physical locations (a possible configuration is
internal Flash and external serial memories). This mechanism is
currently implemented only in the device manager (devman.c),
actual instance implementation require per-FS support (to be
implemented later).
On some platforms, the hardware timers were counting down instead
of up, which broke the assumptions of the new timer implementation.
Fixed by inverting the timer value (relative to its maximum value).
This patch adds more RAM optimizations to eLua:
- direct file memory mapping: files in ROMFS will be read directly from Flash,
without allocating any additional buffers. This doesn't help with RAM
consumption in itself, but enables the set of optimizations below.
- pseudo read-only strings. These are still TStrings, but the actual string
content can point directly to Flash. Original Lua strings are kept in
TStrings structures (lobject.h):
typedef union TString {
L_Umaxalign dummy; /* ensures maximum alignment for strings */
struct {
CommonHeader;
lu_byte reserved;
unsigned int hash;
size_t len;
} tsv;
} TString;
The actual string content comes right after the union TString above.
Pseudo RO strings have the same header, but instead of having the string
content after TString, they have a pointer that points to the actual
string content (which should exist in a RO memory (Flash) that is directly
accesbile from the MCU bus (like its internal Flash memory)). lua_newlstr
detects automatically if it should create a regular string or a pseudo RO
string by checking if the string pointer comes from the Flash region of the
MCU. This optimization works for both precompiled (.lc) files that exist in
ROMFS and for internal Lua strings (C code).
- functions in Flash: for precompiled (.lc) files that exist in ROMFS, the code
of the functions and a part of the debug information will be read directly
from Flash.
- ROMFS was changed to support files that are larger than 2**16 bytes and it
aligns all its files to an offset which is a multiple of 4 in order to prevent
data alignment issues with precompiled Lua code.
- the Lua bytecode dumper was changed to align all the instructions in a Lua
function and a part of the debug information to an offset which is a multiple
of 4. This might slightly increase the size of the precompiled Lua file.
These changes were succesfully checked against the Lua 5.1 test suite.
These changes were tested in eLua on LM3S and AVR32.
From the Lua Power Patches page:
"Use NaN packing for TValue on x86 to reduce memory usage
and tiny performance gain (same as in LuaJIT i2).
It's fully ABI compatible with standard Lua libraries.
On one test script memory consumption reduced from 28Mb
to 21Mb and performance improved about 3.5-5%"
Added support for big endian architectures and LTR compatibility.
luaD_checkstack could damage the stack, possibly making further
references to 'func' invalid. Fix this by using the information
inside the CallInfo structure instead of 'func'.
helper_remote_index() contained an error which allowed for incorrect
calculation of the string length to be sent. This should now be
fixed. Additionally, read_cmd_call() did not check whether indexing
was successful at each step, we now check whether the indexed result
is callable or a table and attempt to provide an indication of the
type of error made by the user.
Methods: mizar32.rtc.get() returns a table like Lua's os.date()
and os.time() with fields year, monthm day, wday, hour min, sec
and mizar32.rtc.set() takes a similar table, only changing the
fields that are present in the table.
Works with DS1337 and PCF8563 clock chips.
Many mizar32.lcd() Lua functions used to tail-call the i2c_send_command()
functions, whereas they should explicitly return 0, the number of return
values from the Lua function. OK, i2c_send_command did return 0 but this
will change in future when it can detect slave presence and collisions.
On AVR32UC3A0 parts, the GPIO pins are named PA0-31, PB0-31, PC0-5 and
PX0-39. There is no port X: these pins map to five backwards ranges of
bits in the third and fourth sets of GPIO registers (where PC0-5 are
the first six of the third register set).
Already we map pio.PX_nn names to these values, and this commit puts the
reverse mapping into place in pio.decode().
Test program to verify correct mapping:
function eval(s)
return( loadstring( "return(" .. s .. ")" ) )()
end
for i=0,39 do
name = "pio.PX_" .. tostring(i)
gpio = eval(name)
print( name, gpio, pio.decode(gpio) )
end
These changes allow you to "#define UIP_CONF_IPV6 1" in uip-conf.h
for an IPV6-capable network layer.
This also removes a pointless inclusion in avr32/uip-conf.h
The changes to the other three .c files (from "build.h" to "platform_conf.h")
are just orthogonal future-proofing.
This change defers enabling the SPI clocks to platform_spi_setup()
so that, if SPI ports are not used and BUILD_MMCFS is disabled,
power consumption is reduced.
This change removes the extra undocumented uart.SYS_TIMER and
net.SYS_TIMER constants, which are equal to tmr.SYS_TIMER.
The documentation says to use tmr.SYS_TIMER and in the rare case
of uart or net being compiled in but not tmr, the system timer
can be had by using nil or omitting the parameter.
newline characters.
The console used to drop the second one of repeated \r or \n characters
because it would stash the second one in std_prev_char, then at the start
of the next call to std_read(), would poke the \r into the start of the
line buffer, returning a line that began with \r or \n.
This change processes the lookahead character the same as regular ones.
Previously, when pasting multiple lines into the console, the first
character of half the lines would not be echoed. This was due to it being
slurped up by the CRLF lookahead detector, but not being echoed when it was
regurgitated. This change fixes that.