more CPUs from a given platform. For example, the <b>lm3s port</b> of <b>eLua</b> runs on LM3S8962, LM3S6965 and LM3S6918 CPUs, all of them part of the
<b>lm3s</b> platform. Refer to <ahref="status.html">the status page</a> for a full list of platforms and CPUs on which <b>eLua</b> runs.</p>
<p>As can be seen from this image, <b>eLua</b> tries to be as portable as possible between different platforms by using a few simple design
<li>all code that is platform-independent is <b>common code</b> and it should be written in ANSI C as much as possible, this makes it highly portable
among different architectures and compilers, just like Lua itself. </li>
<li>all the code that can't possibly be generic (mostly peripheral and CPU specific code) must still be made as portable as possible by using a common
interface that must be implemented by all platforms on which <b>eLua</b> runs. This interface is called <b>platform interface</b> and is discussed in
detail <ahref="arch_platform.html">here</a> (but please see also <ahref="arch_overview.html#platform">"The platform interface"</a>
paragraph in this document).</li>
<li>all platforms (and their peripherals) are not created equal and vary greatly in capabilities. As already mentioned, the platform interface tries
to group only common attributes of different platforms. If one needs to access the specific functionality on a given platform (like the loopback support
mentioned before) it can do so by using a <b>platform module</b>. These are of course platform specific, and their goal is to fill the gap between the
platform interface and the full set of features provided by a platform.</li>
<li>if you want to add a new file system to <b>eLua</b>, this should definitely be generic code. It's likely that this kind of code will have
dependencies related to the physical medium on which this file system resides. If you're lucky, you can solve these dependencies using only the functions
platform interface already has a SPI layer). If not, you should group the platform specific functions in a separate interface that will be implemented by
all platform that want to use your new file system. This gives the code maximum portability.</li>
<li>if you want to add a driver for a specific ADC chip that works over SPI, the same observations apply: write it as common code as much as you can,
<p>Used properly, the platform interface allows writing extremely portable code over a large variety of different platforms, both from C and from Lua.
An important property of the platform interface is that it tries to group only <b>common</b> attributes of different platforms (as much as possible).
For example, if a platform supported by <b>eLua</b> has an UART that can work in loopback mode, but the others don't, loopback support won't be included
in the platform interface.</p>
<p>A special emphasis on the platform interface usage: remember to use it not only for Lua, but also for C. The platform interface is mainly used by the
generic modules to allow Lua code to access platform peripherals, but this isn't its only use. It can (and it should) also be used by C code that wants
to implement a generic module and neeeds access to peripherals. An example was given in the previous section: implementing a new file system.</p>
but have a common behaviour on all platforms (for example virtual timers, see <ahref="arch_platform_timers.html#virtual_timers">here</a> for details). You probably won't need to modify
module already found in the platform interface, it should have the same name, otherwise it should be given a different, but meaningful name. For example:</p>
<p>All the code for platform <i>name</i> (including peripheral drivers) must reside in a directory called <i>src/platform/<name></i> (for example
<i>src/platform/lm3s</i> for the <i>lm3s</i> platform). Each such platform-specific subdirectory must contain at least these files:</p>
<ul>
<li><b>type.h</b>: this defines the "specific data types", which are integer types with a specific size (see <ahref="arch_coding.html">coding style</a>
for details. An example from the <b>i386</b> platform:
<li><b>conf.py</b>: this is the platform specific build configuration file, used by the <ahref="building.html">build system</a> for a number of purposes:
<ul>
<li>to get the list of platform-specific files that will be compiled in the <b>eLua</b> image. They are exported in the <i>specific_files</i> string,
separated by spaces, and must be prepended with the relative path to the platform subdirectory. An example from the <b>i386</b> platform:
<li>to get the full command lines of the different toolchain utilities (linker, assembler, compiler) used to compile <b>eLua</b>. They must be declared
inside the <i>tools</i> variable, in a separate dictinoary which key is the same as the platform name, and with specific names for each tool in turn:
<b>cccom</b> for the compiler, <b>linkcom</b> for the linker and <b>ascom</b> for the assembler.
For example, this is how the <i>tools</i> variable is defined for the <b>i386</b> platform:
Note, once again, how this function uses the same <i>toolset</i> variable mentioned in the previous paragraph.
</li>
</ul>
</li>
<li><b>stacks.h</b>: by convention, the stack(s) size(s) used in the system are declared in this file. An example taken from the <b>at91sam7x</b> platform is given below:
<li><b>platform.c</b>: by convention, the <ahref="arch_platform.html">platform interface</a> is implemented in this file. It also contains the platform-specific
<li><b>platform_conf.h</b>: this is the platform configuration file, used to give information about both the platform itself and the build configuration for the
platform. This is what you can set inside <b>platform_conf.h</b>:
<ul>
<li>the list of <b>components</b> that will be part of the build (see <ahref="building.html">building eLua</a> for details).</li>
<li>the list of <b>modules</b> that will be part of the build (see <ahref="building.html">building eLua</a> and <ahref="arch_ltr.html#config">LTR configuration</a>
for details.</li>
<li>the <b>static configuration data</b> (see <ahref="building.html">building eLua</a> for details).</li>
<li>the <b>number of peripherals</b> on your CPU. See an example below (taken from <b>lm3s</b>) that also shows how to differentiate between different CPUs that belong to the same
platform; the <b>FORxxxx</b> macros are defined in <b>conf.py</b>):
<li><b>specific peripheral configuration</b>: this includes (but it not limited to) enabling buffering on UART, enabling and setting up virtual timers, setting PIO configuration and so on.
<li><b>memory configuration</b>: describes the regions of free RAM in the system, which will be later used by the standard system allocator (malloc/realloc/free). Two macros
(<b>MEM_START_ADDRESS</b> and <b>MEM_END_ADDRESS</b>) define two arrays with the beginning and the end of all the free RAM memory in the system. If your board has external RAM memory, you
should define it here. If not, you can only use the internal memory, and you'll generally need to use the linker-defined symbol <b>end</b> to find out where your free memory starts. Following
is an example from the <b>ATEVK1100</b> (AVR32) board that has both on-chip and external RAM:
<li>if boot is set to 'standard' and the <ahref="using.html#shell">shell</a> was compiled in the image, it is started, in the absence of the shell, a standard Lua interpreter is started.</li>
<li>if boot is set to 'luarpc' an rpc server is started.</li>