mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
17487f9ebe
- This should actually be a merge but we made a mistake on the initial repo creation and a merge was not possible. - Below there is a resumed log of the commit messages for the few steps, just for the record. - The merged commit messages for this work are: - Removing Portuguese doc content - Ignore folder names fixed on .gitignore - Removed doc files which content migrated to the CMS - docdata.lua updated accordingly - Doc build checked ok - Overall doc structure and contents still being refined - Removing folder cache from git versioning - Removing folder dist from git versioning. The folders above are generated by the buildall.lua script and are not part of the sources - Adding .gitignore file with objects info to inform git what to ignore - Removed file - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git - Moving all files and folders to a working doc folder - Css updated - Index page added and CSS adjusts - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git - Signed-off-by: Guilherme Sanchez <guilhermesanchezpacheco@gmail.com> - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git - files deleted - Changed function that creates functions submenus. - Menu inserted with árvore, CSS adjusts, google search - Changed past design to new design - CSS updated - initial import - The commit ids were also preserved but they are related to this "other" work done on Led Lab. We'll keep the repo just in case. 4dce3f77c47b0c3001a2075a946e80ee52759b49 - Removing Portuguese doc content 78d8847525cacf045fe7e672cff6bd1e058a6a4b Ignore folder names fixed on .gitignore 48dee6b7962168ab1098bf709ead6f3cfe6b7964 - Removed doc files which content migrated to the CMS - docdata.lua updated accordingly - Doc build checked ok - Overall doc structure and contents still being refined 2aa2fe0c554db03dbc7029c34d0f4500fe625b37 - Removing folder cache from git versioning - Removing folder dist from git versioning The folders above are generated by the buildall.lua script and are not part of the sources - Adding .gitignore file with objects info to inform git what to ignore af6cc2890edf1855af319dc999a03feee5f9bee0 Removed file 6a180e72eb4f4860620cafc0685000e9f2174cfe Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git eb430112e78ae537459ab315e228ebca84bdf2d4 Moving all files and folders to a working doc folder d28a7c99489915630bd2625f3756fecf0d08ce37 Css updated 32836ffe382f04ab07c3e6f018c7b449a20d7a8d Index page added and CSS adjusts 1461d9957d9d25a1467cb57ab8717aa213a37e8d Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git ae1934c04f35a29e25bb4495ae8a31cd9c000b5b Signed-off-by: Guilherme Sanchez <guilhermesanchezpacheco@gmail.com> b5f31d70f1fac8d3fba325c9867a03f976775698 Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git ec9ad8446b7ea38b252c6a416e70774349835e45 files deleted bd7a80151b2030720ba8d8a303467d8c25a4b4b2 Changed function that creates functions submenus. 6a7494acaec694fadbb13520bcbccc51a6b95dfe Inserido menu com árvore, ajustes no CSS, busca do google e979f1c259d425c9a3be83f9cda20eddffe073bb Changed past design to new design. 381459e95286886b052103a0253e60b29e064d7a CSS updated 4f81d2f1195efe733fe5f97517be325d75937bc3 initial import
139 lines
6.4 KiB
Plaintext
139 lines
6.4 KiB
Plaintext
// $$HEADER$$
|
|
eLua interrupt support implementation
|
|
-------------------------------------
|
|
|
|
To add interrupt support for an eLua platform follow the steps below:
|
|
|
|
1. *Define your interrupts*
|
|
+
|
|
Your interrupt sources should be defined in link:arch_platform.html[platform_conf.h] with macros (don't use C enumerations). The first one should have the value *ELUA_INT_FIRST_ID*
|
|
(defined in _inc/elua_int.h_), the next one *ELUA_INT_FIRST_ID + 1* and so on. Also, there should be a definition for a macro called *INT_ELUA_LAST* that must be equal to the largest
|
|
interrupt source value. An example is given below:
|
|
+
|
|
------------------------------
|
|
#define INT_GPIO_POSEDGE ELUA_INT_FIRST_ID
|
|
#define INT_GPIO_NEGEDGE ( ELUA_INT_FIRST_ID + 1 )
|
|
#define INT_TMR_MATCH ( ELUA_INT_FIRST_ID + 2 )
|
|
#define INT_ELUA_LAST INT_TMR_MATCH
|
|
------------------------------
|
|
+
|
|
Note that the interrupt names aren't random, they should follow a well defined pattern. Check <<intlist, here>> for details.
|
|
|
|
2. *Add them to the list of constants from the CPU module*
|
|
+
|
|
Check the documentation of the _mcpu module for details.
|
|
|
|
3. *Implement your support functions*
|
|
+
|
|
The actual implementation of the interrupt handlers is of course platform specific, so it can stay in the _platform.c_ file. However, since interrupt handlers might require quite a bit
|
|
of code, it is recommended to implement them in a separate file. The eLua convention is to use the _platform_int.c_ file for this purpose. For each interrupt defined in step 1 above, 3
|
|
functions need to be implemented:
|
|
+
|
|
--
|
|
* A function that enables or disables the interrupt and returns its previous state (enabled or disabled).
|
|
* A function that checks if the interrupt is enabled or disabled.
|
|
* A function that checks the interrupt pending flag and optionally clears it.
|
|
--
|
|
+
|
|
These functions are defined in _inc/elua_int.h_, which also defines an "int descriptor" type:
|
|
+
|
|
------------------------------
|
|
// Interrupt functions and descriptor
|
|
typedef int ( *elua_int_p_set_status )( elua_int_resnum resnum, int state );
|
|
typedef int ( *elua_int_p_get_status )( elua_int_resnum resnum );
|
|
typedef int ( *elua_int_p_get_flag )( elua_int_resnum resnum, int clear );
|
|
typedef struct
|
|
{
|
|
elua_int_p_set_status int_set_status;
|
|
elua_int_p_get_status int_get_status;
|
|
elua_int_p_get_flag int_get_flag;
|
|
} elua_int_descriptor;
|
|
------------------------------
|
|
+
|
|
_platform_int.c_ must have an array of *elua_int_descriptor* types named *elua_int_table* (remember to make it _const_ to save RAM). The elements of this array must be in the same
|
|
order as the interrupt sources. The interrupt table for the example from step 1 above might look like this:
|
|
+
|
|
------------------------------
|
|
const elua_int_descriptor elua_int_table[ INT_ELUA_LAST ] =
|
|
{
|
|
{ int_gpio_posedge_set_status, int_gpio_posedge_get_status, int_gpio_posedge_get_flag },
|
|
{ int_gpio_negedge_set_status, int_gpio_negedge_get_status, int_gpio_negedge_get_flag },
|
|
{ int_tmr_match_set_status, int_tmr_match_get_status, int_tmr_match_get_flag }
|
|
};
|
|
------------------------------
|
|
|
|
4. *Implement the init function*
|
|
+
|
|
_platform_int.c_ should implement a function named *platform_int_init* (defined in _inc/platform.h_) that must initialize all the required hardware and the internal data structures of
|
|
the interrupt subsystem. This function should be called from *platform_init*.
|
|
|
|
5. *Implement the interrupt handlers*
|
|
+
|
|
There are two simple requirements for the interrupt handlers: clear the hardware interrupt flag (if needed) and call *cmn_int_handler* (_src/common.c_) to connect the handler with the
|
|
eLua interrupt code. An example is given below:
|
|
+
|
|
[subs="quotes"]
|
|
-------------------------------
|
|
// EINT3 (INT_GPIO) interrupt handler
|
|
static void int_handler_eint3()
|
|
{
|
|
elua_int_id id = ELUA_INT_INVALID_INTERRUPT;
|
|
pio_code resnum = 0;
|
|
int pidx, pin;
|
|
|
|
EXTINT |= 1 << EINT3_BIT; // clear interrupt
|
|
// Look for interrupt source
|
|
// In can only be GPIO0/GPIO2, as the EXT interrupts are not (yet) used
|
|
pidx = ( IO_INT_STAT & 1 ) ? 0 : 1;
|
|
if( *posedge_status[ pidx ] )
|
|
{
|
|
id = INT_GPIO_POSEDGE;
|
|
pin = intlog2( *posedge_status[ pidx ] );
|
|
}
|
|
else
|
|
{
|
|
id = INT_GPIO_NEGEDGE;
|
|
pin = intlog2( *negedge_status[ pidx ] );
|
|
}
|
|
resnum = PLATFORM_IO_ENCODE( pidx * 2, pin, PLATFORM_IO_ENC_PIN );
|
|
[bblue]** *intclr_regs[ pidx ] = 1 << pin**;
|
|
|
|
// Run the interrupt through eLua
|
|
[bblue]**cmn_int_handler( id, resnum )**;
|
|
VICVectAddr = 0; // ACK interrupt
|
|
}
|
|
-------------------------------
|
|
|
|
That's it. If you followed all these steps correctly, your platform should be fully able to support interrupt handlers (as described link:inthandlers.html[here]). Check the *lpc24xx*
|
|
platform implementation (_src/platform/lpc24xx_) for a full example.
|
|
|
|
[[intlist]]
|
|
Interrupt list and naming conventions
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
To ensure maximum portability and correct system behaviour, interrupt names (as defined in _platform_conf.h_) *must* follow a well-defined naming pattern. Please note that this isn't
|
|
merely a convention, many times the names must be properly chosen for the system to work properly. For example, the timer interrupt match will never happen on virtual timers if the
|
|
timer interrupt match name isn't *INT_TMR_MATCH* (see link:arch_platform_timers.html[here] for more details on how to use the timer match interrupt).
|
|
|
|
The naming rule is that the interrupt name must have the format *INT_<peripheral>_<type>_*, where:
|
|
|
|
* *peripheral* is a symbolic name of the peripheral to which the interrupt applies.
|
|
* *type* is a symbolic name of the interrupt type.
|
|
|
|
This restriction applies only to interrupt *names*. The value associated with the interrupt name (as defined in _platform_conf.h_) can vary from platform to platform, as long as
|
|
it follows the rules outlined in step 1 above.
|
|
|
|
The table below lists all the valid interrupt names currently known to eLua. If you add a new interrupt don't forget to update the table below.
|
|
|
|
[width="70%", cols="<2s,<5", options="header"]
|
|
|===================================================================
|
|
^| Name ^| Meaning
|
|
| INT_GPIO_POSEDGE | Interrupt on a positive edge on a GPIO pin
|
|
| INT_GPIO_NEGEDGE | Interrupt on a negative edge on a GPIO pin
|
|
| INT_TMR_MATCH | Interrupt on timer match
|
|
| INT_UART_RX | Interrupt on UART character received
|
|
|===================================================================
|
|
|
|
// $$FOOTER$$
|
|
|