Embedding a scripting engine ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Embedding a scripting engine ?

530 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Leji on Mon May 14 01:35:30 MST 2012
Hi,

I would like to embed some level of scripting functionality in my application to allow users some simple/fast customizations (for example, toggle a GPIO each time an I2C transaction is detected, or repeat a pattern of GPIOs toggling...)

I don't need a fully featured language, just something with IF, FOR and  the ability to call native functions (for I2C, SPI etc...)

The only valid candidate I found until now is http://www.compuphase.com/pawn/pawn.htm
Did anyone use it on an LPC ?
Is anyone using something else ?

Thanks for any suggestions,

Thibaut
0 Kudos
Reply
4 Replies

459 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Leji on Tue May 15 02:04:32 MST 2012
In case anyone's interesting, I chose Pawn (picoc was not as easy to port & use, Pawn has nice documentation + IDE), which compiled quite easily.

To use it, I:
- imported amx, amxaux, amxcore and osdefs
- build with AMX_NOPROPLIST and NDEBUG symbols (as a static lib)
- Write a script in Quincy (Pawn IDE), build and dump the outputed amx file somewhere in LPC memory
- In my LPC main application (bulkData is the address of the script):
        AMX amx;
        cell ret =0;
        int result = 0;
        memset(&amx, 0, sizeof(amx));

        result = amx_Init(&amx,bulkData);
        if (result != 0)
        {
            // handle error
        }
        result = amx_NativeInit(&amx);
        if (result != 0)
        {
            // handle error
        }

        result = amx_Exec(&amx,&ret,AMX_EXEC_MAIN);
        if (result != 0)
            // handle error
        else
        {
// handle success !
// return ret
        }
where amx_NativeInit is the function that initializes external functions calls, like:
static cell amx_toggle_GPIO(AMX *amx, const cell *params)
{
    /* params[1] = port
     * params[2] = pin
     * params[3] = value
     */
    LPC_GPIO[params[1]]->FIODIR |= 1<<params[2];
    if (params[3] == 0)
        LPC_GPIO[params[1]]->FIOCLR |= 1<<params[2];
    else
        LPC_GPIO[params[1]]->FIOSET |= 1<<params[2];

    return SUCCESS;
}

int amx_NativeInit(AMX *amx)
{
    static AMX_NATIVE_INFO nativesFcn[]=
    {
        {"toggleGPIO", amx_toggle_GPIO},
        {0,0} /* terminator */
    };

    return amx_Register(amx, nativesFcn, -1);
}
0 Kudos
Reply

459 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Leji on Mon May 14 02:38:09 MST 2012
picoc looks interesting, I'll try it.

I'm not using an OS at the moment, so the effort of porting my application to freeRTOS would be quite big just to get scripting :)
0 Kudos
Reply

459 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Mon May 14 02:05:37 MST 2012
Hi Thibaut,

if you are using FreeRTOS you can use CLI for free:
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/FreeRTOS_Plus_Command_Line_Interface.shtml
0 Kudos
Reply

459 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon May 14 02:03:03 MST 2012
Did you look at picoc?
http://code.google.com/p/picoc/
0 Kudos
Reply