eLua reference manual - CPU module
Overview
This module deals with low-level access to CPU (and related modules) functionality, such as reading and writing memory, or enabling and disabling interrupts. It also offers access to platform specific CPU-related constants using a special macro defined in the platform's platform_conf.h file, as explained here.
Data structures, constants and types
cpu.INT_GPIOA
cpu.INT_GPIOB
.............
cpu.INT_UDMA
eLua has a mechanism that lets the user export an unlimited number of constants to the cpu module. Although in theory any kind of constant can be exposed by this module, one should only use constants related to the CPU and its subsystems (as shown above, where a number of CPU specific interrupt masks are exposed to Lua using this mechanism). To use this mechanism, just declare the PLATFORM_CPU_CONSTANTS macro in your platform's platform_conf.h file and list all your constants as part of this macro, each enclosed in a special macro called _C. For example, to get the constants listed above declare your PLATFORM_CPU_CONSTANTS macro like this:
#define PLATFORM_CPU_CONSTANTS\ _C( INT_GPIOA ),\ _C( INT_GPIOB ),\ ................. _C( INT_UDMA )
It's worth to note that adding more constants does not increas RAM usage, only Flash usage, so you can expose as much constants as you need without worrying about RAM consumption.
This mechanism is also used to expose interrupt IDs to the CPU module, check here for an overview of eLua interrupt support.
Functions
cpu.w32( address, data )
Writes a 32-bit word to memory.
Arguments:
- address - the memory address.
- data - the 32-bit data to write.
Returns: nothing.
data = cpu.r32( address )
Read a 32-bit word from memory.
Arguments: address - the memory address.
Returns: data - the 32-bit word read from memory.
cpu.w16( address, data )
Writes a 16-bit word to memory.
Arguments:
- address - the memory address.
- data - the 16-bit data to write.
Returns: nothing.
data = cpu.r16( address )
Reads a 16-bit word from memory.
Arguments: address - the memory address.
Returns: data - the 16-bit word read from memory.
cpu.w8( address, data )
Writes a byte to memory.
Arguments:
- address - the memory address.
- data - the byte to write.
Returns: nothing.
data = cpu.r8( address )
Reads a byte from memory.
Arguments: address - the memory address
Returns: data - the byte read from memory.
cpu.cli( [id], [resnum1], [resnum2], ... [resnumn])
Disables the global CPU interrupt flag if called without arguments, or a specific interrupt for a list of resource IDs if called with arguments.
Arguments:
- id - the interrupt ID. If specified, at least one resource ID must also be specified.
- resnum1 - the first resource ID, required if id is specified.
- resnum2 (optional) - the second resource ID.
- resnumn (optional) - the #n#-th resource ID.
Returns: nothing.
cpu.sei( [id], [resnum1], [resnum2], ... [resnumn])
Enables the global CPU interrupt flag if called without arguments, or a specific interrupt for a list of resource IDs if called with arguments.
Arguments:
- id - the interrupt ID. If specified, at least one resource ID must also be specified.
- resnum1 - the first resource ID, required if id is specified.
- resnum2 (optional) - the second resource ID.
- resnumn (optional) - the #n#-th resource ID.
Returns: nothing.
clock = cpu.clock()
Get the CPU core frequency.
Arguments: none.
Returns: clock - the CPU clock (in Hertz).
prev_handler = cpu.set_int_handler( id, handler )
Sets the Lua interrupt handler for interrupt *id* to function *handler*. *handler* can be #nil# to disable the interrupt handler. Only available if interrupt support is enabled, check here for details.
Arguments:
- id - the interrup ID.
- handler - the Lua interrupt handler function, or *nil* to disable the Lua interrupt handler feature.
Returns: prev_handler - the previous interrupt handler for interrupt *id*, or *nil* if an interrupt handler was not set for interrupt *id*.
handler = cpu.get_int_handler( id )
Returns the Lua interrupt handler for interrupt *id*
Arguments: id - the interrup ID.
Returns: handler - the interrupt handler for interrupt *id*, or *nil* if an interrupt handler is not set for interrupt *id*.
cpu.get_int_flag( id, resnum, [clear] )
Get the interrupt pending flag of an interrupt ID/resource ID combination, and optionally clear the pending flag. Only available if interrupt support is enabled, check here for details.
Arguments:
- id - the interrupt ID.
- resnum - the resource ID.
- clear (optional) - true to clear the interrupt pending flag or false to leave the interrupt pending flag untouched. Defaults to true if not specified.
Returns: nothing.