unary negation
bitwise "and"
bitwise "or"
bitwise "exclusive or"
Res = bit.lshift( value, pos )
shift "value" left "pos" positions.
Res = bit.rshift( value, pos )
shift "value" right "pos" positions. The sign is not propagated.
Res = bit.arshift( value, pos )
shift "value" right "pos" positions. The sign is propagated ("arithmetic shift").
a shortcut for bit.lshift( 1, bitno )
Res1, Res2, ... = bit.set( bitno, v1, v2, ... )
set the bit at position "bitno" in v1, v2, ... to 1.
Res1, Res2, ... = bit.clear( bitno, v1, v2, ... )
set the bit at position "bitno"in v1, v2, ... to 0.
Res = bit.isset( value, bitno )
returns true if bit at position "bitno" in "value" is 1, false otherwise.
Res = bit.isclear( value, bitno )
returns true if bit at position "bitno" in "value" is 0, false otherwise.
write32( address, data ) : write the 32-bit data at the specified address
write16( address, data ) : write the 16-bit data at the specified address
write8( address, data ) : write the
8-bit data at the specified address
Data = read16( address ) : reads 16-bit data from the specified address
Data = read8( address ) : reads 8-bit data from the specified address
[cpu.disableinterrupts()] cli(): disable CPU interrupts
[cpu.enableinterrupts()] sei(): enable CPU interrupts
[cpu.clockfrequency()] Clock = clock(): returns the CPU frequency
Also, you can expose as many CPU constants (for example memory mapped registers)
as you want to this module. You might want to use this feature to access some
CPU memory areas (as defined in the CPU header files from the CPU support
package) directly from Lua. To do this, you'll need to define the
PLATFORM_CPU_CONSTANTS macro in the platform's platform_conf.h file
(src/platform/<platform name>/platform_conf.h). Include all your constants in a
_C( <constant name> ) definition, and then build your project.
For example, let's suppose that your CPU's interrupt controler has 3 memory
mapped registers: INT_REG_ENABLE, INT_REG_DISABLE and INT_REG_MASK. If you want
to access them from Lua, locate the header that defines the values of these
registers (I'll assume its name is "cpu.h") and add these lines to the
platform_conf.h:
#include "cpu.h"
#define PLATFORM_CPU_CONSTANTS\
_C( INT_REG_ENABLE ),\
_C( INT_REG_DISABLE ),\
_C( INT_REG_MASK )
After this you'll be able to access the regs directly from Lua, like this:
data = cpu.r32( cpu.INT_REG_ENABLE )
cpu.w32( cpu.INT_REG_ENABLE, data )
For a "real-life" example, see the src/platform/lm3s/platform_conf.h file.
[uart.sendstring] uart.sendstr( id, str1, str2, ... ): this is similar to "uart.send", but its parameters are string.
[gpio] pio
[gpio.setpinvalue] pio.setpin( value, Pin1, Pin2 ... ): set the value to all the pins in the list
to "value" (0 or 1).
[gpio.setpinhigh] pio.set( Pin1, Pin2, ... ): set the value of all the pins in the list to 1.
[gpio.getpinvalue] Val1, Val2, ... = pio.get( Pin1, Pin2, ... ): reads one or more pins and returns
their values (0 or 1).
[gpio.setpinlow] pio.clear( Pin1, Pin2, ... ): set the value of all the pins in the list to 0.
[gpio.configpin(gpio.DIR, gpio.DIR_INPUT)] pio.input( Pin1, Pin2, ... ): set the specified pin(s) as input(s).
[gpio.configpin(gpio.DIR, gpio.DIR_OUTPUT)] pio.output( Pin1, Pin2, ... ): set the specified pin(s) as output(s).
[gpio.setportvalue] pio.setport( value, Port1, Port2, ... ): set the value of all the ports in the
list to "value".
[gpio.getportvalue] Val1, Val2, ... = pio.getport( Port1, Port2, ... ): reads one or more ports and
returns their values.
[gpio.getportname] Port = pio.port( code ): return the physical port number associated with the given code. For example, "pio.port( pio.P0_20 )" will return 0.
[gpio.getpinnumber] Pin = pio.pin( code ): return the physical pin number associated with the
given code. For example, "pio.pin( pio.P0_20 )" will return 20.
[gpio.configport(gpio.DIR, gpio.DIR_INPUT, [Port1], [Port2], ...)] pio.port_input( Port1, Port2, ... ): set the specified port(s) as input(s).
[gpio.configport(gpio.DIR, gpio.DIR_OUTPUT, [Port1], [Port2], ...)] pio.port_output( Port1, Port2, ... ): set the specified port(s) as output(s).
[gpio.configpin(gpio.PULL, gpio.PULL_UP, [Pin1], [Pin2], ...)] pio.pullup( Pin1, Pin2, ... ): enable internal pullups on the specified pins.Note that some CPUs might not provide this feature.
[gpio.configpin(gpio.PULL, gpio.PULL_DOWN, [Pin1], [Pin2], ...)] pio.pulldown( Pin1, Pin2, ... ): enable internal pulldowns on the specified pins. Note that some CPUs might not provide this feature.
[gpio.configpin(gpio.PULL, gpio.PULL_NO, [Pin1], [Pin2], ...)] pio.nopull( Pin1, Pin2, ... ): disable the pullups/pulldowns on the specifiedpins. Note that some CPUs might not provide this feature.
It allows Lua to use the PWM blocks on the target CPU.
[pwm.setup](pwm.setup( id,
frequency, Active Cycle )
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.
Here there is a bigger change on the proposal.
The Timer Clock and the PWM "frame" frequency would be set up in the same function (.setup)
The normal control function would only set the active cicle (.setcycle)
The original .setup function would then be replaced by:
[pwm.setup( id,
tmrclock, pwm_frequency ) ]
[pwm.setcycle( id, active_cycle )]
[pwm.start()] pwm.start( id ): start the PWM block 'id'.
[pwm.stop()] pwm.stop( id ): stop the PWM block 'id'.
Data = pwm.setclock( id, clock ): set the base clock of the PWM block 'id' to
the given clock. In returns the actual clock set on the PWM block.
[pwm.getclock]
Data
= pwm.getclock( id ): returns the base clock of the PWM block 'id'.
[sys.platform()] pd.platform(): returns the platform name (f.e. LM3S)
[sys.mcu()] pd.cpu(): returns the CPU name (f.e. LM3S8962)
[sys.cpu()] would return ARM Cortex M3 in this case.....
[term.clear] term.clrscr(): clear the screen
[term.cleareol]
term.clreol(): clear from the current cursor position to the end of the
line
[term.moveto]
term.gotoxy( x, y ): position the cursor at the given coordinates
[term.moveup] term.up( delta ): move the cursor up "delta" lines
[term.movedown] term.down( delta ): move the cursor down "delta" lines
[term.moveleft] term.left( delta ): move the cursor left "delta" lines
[term.moveright] term.right(
delta ): move the cursor right "delta" lines
[term.getlinecount] Lines = term.lines(): returns the number of lines
[term.getcolcount] Cols = term.cols(): returns the number of columns
[term.printstr]
term.putstr( s1, s2, ... ): writes the specified string(s) to the
terminal
[term.printchar] term.put( c1, c2, ... ): writes the specified character(s) to the terminal
[term.getx] Cx = term.cursorx(): return the cursor X position
[term.gety] Cy = term.cursory(): return the cursor Y position
[term.inputchar] c = term.getch( term.WAIT | term.NOWAIT ): returns a char read from the
terminal.It allows Lua to execute timer specific operations (delay, read timer value,
start timer, get time difference).
tmr.delay( id, delay ): uses timer 'id' to wait for 'delay' us.
Data = tmr.read( id ): reads the value of timer 'id'. The returned value is
platform dependent.
Data = tmr.start( id ): start the timer 'id', and also returns its value at
the moment of start. The returned value is platform dependent.
diff = tmr.diff( id, end, start ): returns the time difference (in us) between
the timer values 'end' and 'start' (obtained from calling tmr.start or
tmr.read). The order of end/start is irrelevant.
Data = tmr.mindelay( id ): returns the minimum delay (in us ) that can be
achieved by calling the tmr.delay function. If the return value is 0, the
platform layer is capable of executing sub-microsecond delays.
Data = tmr.maxdelay( id ): returns the maximum delay (in us) that can be
achieved by calling the tmr.delay function.
Data = tmr.setclock( id, clock ): sets the clock of the given timer. Returns the
actual clock set for the timer.
Data = tmr.getclock( id ): return the clock of the given timer.
[uart.setup( id, baud, databits,
uart.PARITY_EVEN |uart.PARITY_ODD | uart.PARITY_NONE,
uart.STOPBITS_1 | uart.STOPBITS_1_5 | uart.STOPBITS_2 )] Actual_baud = uart.setup( id, baud, databits,
uart.PAR_EVEN |uart.PAR_ODD | uart.PAR_NONE,
uart.STOP_1 | uart.STOP_1_5 | uart.STOP_2 ): set the UART interface with the
given parameters, returns the baud rate that was set for the UART.
[uart.send] uart.send( id, Data1, Data2, ... ): send all the data to the specified UART interface.
#### Data 1 only
!?!!
[uart.recv( id,
uart.TIMEOUT_NO | uart.TIMEOUT_INFINITE |
timeout )
Data =
uart.recv( id, uart.NO_TIMEOUT | uart.INF_TIMEOUT | timeout ): reads a
byte from the specified UART interface.