beautypg.com

Parameterized ucb callout, Parameterized ucb callout -38 – National Instruments AutoCode NI MATRIX User Manual

Page 146

background image

Chapter 5

Generated Code Architecture

AutoCode Reference

5-38

ni.com

Parameterized UCB Callout

A UCB can be defined with %var parameterized data for the UCB’s real
parameters (

RP

) and integer parameters (

IP

). When used, AutoCode

generates code that passes the %var variable as the actual of the UCB
callout. A new option,

-ucbparams

, creates a temporary array within the

subsystem code and passes the temporary arrays as actuals of the UCB
callout. The temporary arrays are initialized with the values of the %var
when the code was generated. Using the temporary arrays allows the UCB
to change its

RP

/

IP

parameters without affecting the %var.

Example 5-18 clarifies this. Assume a UCB is parameterized with the %var
named

floatdata

for the UCB’s real parameters and the %var named

integerdata

for the UCB’s integer parameters.

Example 5-18

Relevant Code for UCB Call

/*-------------------------------------*/

/* USRxx(INFO,T,U,NU,X,XDOT,NX,Y,NY,RP,IP) */

usr01(&I->usr01_13_i, TIME, &usr01_13_u[0], 1, &dummp_f[0],

&dummy_f[0], 0, &usr01_13_y[0], 1, &floatdata[0],

&integerdata[0]);

/*-------------------------------------*/

Relevant code for UCB call with -ucbparams option

/*------------------------------------------------------------*/

static RT_INTEGER I_P[4];

static RT_FLOAT R_P[3];

static const RT_INTEGER _I_P[4] = {3, 5, 30, 40};

static const RT_FLOAT _R_P[3] = {2.05, 3.45, 7.63};

if (SUBSYS_PREINIT[1]) {

for( cnt=0;cnt<4;cnt++) {

I_P[cnt] = _I_P[cnt];

}

for( cnt=0;cnt<3;cnt++) {

R_P[cnt] = _R_P[cnt];

}

}

/* USRxx(INFO,T,U,NU,X,XDOT,NX,Y,NY,RP,IP)*/

usr01(&I->usr01_13_i, TIME, &usr01_13_u[0], 1, &dummp_f[0], &dummy_f[0],

0, &usr01_13_y[0], 1, &R_P[0], &I_P[0]);

/*------------------------------------------------------------*/