<< C/C++ code integration C/C++ code integration Custom 'My step' Xcos block for MicroDAQ >>

MicroDAQ toolbox >> MicroDAQ toolbox > C/C++ code integration > Introduction

Introduction

C/C++ code integration tools introduction

MicroDAQ toolbox for Scilab allows easy integration of legacy or custom C/C++ code making Xcos model creation more flexible. User can automatically generate Xcos blocks which executes custom C/C++ code. Moreover block code can be debugged with Code Composer Studio like during normal DSP application development. User can optimize some parts of Xcos model by repleacing Xcos standard block with custom block which contains optimized C code for faster execution. Especially C/C++ programmers will benefit from code integration tools giving easy way to write custom Xcos block which sometimes is easer then making it with standard Xcos blocks. Together with 'Execution profiling' feature which allows precisly determine model execution times code integration tools can be used creating high performance real-time control and measurement applications.

Examples

// call mdaqBlock to initialize block structure describing new MicroDAQ block		
block = mdaqBlock();
block.name = "test"; // set block name 
block.param_name = [ "param1" "param2" "param3" ]; // set block parameters
block.param_size = [ 1 2 4 ]; // set block parameters sizes
block.param_def_val(1) = 1;  // assign default values to defined block parameters according to block.param_size
block.param_def_val(2) = [ 2; 3 ]; 
block.param_def_val(3) = [ 4; 5; 6; 7 ]; 

// define block inputs (four inputs: input 1 - vec size 1, input 2 - vec size 2, input 3 - vec size 4, input 4 - vec size 1)
block.in = [1 2 4 1];

// define block outputs (two outputs both with vector size 1)
block.in = [1 1];

// create block - generate block code and corresponding C source file
mdaqBlockAdd(block);

Generated C code

/* Generated with MicroDAQ toolbox ver: 1.0. */
#include "scicos_block4.h"

extern double get_scicos_time( void );

/* This function will executed once at the beginning of model execution */
static void init(scicos_block *block)
{
    /* Block parameters */
    double *params = GetRparPtrs(block);

    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Add block init code here */
}

/* This function will be executed on every model step */
static void inout(scicos_block *block)
{
    /* Block parameters */
    double *params = GetRparPtrs(block);
    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Block input ports */
    double *u1 = GetRealInPortPtrs(block,1);
    int u1_size = GetInPortRows(block,1);    /* u1_size = 1 */

    double *u2 = GetRealInPortPtrs(block,2);
    int u2_size = GetInPortRows(block,2);    /* u2_size = 1 */

    /* Block output ports */
    double *y1 = GetRealOutPortPtrs(block,1);
    int y1_size = GetOutPortRows(block,1);    /* y1_size = 1 */

    /* Add block code here (executed every model step) */

}

/* This function will be executed once at the end of model execution (only in Ext mode) */
static void end(scicos_block *block)
{
    /* Prameters */
    double *params = GetRparPtrs(block);

    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Add block end code here */
}

void mdaq_test(scicos_block *block,int flag)
{
    if (flag == 1){            /* set output */
        inout(block);
    }
    else if (flag == 5){       /* termination */
        end(block);
    }
    else if (flag == 4){       /* initialisation */
        init(block);
    }
}

See Also


Report an issue
<< C/C++ code integration C/C++ code integration Custom 'My step' Xcos block for MicroDAQ >>