[cpu.enableinterrupts()] <fontface="Bitstream Vera Sans Mono, sans-serif">sei(): enable
CPU interrupts</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="cpu_clockfrequency"></a>[cpu.clockfrequency()]
Clock = clock(): returns the CPU frequency</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">Also, you can
expose as many CPU constants (for example memory mapped registers)</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">as you want to
this module. You might want to use this feature to access some </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">CPU memory areas
(as defined in the CPU header files from the CPU support </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">package)
directly from Lua. To do this, you'll need to define the </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">PLATFORM_CPU_CONSTANTS
macro in the platform's platform_conf.h file </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">(src/platform/<platform
name>/platform_conf.h). Include all your constants in a </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">_C(
<constant name> ) definition, and then build your project.</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">For example,
let's suppose that your CPU's interrupt controler has 3 memory</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">mapped
registers: INT_REG_ENABLE, INT_REG_DISABLE and INT_REG_MASK. If you want</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">to access them
from Lua, locate the header that defines the values of these</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">registers (I'll
assume its name is "cpu.h") and add these lines to the</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">platform_conf.h:</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">#include "cpu.h"</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">#define
PLATFORM_CPU_CONSTANTS\</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">_C(
INT_REG_ENABLE ),\</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">_C(
INT_REG_DISABLE ),\</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">_C( INT_REG_MASK
)</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">After this
you'll be able to access the regs directly from Lua, like this:</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">data = cpu.r32(
cpu.INT_REG_ENABLE )</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">cpu.w32(
cpu.INT_REG_ENABLE, data )</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">For a
"real-life" example, see the src/platform/lm3s/platform_conf.h file.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">[uart.sendstring]
uart.sendstr( id, str1, str2, ... ): this is similar to "uart.send",
pio.nopull( Pin1, Pin2, ... ): disable the pullups/pulldowns on the
specifiedpins. Note that some CPUs might not provide this feature.
</p>
<br>
<h3><aname="netmodule"></a>net</h3>
<br>
<h3><aname="pwmmodule"></a>pwm</h3>
<spanstyle="font-weight: bold;"></span><br>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">It allows Lua to
use the PWM blocks on the target CPU.</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><strike><aname="pwm_setup"></a>[pwm.setup]</strike>(</font><fontface="Bitstream Vera Sans Mono, sans-serif">pwm.setup( id,
frequency, Active Cycle ) </font><fontface="Bitstream Vera Sans Mono, sans-serif">
Data = pwm.setup( id, frequency, duty ): sets the PWM block 'id' to
generate the specified frequency with the specified duty cycle (duty is
an integer number from 0 to 100, specifying the duty cycle in
percents). It returns the actual frequency set on the PWM block.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"> Here there is a bigger
change on the proposal.
</p>
<pstyle="margin-bottom: 0in;"> The Timer Clock and the
PWM "frame" frequency would be set up in the same function (.setup)
</p>
<pstyle="margin-bottom: 0in;"> The normal control
function would only set the active cicle (.setcycle)
</p>
<pstyle="margin-bottom: 0in;"> The original .setup
function would then be replaced by:
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">[pwm.setup( id,
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="pwm_start"></a>[pwm.start()]
pwm.start( id ): start the PWM block 'id'.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="pwm_stop"></a>[</font><fontface="Bitstream Vera Sans Mono, sans-serif">pwm.stop()]
</font><fontface="Bitstream Vera Sans Mono, sans-serif">pwm.stop(
id ): stop the PWM block 'id'.</font>
</p>
<br>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="pwm_setclock"></a>Data = pwm.setclock( id, clock ):
set the base clock of the PWM block 'id' to</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">the given clock.
In returns the actual clock set on the PWM block.</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">[</font><fontface="Bitstream Vera Sans Mono, sans-serif"><strike>pwm.getclock</strike>]
</font><fontface="Bitstream Vera Sans Mono, sans-serif">Data
= pwm.getclock( id ): returns the base clock of the PWM block 'id'.</font>
<fontstyle="font-family: Helvetica,Arial,sans-serif;"size="2"><big>Sending multiple data/chars in a single
call and not in
a table argument does not allow the data to be built in run time
(without some string massage, of course :)</big></font><br>
<br>
<br>
<br>
</big>
<h3><aname="sysmodule"></a>sys</h3>
<br>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="sys_platform"></a>[sys.platform()]
pd.platform(): returns the platform name (f.e. LM3S)</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="sys_mcu"></a>[sys.mcu()]
pd.cpu(): returns the CPU name (f.e. LM3S8962)</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="sys_cpu"></a>[sys.cpu()]
would return ARM Cortex M3 in this case.....</font></p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<fontface="Bitstream Vera Sans Mono, sans-serif"> <aname="sys_board"></a>[sys.board()]</font><fontface="Bitstream Vera Sans Mono, sans-serif">
pd.board(): returns the CPU board (f.e. EK-LM3S8962)</font>
<pstyle="margin-bottom: 0in;"><br>
</p>
<h3><aname="term_termmodule">term</a></h3>
Terminal support
<p><aname="term_clear"></a>[term.clear]
term.clrscr(): clear the screen </p>
<p> <br>
<aname="term_cleareol"></a>[term.cleareol]
term.clreol(): clear from the current cursor position to the end of the
line </p>
<p> </p>
<p><aname="term_moveto"></a> [term.moveto]
term.gotoxy( x, y ): position the cursor at the given coordinates<br>
</p>
<br>
<p><aname="term_moveup"></a> [term.moveup]
term.up( delta ): move the cursor up "delta" lines </p>
<p> </p>
<p><aname="term_movedown"></a> [term.movedown]
term.down( delta ): move the cursor down "delta" lines </p>
<p> </p>
<p><aname="term_moveleft"></a> [term.moveleft]
term.left( delta ): move the cursor left "delta" lines </p>
c = term.getch( term.WAIT | term.NOWAIT ): returns a char read from the
</font></p>
<fontsize="2"> terminal.</font>
<brstyle="font-family: Verdana;">
<br>
<br>
<h3><aname="tmr_tmrmodule"></a>tmr</h3>
<spanstyle="font-weight: bold;"></span><big><br>
</big>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">It allows Lua to
execute timer specific operations (delay, read timer value,</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">start timer, get
time difference).</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_delay"></a>tmr.delay( id, delay ): uses timer
'id' to wait for 'delay' us.</font>
</p>
<pstyle="margin-bottom: 0in;"><br>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><spanstyle="font-style: italic;"><aname="tmr_read"></a></span>Data
= tmr.read( id ): reads the value of timer 'id'. The returned value is </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">platform
dependent.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><spanstyle="font-style: italic;"><aname="tmr_start"></a></span>Data
= tmr.start( id ): start the timer 'id', and also returns its value at</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">the moment of
start. The returned value is platform dependent.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_diff"></a>diff
= tmr.diff( id, end, start ): returns the time difference (in us)
between</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">the timer values
'end' and 'start' (obtained from calling tmr.start or</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">tmr.read). The
order of end/start is irrelevant. </font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_mindelay"></a>Data = tmr.mindelay( id ): returns
the minimum delay (in us ) that can be </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">achieved by
calling the tmr.delay function. If the return value is 0, the </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">platform layer
is capable of executing sub-microsecond delays.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_maxdelay"></a>Data = tmr.maxdelay( id ): returns
the maximum delay (in us) that can be</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">achieved by
calling the tmr.delay function.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_setclock"></a>Data = tmr.setclock( id, clock ):
sets the clock of the given timer. Returns the</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">actual clock set
for the timer.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="tmr_getclock"></a>Data = tmr.getclock( id ): return
the clock of the given timer.</font>
</p>
<br>
<br>
<br>
<br>
<br>
<h3><aname="uartmodule"></a>uart</h3>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="uart_setup"></a>[uart.setup(</font><fontface="Bitstream Vera Sans Mono, sans-serif"> id, baud,
databits, </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">uart.PARITY_EVEN
|uart.</font><fontface="Bitstream Vera Sans Mono, sans-serif">PARITY</font><fontface="Bitstream Vera Sans Mono, sans-serif">_ODD | uart.</font><fontface="Bitstream Vera Sans Mono, sans-serif">PARITY</font><fontface="Bitstream Vera Sans Mono, sans-serif">_NONE, </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">uart.STOPBITS_1
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">uart.PAR_EVEN
|uart.PAR_ODD | uart.PAR_NONE, </font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">uart.STOP_1 |
uart.STOP_1_5 | uart.STOP_2 ): set the UART interface with the</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">given
parameters, returns the baud rate that was set for the UART.</font>
</p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="uart_send"></a>[</font><fontface="Bitstream Vera Sans Mono, sans-serif">uart.send] </font><fontface="Bitstream Vera Sans Mono, sans-serif">uart.send( id,
Data1, Data2, ... ): send all the data to the specified UART interface.</font>
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif">#### Data 1 only
!?!!<br>
</font></p>
<pstyle="margin-bottom: 0in;">
</p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<pstyle="margin-bottom: 0in;"><fontface="Bitstream Vera Sans Mono, sans-serif"><aname="uart_recv"></a>[</font><fontface="Bitstream Vera Sans Mono, sans-serif">uart.recv(</font><fontface="Bitstream Vera Sans Mono, sans-serif"> id,
Modules</h3><h3><aname="adcmodule"></a>adc</h3>Currently runs on: LM3S <br><br><aname="adc_sample"></a>adc.sample(channel_id) - generate one processed sample<br><br><aname="adc_getsamples"></a>adc.getsamples(channel_id,
count) - request (count) samples from the buffer. if singular, an
integer is returned. if multiple, a table of integers is returned. If
count is either zero or omitted, all available samples are returned.<br><br><aname="adc_maxval"></a>adc.maxval(channel_id) - returns largest integer one can expect for this channel on a given platform (based on bit depth)<br><br><aname="adc_samplesready"></a>adc.samplesready(channel_id) - returns number of samples waiting in the buffer<br><br><aname="adc_dataready"></a>adc.dataready(channel_id)
are waiting in the buffer<br><br><aname="adc_setmode"></a>adc.setmode(channel_id,
mode) - mode: 0 sets mode to blocking (getsamples will wait for
requested samples to be captured before returning), 1 sets non-blocking<br><br><aname="adc_setsmoothing"></a>adc.setsmoothing(channel_id, length) - set the length of the smoothing filter, this must be a power of 2 (maximum = 128)<br><br><aname="adc_getsmoothing"></a>adc.getsmoothing(channel_id) - get the current smoothing length in use<br><br><aname="adc_burst"></a>adc.burst(