National Instruments AutoCode NI MATRIX User Manual

Page 31

Advertising
background image

Chapter 2

C Language Reference

AutoCode Reference

2-14

ni.com

The operations within UCBs are controlled by the argument

INFO

, a pointer

to a structure of type

STATUS_RECORD

that is passed as part of the

argument list for each UCB (located in

sa_types

):

typedef struct STATUS_RECORD

{

RT_INTEGER ERROR;

RT_BOOLEAN INIT;

RT_BOOLEAN STATES;

RT_BOOLEAN OUTPUT;

}

RT_STATUS_RECORD;

The following example shows the general form of UCB equations for
AutoCode and indicates how the

INFO

status record pointer is used to

control the computations.

if (INFO->INIT) {

/* do user code initialization */

INFO->INIT = 0;

}

if (INFO->OUTPUTS) {

/* do output calculations having the general form:

Y = H(T,X,XD,U,RP,IP); */

}

if (INFO->STATES) {

/* do state update calculation with the general form:

XD = F(T,X,XD,U,RP,IP); */

}

When an error occurs within the UCB, set

INFO->ERROR

equal to some

nonzero integer value as an error return. Also, make sure that

INFO->INIT

is set to FALSE (0) at the end of the initialization cycle.

The process of linking handwritten UCBs (in

usr_dsp.c

) with an

AutoCode application (in

dsp.c

) is depicted in Figure 2-2. The

SystemBuild model in Figure 2-2 depicts the filter described by the
difference equation:

y(k) = –1/2 * y(k – 2) + 3 * u(k) + u(k – 2)

The UserCode Block provides the interface to the handwritten function

usr_dsp( )

implemented in the file

usr_dsp.c

. The

usr_dsp( )

function essentially implements the behavior of the same filter.

Advertising