National Instruments AutoCode NI MATRIX Reference - Introduction

Manual is about: National Instruments NI MATRIXx Reference Manual

Summary of AutoCode NI MATRIX

  • Page 1

    Ni matrixx tm autocode tm reference autocode reference april 2007 370768c-01.

  • Page 2

    Support worldwide technical support and product information ni.Com national instruments corporate headquarters 11500 north mopac expressway austin, texas 78759-3504 usa tel: 512 683 0100 worldwide offices australia 1800 300 800, austria 43 662 457990-0, belgium 32 (0) 2 757 0020, brazil 55 11 3262 3...

  • Page 3: Important Information

    Important information warranty the media on which you receive national instruments software are warranted not to fail to execute programming instructions, due to defects in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. Nati...

  • Page 4: Conventions

    Conventions the following conventions are used in this manual: angle brackets that contain numbers separated by an ellipsis represent a range of values associated with a bit or signal name—for example, dio. » the » symbol leads you through nested menu items and dialog box options to a final action. ...

  • Page 5: Contents

    © national instruments corporation v autocode reference contents chapter 1 introduction manual organization .....................................................................................................1-1 general information.......................................................................

  • Page 6

    Contents autocode reference vi ni.Com linking procedures with real-time applications or simulator .................... 2-22 invoking generated procedures directly.......................................... 2-22 invoking procedures using generated ucb wrapper function...... 2-24 invoking procedures us...

  • Page 7

    Contents © national instruments corporation vii autocode reference external_input ( ) procedure.............................................................3-10 external_output( ) procedure ...........................................................3-11 usercode blocks .................................

  • Page 8

    Contents autocode reference viii ni.Com chapter 4 generating code for real-time operating systems real-time operating system configuration file.......................................................... 4-1 configuration items .............................................................................

  • Page 9

    Contents © national instruments corporation ix autocode reference system external interface layer .....................................................................5-7 discrete subsystem interface layer ................................................................5-8 single-rate system ..........

  • Page 10

    Contents autocode reference x ni.Com states ............................................................................................................... 5-26 local variables and phases .............................................................. 5-27 discrete semantics ............................

  • Page 11

    Contents © national instruments corporation xi autocode reference definitions and conventions ...........................................................................5-45 shared memory fixed-point callouts in autocode/c .....................5-46 shared variable block support ........................

  • Page 12

    Contents autocode reference xii ni.Com chapter 7 code optimization read from variable blocks ........................................................................................... 7-1 restart capability ...............................................................................................

  • Page 13

    Contents © national instruments corporation xiii autocode reference variable block aliasing....................................................................9-4 monitored signals within a procedure superblock ..........................9-4 monitoring procedure external outputs ........................

  • Page 14: Introduction

    © national instruments corporation 1-1 autocode reference 1 introduction this manual provides reference material for using autocode to write production quality code using graphical tools. Together with the autocode user guide and the template programming language user guide , autocode documentation ...

  • Page 15: General Information

    Chapter 1 introduction autocode reference 1-2 ni.Com • chapter 8, autocode sim cdelay scheduler , discusses the sim cdelay low-latency scheduler. • chapter 9, global scope signals and parameterless procedures , discusses additional signals and procedures. This guide also has an index . General infor...

  • Page 16: Using Matrixx Help

    Chapter 1 introduction © national instruments corporation 1-3 autocode reference structure and content of the generated code this reference includes detailed descriptions about what is generated for many of the blocks used within a model. Also, the framework of the generated code is discussed to sho...

  • Page 17: Related Publications

    Chapter 1 introduction autocode reference 1-4 ni.Com related publications national instruments provides a complete library of publications to support its products. In addition to this guide, publications that you may find particularly useful when using autocode include the following: • autocode user...

  • Page 18: C Language Reference

    © national instruments corporation 2-1 autocode reference 2 c language reference this chapter discusses files used to interface autocode and the generated c code to your specific platform and target processor. This chapter also describes target-specific utilities needed for simulation and testing. S...

  • Page 19: Stand-Alone Library

    Chapter 2 c language reference autocode reference 2-2 ni.Com stand-alone library this section describes the system-specific and target-specific stand-alone ( sa ) files supplied with your system. System-specific files national instruments furnishes files to interface autocode and the generated code ...

  • Page 20

    Chapter 2 c language reference © national instruments corporation 2-3 autocode reference • the principal file is sa_utils.C , the stand-alone utilities file. At the time that you compile sa_utils.C and your generated code program, you must make the following header files available locally: sa_sys.H ...

  • Page 21

    Chapter 2 c language reference autocode reference 2-4 ni.Com data types several of the target-specific utilities are involved with data types (in the sa_types.H file). The three following data types are defined for the c code generator: rt_float corresponds to c type double or float, depending on yo...

  • Page 22

    Chapter 2 c language reference © national instruments corporation 2-5 autocode reference to. For example, rt_integer can be redefined as long int if arithmetic overflow becomes a problem on a given platform. Target-specific utilities target-specific utilities (in sa_utils.C ) perform hardware, appli...

  • Page 23

    Chapter 2 c language reference autocode reference 2-6 ni.Com the sa_utils.C file contains comments about each of the routines as they are used for comparing simulation with generated code results. After you generate code, link the generated code with sa_*.O object files (refer to chapter 2, using au...

  • Page 24

    Chapter 2 c language reference © national instruments corporation 2-7 autocode reference two error functions are provided, fatalerr( ) and error( ) . The fatalerr( ) function reports exception conditions detected by the functions in the sa_utils.C file. Error( ) reports conditions detected by the ge...

  • Page 25

    Chapter 2 c language reference autocode reference 2-8 ni.Com the comments there and adjust the limits accordingly, then recompile and relink the sa_utils.C file. Error opening the input file error opening the output file a problem was encountered opening the input or output file. Possible causes inc...

  • Page 26

    Chapter 2 c language reference © national instruments corporation 2-9 autocode reference implementation_initialize( ) function void implementation_initialize (rt_float *bus_in rt_integer, ni, rt_float bus_out, rt_integer no, rt_float scheduler_freq); in the default version of sa_utils.C (simulation ...

  • Page 27: Usercode Blocks

    Chapter 2 c language reference autocode reference 2-10 ni.Com external_input ( ) function rt_integer external_input(void) external_input( ) is for use in the simulation comparison mode; it reads in external input data from your specified fsave input file. The data appears in xinput , an array of typ...

  • Page 28

    Chapter 2 c language reference © national instruments corporation 2-11 autocode reference linking handwritten ucbs with autocode applications to write code for usercode blocks (ucbs), refer to the sa_user.C file, which is provided in your src distribution directory. The sa_user.C file contains an ex...

  • Page 29

    Chapter 2 c language reference autocode reference 2-12 ni.Com figure 2-1. Example usercode function file (sa_user.C) the $ucb directive is recognized and interpreted by the automatic linking facility of the simulator in systembuild to distinguish between ucbs written for simulation purposes using sy...

  • Page 30

    Chapter 2 c language reference © national instruments corporation 2-13 autocode reference implementing handwritten ucbs arguments are passed for each call to the ucb in the following order: info, t, u, nu, x, xdot, nx, y, ny, r_p, and i_p pointers to all of the arrays ( u , x , xd , y , r_p , i_p ) ...

  • Page 31

    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 err...

  • Page 32

    Chapter 2 c language reference © national instruments corporation 2-15 autocode reference figure 2-2. Linking handwritten ucbs with autocode applications generate autocode application dsp . C usr_dsp.C (handwritten ucb using sa_user . C example) compile and link file name: usr_dsp.C y (k) = -1/2*y(k...

  • Page 33

    Chapter 2 c language reference autocode reference 2-16 ni.Com linking handwritten ucbs (for autocode) with systembuild after you have written a ucb to create an autocode application, you can use the same ucb for simulation. Systembuild can automatically compile and link your usercode function into t...

  • Page 34

    Chapter 2 c language reference © national instruments corporation 2-17 autocode reference figure 2-3. Linking handwritten ucbs with the systembuild simulator the arguments to a ucb written only for linking with the systembuild simulator (using usr01.C ) are inherently different than the arguments to...

  • Page 35

    Chapter 2 c language reference autocode reference 2-18 ni.Com applications, make sure you adapt the same algorithm in the body of a function using the autocode ucb arguments as in sa_user.C . Variable interface ucb the preceding sections described the fixed interface; however, a ucb can also use the...

  • Page 36

    Chapter 2 c language reference © national instruments corporation 2-19 autocode reference as previously stated, the inputs and outputs of the ucb will have the same data type as specified in the model diagram. Inputs are passed by value while outputs are passed by reference. In addition, the “shape”...

  • Page 37: Procedure Superblocks

    Chapter 2 c language reference autocode reference 2-20 ni.Com linking a variable interface ucb with the simulator unlike the fixed interface which provides an automatic method for linking with the simulator, the variable interface is too complicated for that method. As a result, you are required to ...

  • Page 38

    Chapter 2 c language reference © national instruments corporation 2-21 autocode reference proc_ucb_hook . Refer to the template programming language user guide . Figure 2-4. Linking generated reusable procedures procedure generate reusable procedure filename: myproc.C function name: simexe.Lnx mypro...

  • Page 39

    Chapter 2 c language reference autocode reference 2-22 ni.Com linking procedures with real-time applications or simulator generate reusable procedures from your procedure superblocks as described in this chapter and in chapter 3, ada language reference . To link generated reusable procedures with yo...

  • Page 40

    Chapter 2 c language reference © national instruments corporation 2-23 autocode reference 3. Create an object of type _ procedure name _s where the states of the procedure will be stored and initialize all members of the object to 0.0. This should be done during initialization only. A pointer to thi...

  • Page 41

    Chapter 2 c language reference autocode reference 2-24 ni.Com point to the appropriate global variables. A pointer to this object will be passed as argument i to the procedure. 5. Invoke the procedure using pointers to the objects created in steps 1 through 4. 6. Toggle the state flag of the states ...

  • Page 42

    Chapter 2 c language reference © national instruments corporation 2-25 autocode reference properly. Refer to the systembuild user guide for an explanation of rinfo . Only the first four elements of this array will be used by the generated procedure. This array will be passed as argument rinfo . 3. C...

  • Page 43: C Fixed-Point Arithmetic

    Chapter 2 c language reference autocode reference 2-26 ni.Com data-typed variables reflecting each subsystem input signal and type. The outputs to the subsystem are provided by the argument y , a pointer to a structure named _subsys_ number _out . This structure has mixed data-typed variables reflec...

  • Page 44

    Chapter 2 c language reference © national instruments corporation 2-27 autocode reference number—for each integer item and the sign are managed by the code generator. Arithmetic expressions are scaled to emulate a fixed-point capability, and all expressions involving the item are coded to be consist...

  • Page 45

    Chapter 2 c language reference autocode reference 2-28 ni.Com language and replace the supplied macros (or functions) with your (assembly) functions so that you can take full advantage of the processor’s arithmetic capabilities. Generated code with fixed-point variables code generated for models usi...

  • Page 46

    Chapter 2 c language reference © national instruments corporation 2-29 autocode reference a typical fixed-point type looks like the following: rt_ushort06 where ushort stands for unsigned short, and 06 indicates the radix position. Fixed-point variables that are always positive in nature can be decl...

  • Page 47

    Chapter 2 c language reference autocode reference 2-30 ni.Com rt_sshort05 ss5; rt_sshort ss0; rt_sshort05 ss5_1; }; struct _sys_extin { rt_ushort13 us13; rt_sshort14 ss14; }; /******* system ext i/o type definitions. *******/ struct _subsys_1_out subsys_1_out; struct _sys_extin sys_extin; static rt_...

  • Page 48

    Chapter 2 c language reference © national instruments corporation 2-31 autocode reference the uts appear as typedef statements in the generated c code. For example: typedef volts rt_sbyte03; this code defines the data type called volts to be a signed byte with radix position 3. Overflow protection o...

  • Page 49

    Chapter 2 c language reference autocode reference 2-32 ni.Com macro interface the macro interface files are: sa_types.H updated to include fixed-point types. Sa_fx.H contains fixed-point conversion macros. Sa_fxp.H contains fixed-point conversion macros with overflow protection. Sa_fxr.H contains fi...

  • Page 50

    Chapter 2 c language reference © national instruments corporation 2-33 autocode reference sa_fx_externs.C contains definitions for extern variables such as mask buffers that are read only. Function interface the function interface files are: sa_types.H updated to include fixed-point types. Sa_fxp.H ...

  • Page 51

    Chapter 2 c language reference autocode reference 2-34 ni.Com sa_fxsub_byte.C contains fixed-point subtraction functions for byte data type. Sa_fxsub_short.C contains fixed-point subtraction functions for short data type. Sa_fxsub_long.C contains fixed-point subtraction functions for long data type....

  • Page 52

    Chapter 2 c language reference © national instruments corporation 2-35 autocode reference fixed-point conversion and arithmetic macros although this section explains different fixed-point operations in terms of macros, all of these operations are supported as functions in the function interface. Hen...

  • Page 53

    Chapter 2 c language reference autocode reference 2-36 ni.Com figures 2-6 through 2-8 show how the conversion macros are named. Notice that macro names have no embedded spaces. Figure 2-6. Autocode/c conversion macros for fixed-to-fixed conversions for example, the macro to convert an unsigned 8-bit...

  • Page 54

    Chapter 2 c language reference © national instruments corporation 2-37 autocode reference figure 2-7. Autocode/c conversion macros for fixed-to-integer conversions for example, the macro to convert an unsigned 8-bit number to an integer number with a shift of rp bits, and with overflow protection is...

  • Page 55

    Chapter 2 c language reference autocode reference 2-38 ni.Com arithmetic macros the arithmetic macros perform addition, subtraction, multiplication, and division. The top level macros for arithmetic operations are present in the sa_fxm.H and sa_fxmp.H files. These macros in turn call the align macro...

  • Page 56

    Chapter 2 c language reference © national instruments corporation 2-39 autocode reference table 2-7 shows permissible operand and result sizes for the arithmetic macros. For example, the macro to add two 8-bit unsigned numbers with overflow protection and produce an unsigned 8-bit result is: ubadd_u...

  • Page 57

    Chapter 2 c language reference autocode reference 2-40 ni.Com implementation of the addition and subtraction macros autocode has two implementations of the addition and subtraction macros: • macros that apply wordsize extension (also called extended intermediate types) to the two operands before ali...

  • Page 58

    Chapter 2 c language reference © national instruments corporation 2-41 autocode reference align the radix positions of n1 and n2 to the radix position of the result before subtracting (that is, shift n1 left by three bits, and shift n2 left by two bits). Place the aligned results in n1' and n2' and ...

  • Page 59

    Chapter 2 c language reference autocode reference 2-42 ni.Com 0^1111111 (n2' = (127,r7) , decimal value = .9921875) ___________ 0^0000000 (n3 = (0,r7) , decimal value = 0.0) in example 2-3, method 1 is more accurate than method 2, but it is also less efficient because it involves a 16-bit subtractio...

  • Page 60

    Chapter 2 c language reference © national instruments corporation 2-43 autocode reference the maximum possible value representable in 32 bits—is returned. This multiplication process can be expensive because it involves several multiplication and addition operations to produce an intermediate result...

  • Page 61

    Chapter 2 c language reference autocode reference 2-44 ni.Com in terms of speed, but is needed to compute an accurate result. By changing this behavior, you can speed up the operation if you are willing to give up some accuracy. Note for more information on the implementation of multiplication and d...

  • Page 62

    Chapter 2 c language reference © national instruments corporation 2-45 autocode reference for example, the macro to check an 8-bit unsigned number and an 8-bit signed number for equality and produce a boolean result is: booleq_ub_sb(n1,n2,rp1,rp2) some relevant issues • the fixed-point macros used b...

  • Page 63: Ada Language Reference

    © national instruments corporation 3-1 autocode reference 3 ada language reference this chapter discusses files used to interface autocode and the generated ada code to your specific platform and target processor. This chapter also discusses target-specific utilities needed for simulation and testin...

  • Page 64: Supplied Templates

    Chapter 3 ada language reference autocode reference 3-2 ni.Com supplied templates ada_rt.Tpl template the ada_rt.Tpl template is the default when generating ada code. This template uses ada tasks to implement the scheduling mechanism for the model. This template supports fixed-point arithmetic. Ada_...

  • Page 65: Stand-Alone Library

    Chapter 3 ada language reference © national instruments corporation 3-3 autocode reference stand-alone library this section describes the system-specific and target-specific stand-alone ( sa_* ) files supplied with your system. System-specific files header and source files are supplied to interface ...

  • Page 66

    Chapter 3 ada language reference autocode reference 3-4 ni.Com • the principal file is sa_utils.A (or sa_utils.Ada ), the stand-alone utilities file. When you compile sa_utils.A/.Ada , you must make the following files from the source distribution directory available locally: – sa_utils_.A/.Adasa_ut...

  • Page 67

    Chapter 3 ada language reference © national instruments corporation 3-5 autocode reference floating-point math_lib . The sa_time.A/.Ada file provides the elapsed_time_of( ) function. The purposes of the more important specification files are listed in table 3-3. . Data types several of the target-sp...

  • Page 68

    Chapter 3 ada language reference autocode reference 3-6 ni.Com target-specific utilities the target-specific utilities in the sa_utils.A or sa_utils.Ada file perform hardware-, application-, and ada-specific tasks that are required for simulation and testing. They can be modified to support the gene...

  • Page 69

    Chapter 3 ada language reference © national instruments corporation 3-7 autocode reference the sa_utils.A or sa_utils.Ada file contains comments about each of the routines as they are used for comparing simulation with generated code results. Enable( ), disable( ), and background( ) procedures enabl...

  • Page 70

    Chapter 3 ada language reference autocode reference 3-8 ni.Com refer to the chapter 14, usercode blocks , of the systembuild user guide or the source listing of the usr01 routine for meanings of ucb errors. You are allowed to extend the scope of these messages, so it might be one of yours. Unknown e...

  • Page 71

    Chapter 3 ada language reference © national instruments corporation 3-9 autocode reference by default, several error conditions are trapped in the procedure implementation_initialize of sa_utils.A/.Ada , but you can expand this capability in your own versions of the program, detecting your own error...

  • Page 72

    Chapter 3 ada language reference autocode reference 3-10 ni.Com these messages indicate that the sizes of the time vector and input array have exceeded one or more of the storage allocation size limits established by sa_utils.A/.Ada . These limits are established as constants at the very beginning o...

  • Page 73: Usercode Blocks

    Chapter 3 ada language reference © national instruments corporation 3-11 autocode reference external_input( ) is much the same; it returns an input vector from the software data bus. External_input( ) returns the value of scheduler_status , which is passed to it by the scheduler. External_output( ) ...

  • Page 74

    Chapter 3 ada language reference autocode reference 3-12 ni.Com calling ucbs every one of the following arguments will be passed for each call to the ucb in the following order: info, t, u, nu, x, xd, nx, y, ny, r_p, i_p within the ucb, the elements of all the array variables ( u , x , xd , y , r_p ...

  • Page 75

    Chapter 3 ada language reference © national instruments corporation 3-13 autocode reference the operations within ucbs are controlled by the info argument, a record of rt_status_record type that is passed as part of the argument list for each ucb: type rt_status_record is record error: rt_integer; i...

  • Page 76: Procedure Superblocks

    Chapter 3 ada language reference autocode reference 3-14 ni.Com procedure superblocks this section describes how to generate and link procedure superblocks. Generating reusable procedures generate reusable procedures from your procedure superblocks as described in chapter 2, using autocode , of the ...

  • Page 77

    Chapter 3 ada language reference © national instruments corporation 3-15 autocode reference ----------------------------------------------------------------------- -- wrapper around the procedure to support ucb (fixed calltype) interface -- this routine can be called as a ucb either from systembuild...

  • Page 78: Ada Fixed-Point Arithmetic

    Chapter 3 ada language reference autocode reference 3-16 ni.Com ada fixed-point arithmetic this section describes the implementation of fixed-point arithmetic in autocode/ada. It is assumed that you are familiar with the ada programming language. Note the systembuild user guide has a fixed-point ari...

  • Page 79

    Chapter 3 ada language reference © national instruments corporation 3-17 autocode reference fixed-point data types fixed-point type declarations exist in the file named: sa_fxptypes_.A and is provided in the system-specific files src (source) directory. 1 this file contains the specification of the ...

  • Page 80

    Chapter 3 ada language reference autocode reference 3-18 ni.Com package dependencies the fixed-point autocode/ada architecture forces a dependency among the supplied and generated code for a model that uses any fixed-point types. This dependency affects compilation order within an ada library. Figur...

  • Page 81

    Chapter 3 ada language reference © national instruments corporation 3-19 autocode reference generated code with fixed-point variables fixed-point arithmetic operations are accomplished by overloading the standard arithmetic operators for the fixed-point types. Therefore, the generated code with fixe...

  • Page 82

    Chapter 3 ada language reference autocode reference 3-20 ni.Com system-level parameters to generate user types table 3-6 describes new system-level parameters that are used to generate the user_types package. Overflow protection overflow is defined as loss of significance—that is, a computation resu...

  • Page 83

    Chapter 3 ada language reference © national instruments corporation 3-21 autocode reference frequently overflowing, a different data type should be selected. If you are concerned about performance and the use of an exception handler for detecting overflow, the generic functions can be changed. These...

  • Page 84

    Chapter 3 ada language reference autocode reference 3-22 ni.Com 1. Build a model —use the superblock editor to construct a model that uses fixed-point types for input/output signals. Refer to the systembuild user guide for more information. 2. Generate real-time code —from the systembuild pull-down ...

  • Page 85

    Chapter 3 ada language reference © national instruments corporation 3-23 autocode reference 4. Compile the generated files —two source files are generated, gaintest.A and fxp_gaintest_.A , as shown in figure 3-1. The imposed package dependencies (refer to the package dependencies section) require th...

  • Page 86

    Chapter 3 ada language reference autocode reference 3-24 ni.Com table 3-9. Generic function summary function name purpose fixed_add addition of two fixed-point values. Fixed_sub subtraction of two fixed-point values. Fixed_mul multiplication of two fixed-point values. Fixed_div division of two fixed...

  • Page 87

    Chapter 3 ada language reference © national instruments corporation 3-25 autocode reference longintcast fixed-point value to rt_long_integer conversion. Longintcast_trunc fixed-point value to rt_long_integer conversion using truncation. Longintcast_round fixed-point value to rt_long_integer conversi...

  • Page 88

    Chapter 3 ada language reference autocode reference 3-26 ni.Com bit-wise functions a restricted set of bit-wise operations have been defined for certain fixed-point types. These functions exist in the sa_fixed_bitwise_functions package found in the sa_fxpbit_.A and sa_fxpbit.A files. The set of bit-...

  • Page 89

    Chapter 3 ada language reference © national instruments corporation 3-27 autocode reference conversion function instantiations the rt_fixed_operators package contains instantiations of functions that represent conversion of values to and from a fixed-point type. The appropriate generic function from...

  • Page 90

    Chapter 3 ada language reference autocode reference 3-28 ni.Com sample package example 3-3 shows a generated rt_fixed_operators package. Example 3-3 generated rt_fixed_operators package --------------------------------------------------------------------------- -- autocode/ada (tm) code generator 7....

  • Page 91

    Chapter 3 ada language reference © national instruments corporation 3-29 autocode reference function “>=” is new sa_fixed_generics.Greaterequal(sa_fixed.Rt_sshort14, sa_fixed.Rt_sshort08); --pragma inline (">="); function ">=" (left, right : sa_fixed.Rt_sshort13) return boolean renames sa_fixed.">="...

  • Page 92

    Chapter 3 ada language reference autocode reference 3-30 ni.Com the selection of the intermediate type is performed by the code generator. The selection involves a set of rules that rely upon word size extension. Word size extension is selecting a fixed-point type with a larger number of bits that c...

  • Page 93

    Chapter 3 ada language reference © national instruments corporation 3-31 autocode reference multiplication and division functions the predefined multiplication and division operators for fixed-point type based arguments are defined in ada for any combination of fixed-point arguments. The result of t...

  • Page 94

    Chapter 3 ada language reference autocode reference 3-32 ni.Com no chance of overflow. To support these issues there are three types of conversion functions: • language-defined conversion • truncation conversion • explicit rounding conversion these conversions are described in the following sections...

  • Page 95

    Chapter 3 ada language reference © national instruments corporation 3-33 autocode reference for these types of conversions, the language-defined conversion is used. In general, when an explicit conversion is required and there is no specification of which to choose, autocode/ada will select the expl...

  • Page 96

    Chapter 3 ada language reference autocode reference 3-34 ni.Com the data in the sp_fxp parameters represent the operators and conversion used in the currently scoped subsystem or procedure. No assumptions can be made about the order within a given list parameter. However, the n th element in one lis...

  • Page 97

    Chapter 3 ada language reference © national instruments corporation 3-35 autocode reference known ada compiler problems the architecture of autocode/ada fixed-point heavily relies upon overloaded operators and generic function instantiation. For a large and complex model, the number of overloads and...

  • Page 98

    Chapter 3 ada language reference autocode reference 3-36 ni.Com • floating-point textual representation —the values generated from a stand-alone simulation are converted to a textual (ascii) representation. That representation in textual form might not quite be as accurate as possible. That is, the ...

  • Page 99

    Chapter 3 ada language reference © national instruments corporation 3-37 autocode reference example 3-6 example code causing ambiguous selection of overloaded operators function "*" (left:sb0; right:sb1) return sl0; function "*" (left:sb0; right:sb1) return ss0; function "*" (left:sl0; right:sl0) re...

  • Page 100: Operating Systems

    © national instruments corporation 4-1 autocode reference 4 generating code for real-time operating systems this chapter describes the rtos configuration file and functionality provided for generating code for real-time operating systems. Real-time operating system configuration file code that is to...

  • Page 101

    Chapter 4 generating code for real-time operating systems autocode reference 4-2 ni.Com configuration items the following is a list of configuration attributes for each type of autocode component. • number of processors • scheduler priority • subsystem tasks – priority – stack size – processor – mod...

  • Page 102

    Chapter 4 generating code for real-time operating systems © national instruments corporation 4-3 autocode reference table naming convention tables are given a name to identify the contents of the data contained therein. Table names are specified in the same form as xmath variables, partition.Name . ...

  • Page 103

    Chapter 4 generating code for real-time operating systems autocode reference 4-4 ni.Com example 4-1 processors table example rtos.Processors = 2 scheduler priority table table 4-2 is a single element table consisting of the priority assigned to the scheduler task. The table is named: scheduler_prior...

  • Page 106

    Chapter 4 generating code for real-time operating systems © national instruments corporation 4-7 autocode reference startup procedure superblock table table 4-6 consists of configuration information for all startup procedure superblocks in the model. Each row is identified by the name of the superbl...

  • Page 108

    Chapter 4 generating code for real-time operating systems © national instruments corporation 4-9 autocode reference configuration file is updated. Also, the updated configuration file is stored in the same directory where the generated code is placed. Refer to the -o option. Caution comments are not...

  • Page 109: Generated Code Architecture

    © national instruments corporation 5-1 autocode reference 5 generated code architecture this chapter supplies more details about the content and framework of the generated code. This includes storage usage, various procedures, specialized blocks, and subsystems. This chapter is directed toward someo...

  • Page 110

    Chapter 5 generated code architecture autocode reference 5-2 ni.Com signal naming a signal in the diagram is represented as a variable in the generated code. Within the diagram, signals can have two names: a label and a name . The signal’s label can appear in the diagram while a signal’s name does n...

  • Page 111: Global Storage

    Chapter 5 generated code architecture © national instruments corporation 5-3 autocode reference global storage in a strict modular programming paradigm, global storage is strictly avoided. However, global storage can be used safely and provides significant benefits in terms of code size and speed. T...

  • Page 112

    Chapter 5 generated code architecture autocode reference 5-4 ni.Com • write-to variable block (all addressing mode) —these blocks execute after all other types of blocks within the subsystem, procedure or sequence frame. • read-from/write-to variable block (element/bit addressing modes) —these varia...

  • Page 113: Subsystems

    Chapter 5 generated code architecture © national instruments corporation 5-5 autocode reference subsystems this section describes the design and operation of subsystems. This includes: • discrete and continuous superblocks versus subsystems • block ordering • interface layers • scheduler external in...

  • Page 114

    Chapter 5 generated code architecture autocode reference 5-6 ni.Com top-level superblock the term top-level superblock is often used. This term describes the superblock that was the root of the analyzer’s processing of the superblock hierarchy into subsystems, that is, a starting point for the trans...

  • Page 115

    Chapter 5 generated code architecture © national instruments corporation 5-7 autocode reference figure 5-1 illustrates the interface layers. The layers are described in the subsections shown in the figure. Figure 5-1. Interface layering diagram scheduler external interface layer this layer refers to...

  • Page 116

    Chapter 5 generated code architecture autocode reference 5-8 ni.Com discrete subsystem interface layer this layer comes in two variations to allow for both an optimized and general solution. The external interface to a discrete subsystem is represented by two structures, one representing the subsyst...

  • Page 117

    Chapter 5 generated code architecture © national instruments corporation 5-9 autocode reference this sample and hold mechanism guarantees deterministic behavior for all possible connectivities and is implemented using a technique called double buffering. Double buffering involves swapping of pointer...

  • Page 118

    Chapter 5 generated code architecture autocode reference 5-10 ni.Com procedure data procedure superblocks have inputs, outputs and states independent of the subsystem from which the procedure is called. This is required to properly implement the characteristics of a procedure; those characteristics ...

  • Page 119: Standard Procedures

    Chapter 5 generated code architecture © national instruments corporation 5-11 autocode reference system, because ordering of the outputs in a single-rate system is maintained. In a multi-rate system, duplicates can be safely eliminated because of the sample and hold mechanism. The code to perform bo...

  • Page 120

    Chapter 5 generated code architecture autocode reference 5-12 ni.Com unrolled interface there is another form of the procedural interface, the unrolled interface ( no-uy ). This interface does not use u - and y -structures to pass the inputs and outputs. The input/output signals are passed as separa...

  • Page 121

    Chapter 5 generated code architecture © national instruments corporation 5-13 autocode reference note i f you specify a specific partition with the %var name in the block form (that is, a.Gain ), that %var is directly used, not indirectly referenced. Example 5-1 relevant code to support partitioned ...

  • Page 122

    Chapter 5 generated code architecture autocode reference 5-14 ni.Com exec_error: return; } /******* subsystem 1 *******/ void subsys_1(u, y) struct _sys_extin *u; struct _subsys_1_out *y; { static rt_integer iinfo[4]; /***** local block outputs. *****/ rt_float foo_2_1; static struct _foo_u foo_2_u;...

  • Page 123

    Chapter 5 generated code architecture © national instruments corporation 5-15 autocode reference foo_2_u.Foo_1 = u->t_l_1; foo(&foo_2_u, &foo_2_y, &foo_2_i); foo_2_1 = foo_2_y.Foo_2_1; iinfo[0] = foo_2_i.Iinfo[0]; if( iinfo[0] != 0 ) { foo_2_i.Iinfo[0] = 0; goto exec_error; } /* --------------------...

  • Page 124

    Chapter 5 generated code architecture autocode reference 5-16 ni.Com mixed data-typed variables reflecting each procedure output signal and type. The states of the procedure are provided by the argument s, a pointer to a structure named _ procedure name _s . This structure contains the double-buffer...

  • Page 125

    Chapter 5 generated code architecture © national instruments corporation 5-17 autocode reference the parameter arrays rp (real parameters) and ip (integer parameters) in structure _ procedure name _i are used for storing parameter values used by algorithms of blocks in the procedure. During initiali...

  • Page 126

    Chapter 5 generated code architecture autocode reference 5-18 ni.Com extended procedure information structure the -epi option specifies that additional elements to all standard procedure superblock’s info structure are to be generated. Currently, only one additional element is generated. It is named...

  • Page 127

    Chapter 5 generated code architecture © national instruments corporation 5-19 autocode reference notice the relative numbering within a task/procedure type. Also, be aware that standard procedures are not given a unique identifier for the purposes of the caller_id element. A standard procedure super...

  • Page 128: Macro Procedure

    Chapter 5 generated code architecture autocode reference 5-20 ni.Com however, is to create additional space when declaring a variable of the info structure’s type and for the new code generated with the -epi option, which assumes the field exists in all procedure info structures. However, the old pr...

  • Page 129: Asynchronous Procedures

    Chapter 5 generated code architecture © national instruments corporation 5-21 autocode reference asynchronous procedures asynchronous procedures are procedures that are not regularly scheduled to be executed or directly called from a subsystem or standard procedure. In other words, these procedures ...

  • Page 130: Condition Block

    Chapter 5 generated code architecture autocode reference 5-22 ni.Com changing %var values during startup a special feature of the startup allows the value of a %var to be set at run-time through a global variable block that has the same name as the %var. Condition block systembuild provides three va...

  • Page 131

    Chapter 5 generated code architecture © national instruments corporation 5-23 autocode reference the blockscript block allows you to specify conditions and actions, define block inputs, outputs, and parameters, and specify their data types and dimensions. Blockscript then writes the update equations...

  • Page 132

    Chapter 5 generated code architecture autocode reference 5-24 ni.Com in example 5-5, alpha, beta, and gamma are the variables to be used as representations for the inputs. Alpha is a scalar representing the input from pin 1. Beta is an array of integers representing inputs pins 2 through 6. Gamma fo...

  • Page 133

    Chapter 5 generated code architecture © national instruments corporation 5-25 autocode reference init, output, and state phases a subsystem has phases because the blocks within the subsystem need phases of computation. The three phases are intended to be used in a consistent way, just like the stand...

  • Page 134

    Chapter 5 generated code architecture autocode reference 5-26 ni.Com default phase if you do not specify a phase and/or all code is not contained within an if statement guarded by a phase environment variable, that code is generated in the output phase and, if there is a state phase, that code also ...

  • Page 135

    Chapter 5 generated code architecture © national instruments corporation 5-27 autocode reference local variables and phases a local variable cannot be used to pass data between phases, because the different phases occur at different locations in the execution order of the whole subsystem or procedur...

  • Page 136

    Chapter 5 generated code architecture autocode reference 5-28 ni.Com new_total = y; endif; example 5-8 generated code from example 5-7 void subsys_1(u, y) struct _sys_extin *u; struct _subsys_1_out *y; { /***** states array. *****/ static struct _subsys_1_states ss_1_states[2] = {{0.0}, {0.0}}; /***...

  • Page 137

    Chapter 5 generated code architecture © national instruments corporation 5-29 autocode reference continuous semantics the state data within a continuous subsystem are called states and state derivatives. These look very similar to the discrete equivalents, except that state data is integrated by the...

  • Page 138

    Chapter 5 generated code architecture autocode reference 5-30 ni.Com in example 5-9, a hard-subscript, i , is used to access both inputs and outputs. The reason i is a hard-subscript is that the range of i —that is, the values of 1 through to the number of inputs ( u.Size )—is known when the code is...

  • Page 139

    Chapter 5 generated code architecture © national instruments corporation 5-31 autocode reference example 5-11 local variables used to allow loops in scalar code generation inputs: u; outputs: y; float u(:), y(u.Size), local_u(u.Size), local_y(y.Size); integer i,j; for i = 1:u.Size do local_u(i) = u(...

  • Page 140

    Chapter 5 generated code architecture autocode reference 5-32 ni.Com • for loop—can generate either a rolled or unrolled loop depending upon the range of the loop subscript and whether or not scalar code is generated. Examples of rolled and unrolled loops example 5-12 unrolled loop from example 5-9 ...

  • Page 141

    Chapter 5 generated code architecture © national instruments corporation 5-33 autocode reference parameters parameters represent data that can be used to provide data to tune the algorithm by representing coefficients in equations or persistent data somewhat like states. Parameters are implemented a...

  • Page 142

    Chapter 5 generated code architecture autocode reference 5-34 ni.Com example 5-14 blockscript block example with updating of a parameter inputs: u; outputs: y; environment: (output, init); parameters: total; float u,y,total; if output then if !Init then total = total + u; else total = u; endif; y = ...

  • Page 143

    Chapter 5 generated code architecture © national instruments corporation 5-35 autocode reference else { total = u->bsb_1; } y->bsb_22_1 = total; init = 0; optimizations when translating a blockscript block into source code, certain optimizations are automatically done. These optimization can reduce ...

  • Page 144

    Chapter 5 generated code architecture autocode reference 5-36 ni.Com for i = 1:y.Size do y(i) = 0.0; endif; endif; example 5-17 generated code for blockscript block example 5-16 /***** output update. *****/ /* ---------------------------- blockscript block */ /* {deadbsb..2} */ for (i=1; i deadbsb[-...

  • Page 145: Usercode Block

    Chapter 5 generated code architecture © national instruments corporation 5-37 autocode reference usercode block the purpose of the usercode block (ucb) is to interface your existing code with autocode-generated source code. A ucb is typically used to access low-level device drivers or any algorithm ...

  • Page 146

    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 u...

  • Page 147: Software Constructs

    Chapter 5 generated code architecture © national instruments corporation 5-39 autocode reference software constructs these blocks provide the software constructs that are typically found in any imperative programming language such as c, pascal, and fortran. The following software constructs are supp...

  • Page 148

    Chapter 5 generated code architecture autocode reference 5-40 ni.Com break block the while construct indefinitely iterates unless a break block is executed within the loop. You are responsible for properly detecting an exit condition and using it as an input to a break block inside the loop. If the ...

  • Page 149: Continuous Subsystem

    Chapter 5 generated code architecture © national instruments corporation 5-41 autocode reference the read from variable block optimization also is supported for local variable blocks. Refer to chapter 7, code optimization , for more details on optimization. Also, the sequencing of local variable blo...

  • Page 150

    Chapter 5 generated code architecture autocode reference 5-42 ni.Com representative of a sequence of equations. These equations are sensitive (that is, potentially numerically unstable) to the integration algorithm and order in which the equations are computed. Introducing multiple continuous subsys...

  • Page 151

    Chapter 5 generated code architecture © national instruments corporation 5-43 autocode reference • algebraic loops are not supported. • autocode only performs a single initialization pass at time = 0.0. This corresponds to the systembuild simulation options of initmode=0 or actiming . Multiprocessor...

  • Page 152

    Chapter 5 generated code architecture autocode reference 5-44 ni.Com distributed memory architecture autocode also supports a multiprocessor architecture that uses distributed memory instead of shared memory. Autocode does this by generating callouts (that is, macros) instead of the explicit code, a...

  • Page 153

    Chapter 5 generated code architecture © national instruments corporation 5-45 autocode reference 3. Copy a block of local data into shared data: update_mbuf_with_locblk(dest,src,size) 4. Copy shared data into local data: get_locf_from_mbuff(dest,src) get_locb_from_mbufb(dest,src) get_loci_from_mbufi...

  • Page 154

    Chapter 5 generated code architecture autocode reference 5-46 ni.Com • slong stands for signed long. • ulong stands for unsigned long. The naming convention of the callouts uses the terms listed above and associates from right to left. The following is an example of a callout. Update_mbufsbyte_with_...

  • Page 155

    Chapter 5 generated code architecture © national instruments corporation 5-47 autocode reference update_mbuff_with_mbufushort(x, y, convert_macro_name ) update_mbufslong_with_mbuff(x, y, convert_macro_name ) update_mbuff_with_mbufslong(x, y, convert_macro_name ) update_mbufulong_with_mbuff(x, y, con...

  • Page 156

    Chapter 5 generated code architecture autocode reference 5-48 ni.Com example 5-21 shows template code to generate the required structure and pointer. All of the necessary information about the shared variable blocks is accessible from within the template using parameter information. Example 5-21 tem...

  • Page 157

    Chapter 5 generated code architecture © national instruments corporation 5-49 autocode reference /**** declare pointer to shared variables ****/ volatile struct _shared_varblk *isi_varblk[1] = {&shared_var_blks}; @endiff@ example 5-21 assumes the existence of a fictional shared memory target such th...

  • Page 158

    Chapter 5 generated code architecture autocode reference 5-50 ni.Com shared memory callout option autocode supports a shared memory callout for all access to elements in shared memory. Callouts are generated when the -smco option is specified. The previous discussion about shared variable blocks sti...

  • Page 159

    Chapter 5 generated code architecture © national instruments corporation 5-51 autocode reference proc2_4_2 = read_shared_varblk_float(&isi_varblk[0]->block5[1]); leave_shared_varblk_section(4); /* ------------------------------- write to variable */ enter_shared_varblk_section(4); write_shared_varbl...

  • Page 160

    Chapter 5 generated code architecture autocode reference 5-52 ni.Com the formal argument represents the global reference number for which the variable block is being accessed. The default implementation of those simply calls the disable( ) function. Leaving non-shared (local) critical section the pr...

  • Page 161

    Chapter 5 generated code architecture © national instruments corporation 5-53 autocode reference the formal argument represents the global reference number for which the variable block is being accessed. The second formal argument, caller_id , represents a unique identifier for the caller. The defau...

  • Page 162

    Chapter 5 generated code architecture autocode reference 5-54 ni.Com the first formal argument represents which processor the access is taking place on. Processor numbers are 1-based. The second formal argument represents the global reference number for which the variable block is being accessed. Th...

  • Page 163

    Chapter 5 generated code architecture © national instruments corporation 5-55 autocode reference the following code uses the enter_shared_varblk... Syntax for shared variable block generated code with callouts, using the -vbco and -epi options. Enter_shared_varblk_section(4, 1); proc2_4_1 = isi_varb...

  • Page 164: Vectorized Code Generation

    © national instruments corporation 6-1 autocode reference 6 vectorized code generation this chapter discusses various ways to generate vectorized code. This includes describing the options available, design guidelines, and implementation details about the vectorized code. Introduction autocode has t...

  • Page 165

    Chapter 6 vectorized code generation autocode reference 6-2 ni.Com scalar gain block example example 6-1 shows the scalar code generated for a gain block. Example 6-1 scalar code generated for gain block example void subsys_1(u, y) struct _sys_extin *u; struct _subsys_1_out *y; { static rt_integer i...

  • Page 166

    Chapter 6 vectorized code generation © national instruments corporation 6-3 autocode reference where y ( i ) is the i th output u ( i ) is the i th input gainparameter ( i ) is the i th gain value i is the range x >, where x is the number of outputs of the block as you can see from the code generati...

  • Page 167

    Chapter 6 vectorized code generation autocode reference 6-4 ni.Com if (subsys_preinit[1]) { iinfo[0] = 0; iinfo[1] = 1; iinfo[2] = 1; iinfo[3] = 1; for( cnt=0;cnt r_p[cnt] = _r_p[cnt]; } subsys_preinit[1] = false; return; } /***** output update. *****/ /* ---------------------------- gain block */ /...

  • Page 168

    Chapter 6 vectorized code generation © national instruments corporation 6-5 autocode reference addition to issues with the standard block library, all general blockscript blocks within the diagram are implemented as 1-based arrays. If the subscript can be evaluated at generation-time, the 0-based su...

  • Page 169

    Chapter 6 vectorized code generation autocode reference 6-6 ni.Com figure 6-1. Poorly connected gain block example 6-3 generated code for poorly connected gain block (for figure 6-1) void subsys_1(u, y) struct _subsys_1_in *u; struct _subsys_1_out *y; { static rt_integer iinfo[4]; /***** parameters....

  • Page 170: Vectorization Modes

    Chapter 6 vectorized code generation © national instruments corporation 6-7 autocode reference /* ---------------------------- gain block */ /* {gain..2} */ y->gain_2_1[0] = 1.2*u->gain_1[0]; y->gain_2_1[1] = 2.3*u->gain_1[2]; y->gain_2_1[2] = 3.4*u->gain_1[3]; y->gain_2_1[3] = 4.5*u->gain_1[5]; y->...

  • Page 171

    Chapter 6 vectorized code generation autocode reference 6-8 ni.Com vector labels and names the superblock editor lets you give a name to a range of signals using a special notation. The editor then repeatedly applies that name to the range. Autocode interprets this type of labeling as a definition o...

  • Page 172

    Chapter 6 vectorized code generation © national instruments corporation 6-9 autocode reference figure 6-2. Example model diagram example 6-4 maximal vectorized code generation (for figure 6-2) /******* system ext i/o type declarations. *******/ struct _subsys_1_out { rt_float delayed_pulse[5]; }; st...

  • Page 173

    Chapter 6 vectorized code generation autocode reference 6-10 ni.Com static struct _subsys_1_states *x; static struct _subsys_1_states *xd; static struct _subsys_1_states *xtmp; static rt_integer iinfo[4]; static rt_integer init; /***** parameters. *****/ static rt_float r_p[11]; rt_integer cnt; stat...

  • Page 174

    Chapter 6 vectorized code generation © national instruments corporation 6-11 autocode reference } subsys_preinit[1] = false; return; } /***** output update. *****/ /* ---------------------------- time delay */ /* {vecex..12} */ if (init) { k = 0; for (i=1; i x->sensor_delay[k] = r_p[i]; k = k + 1; }...

  • Page 175

    Chapter 6 vectorized code generation autocode reference 6-12 ni.Com example 6-5 mixed vectorized code generation (for figure 6-2) /******* system ext i/o type declarations. *******/ struct _subsys_1_out { rt_float delayed_pulse[5]; }; struct _sys_extin { rt_float sensor_5; rt_float sensor_11; rt_flo...

  • Page 176

    Chapter 6 vectorized code generation © national instruments corporation 6-13 autocode reference rt_float brake; rt_float gear; rt_float clutch; /***** algorithmic local variables. *****/ rt_integer i; rt_integer j; rt_integer k; /******* initialization. *******/ if (subsys_preinit[1]) { iinfo[0] = 0...

  • Page 177: Vectorization Features

    Chapter 6 vectorized code generation autocode reference 6-14 ni.Com k = k + 1; } } k = 1; for (i=1; i y->delayed_pulse[-1+i] = x->sensor_delay[-1+k]; k = k + 1; } /* ---------------------------- gain block */ /* {vecex..2} */ throttle = -8.7*u->sensor_5; pedal = -7.6*u->sensor_11; brake = -6.5*u->se...

  • Page 178

    Chapter 6 vectorized code generation © national instruments corporation 6-15 autocode reference note the examples within this section assume maximal vectorization unless otherwise noted. Multiple arrays within a block all blocks support multiple vectors (arrays) as both outputs and inputs. However, ...

  • Page 179

    Chapter 6 vectorized code generation autocode reference 6-16 ni.Com 1.2, 2.3, 3.4, 4.5, 5.6, 1.0, 1.0, 1.0, 1.0, 1.0}; /***** local block outputs. *****/ rt_float top[5]; rt_float bottom[5]; /***** algorithmic local variables. *****/ rt_integer i; /******* initialization. *******/ if (subsys_preinit...

  • Page 180

    Chapter 6 vectorized code generation © national instruments corporation 6-17 autocode reference the interesting part is that of the last gain block ( gain..99 ). Notice that although two distinct arrays are used as input, because the input arrays are connected contiguously, the code is rolled into t...

  • Page 181

    Chapter 6 vectorized code generation autocode reference 6-18 ni.Com figure 6-4. Example of a split vector example 6-7 generated code for split vector (for figure 6-4) /***** output update. *****/ /* ---------------------------- gain block */ /* {gain.Top.2} */ for (i=1; i top[-1+i] = r_p[-1+i]*u->ga...

  • Page 182

    Chapter 6 vectorized code generation © national instruments corporation 6-19 autocode reference the two producer gain blocks (top, bottom) vectorize as expected. The (gain..99) does not vectorize well. Notice that autocode was only able to vectorize two inputs while the remaining four were unrolled....

  • Page 183

    Chapter 6 vectorized code generation autocode reference 6-20 ni.Com example 6-8 generated code (for figure 6-5) /***** output update. *****/ /* ---------------------------- gain block */ /* {gain.Top.2} */ for (i=1; i top[-1+i] = r_p[-1+i]*u->gain_1[-1+i]; } /* ---------------------------- gain bloc...

  • Page 184

    Chapter 6 vectorized code generation © national instruments corporation 6-21 autocode reference you should notice two things in the code shown in example 6-8. First, the gain block added to merge the data is generated as copies from the respective inputs into the single array. Second, the integrator...

  • Page 185

    Chapter 6 vectorized code generation autocode reference 6-22 ni.Com figure 6-6. Copy-back example example 6-9 generated code (for figure 6-6) void subsys_1(u, y) struct _sys_extin *u; struct _subsys_1_out *y; { /**** some code deleted ****/ /***** output update. *****/ /* ---------------------------...

  • Page 186

    Chapter 6 vectorized code generation © national instruments corporation 6-23 autocode reference eliminating copy-back there are many design ways to eliminate or hide the extra copies of the copy-back. All of them can be categorized into two groups: • use mixed vectorization mode and force scalars to...

  • Page 187

    Chapter 6 vectorized code generation autocode reference 6-24 ni.Com figure 6-7. Vectorized procedure interface example 6-10 generated code (for figure 6-7) /******* procedure: vecproc *******/ void vecproc(vecproc_1, vecproc_2_1, i) rt_float vecproc_1[5]; rt_float vecproc_2_1[5]; struct _vecproc_inf...

  • Page 188

    Chapter 6 vectorized code generation © national instruments corporation 6-25 autocode reference top[-1+i] = r_p[-1+i]*u->gain_1[-1+i]; } /* ---------------------------- procedure super block */ /* {vecproc.3} */ vecproc(&top[0], &y->vecproc_3_1[0], &vecproc_3_i); iinfo[0] = vecproc_3_i.Iinfo[0]; if(...

  • Page 189

    Chapter 6 vectorized code generation autocode reference 6-26 ni.Com init := true; x := ptr_of(ss_1_states(0)’address); xd := ptr_of(ss_1_states(1)’address); x.Sensor_delay := (others => 0.0); xd.Sensor_delay := (others => 0.0); for cnt in rt_integer range 0..10 loop r_p(cnt) := rp(cnt); end loop; su...

  • Page 190

    Chapter 6 vectorized code generation © national instruments corporation 6-27 autocode reference ------ swap state pointers. ------ xtmp := x; x := xd; xd := xtmp; init := false; end; vectorization of the blockscript block the general blockscript block is commonly used to implement very complicated o...

  • Page 191: Matrix Outputs

    Chapter 6 vectorized code generation autocode reference 6-28 ni.Com matrix outputs when you provide matricized output labeling for a block, autocode generates the resulting “matrix” as a single-dimensional array, even in ada. This means that the output of a matrix-labeled block and the output of a v...

  • Page 192: Code Optimization

    © national instruments corporation 7-1 autocode reference 7 code optimization this chapter explains the details of generating production quality code for micro controller-based applications. Generally, micro controller-based applications have stringent requirements for code size and execution speed....

  • Page 193

    Chapter 7 code optimization autocode reference 7-2 ni.Com static rt_integer iinfo[4]; /***** local block outputs. *****/ rt_float new_11_1; rt_float new_1_1; rt_float new_12_1; /******* initialization. *******/ if (subsys_preinit[1]) { iinfo[0] = 0; iinfo[1] = 1; iinfo[2] = 1; iinfo[3] = 1; subsys_p...

  • Page 194

    Chapter 7 code optimization © national instruments corporation 7-3 autocode reference example 7-2 code generated with variable block optimization turned on /* model variable definitions */ rt_float var; rt_float var1; void subsys_1(u, y) struct _sys_extin *u; struct _subsys_1_out *y; { static rt_int...

  • Page 195

    Chapter 7 code optimization autocode reference 7-4 ni.Com iinfo[1] = 0; } return; exec_error: error_flag[1] = iinfo[0]; iinfo[0]=0;}} autocode performs this optimization only if it is safe to do so. There could be circumstances that could potentially prevent this optimization from taking place. Auto...

  • Page 196: Restart Capability

    Chapter 7 code optimization © national instruments corporation 7-5 autocode reference write to the same variable block. Due to the cyclic nature of loops, any write to variable block inside the loop appears in between the read from variable block outside the loop and its use inside the loop. Restart...

  • Page 197

    Chapter 7 code optimization autocode reference 7-6 ni.Com static const rt_float _r_p[8] = {-1.0, 1.0, 1.5, 2.0, -1.0, 1.0, 1.25,1.4}; /***** local block outputs. *****/ rt_float proc_2_1; rt_float proc_14_1; rt_float proc_12_1; /***** algorithmic local variables. *****/ rt_integer ilower; rt_integer...

  • Page 198

    Chapter 7 code optimization © national instruments corporation 7-7 autocode reference the buffer _r_p and the initialization code are optimized away. Instead, the buffer r_p (parameter array), states, derivatives, and info structures are initialized directly in the declaration portion. After these s...

  • Page 199: Merging Init Sections

    Chapter 7 code optimization autocode reference 7-8 ni.Com merging init sections most of the dynamic blocks have explicit initialization, output update and state update sections. The initialization section is guarded by an init boolean variable that is true only for the first time a subsystem or a pr...

  • Page 200

    Chapter 7 code optimization © national instruments corporation 7-9 autocode reference /* ---------------------------- time delay */ /* {proc..22} */ if (init) { x->proc_22_s1 = 0.0; } proc_22_1 = x->proc_22_s1; /* ---------------------------- time delay */ /* {proc..24} */ if (init) { x->proc_24_s1 ...

  • Page 201

    Chapter 7 code optimization autocode reference 7-10 ni.Com x->proc_22_s1 = 0.0; x->proc_24_s1 = 0.0; xd->proc_22_s1 = 0.0; xd->proc_24_s1 = 0.0; /* ---------------------------- time delay */ /* {proc..22} */ x->proc_22_s1 = 0.0; /* ---------------------------- time delay */ /* {proc..24} */ x->proc_...

  • Page 202

    Chapter 7 code optimization © national instruments corporation 7-11 autocode reference in example 7-5, both time delay blocks have separate init sections. In example 7-6, the initialization code for these blocks is merged along with the subsystem initialization section. Reuse of temporary block outp...

  • Page 203

    Chapter 7 code optimization autocode reference 7-12 ni.Com example 7-7 shows code generated without the reuse option, and example 7-8 shows code generated from the same models with the maximal reuse option. Example 7-7 code fragment without reuse optimization /***** local block outputs. *****/ rt_fl...

  • Page 204: Constant Propagation

    Chapter 7 code optimization © national instruments corporation 7-13 autocode reference } y->model_5_1 = x->model_5_s1; /* ---------------------------- gain block */ /* {model..2} */ model_2_1 = 2.0*u->model_1; /* ---------------------------- sum of vectors */ /* {model..3} */ model_3_1 = model_2_1 -...

  • Page 205

    Chapter 7 code optimization autocode reference 7-14 ni.Com all of the blocks can accept constants as inputs. If any input is available during code generation time as a constant, the constant is used instead of a symbol name (or variable name). This applies to blocks of both categories. One limitatio...

  • Page 206

    Chapter 7 code optimization © national instruments corporation 7-15 autocode reference /* {const..4} */ y->const_4_1 = 2.0*const_2_1; .. .. Example 7-10 code generated with the constant propagation option void subsys_1(y) struct _subsys_1_out *y; { static rt_integer iinfo[4]; /***** local block outp...

  • Page 207

    Chapter 7 code optimization autocode reference 7-16 ni.Com input of the gain block and the expression 2.0 * const_2 is evaluated to 4 as the value of const_2_1 is 2. Hence, the subsystem output gets the value 4. The command-line option for invoking this optimization is -opc . Optimizing with matrix ...

  • Page 208

    Chapter 7 code optimization © national instruments corporation 7-17 autocode reference constant block is optimized away, including the output variable. Also notice that the existing constant propagation optimization can be used with the constant block, but will only operate on scalar pieces of the c...

  • Page 209

    Chapter 7 code optimization autocode reference 7-18 ni.Com if you have decided on the matrixrightdivide block, the tips for optimizing the inputs are much the same as for the matrixinverse block. In this case there are two inputs, a and b, and both are modified by the callout algorithm. Thus, a copy...

  • Page 210: Summary

    Chapter 7 code optimization © national instruments corporation 7-19 autocode reference summary all of the optimizations discussed so far can be used at the same time without limitations. All of these optimizations can work together and potentially bring about a cumulative effect in reducing the code...

  • Page 211: Introduction

    © national instruments corporation 8-1 autocode reference 8 autocode sim cdelay scheduler this chapter discusses the sim cdelay low-latency scheduler. Introduction the default autocode scheduler is based on high throughput. Latency is acceptable as long as scheduler interrupt times are frequent. Bec...

  • Page 212: Task Posting Policies

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-2 ni.Com real-time hardware. It assumes the reader is familiar with the concepts of autocode’s default scheduler. Refer to the autocode user guide for more information about the scheduler, task types, and output posting. Task posting polic...

  • Page 213: Standard Autocode Scheduler

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-3 autocode reference standard autocode scheduler to illustrate the behavior of the standard autocode scheduler with triggered and enabled superblocks, it is helpful to consider the diagnostic model shown in figure 8-1, whic...

  • Page 214

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-4 ni.Com figure 8-1. Model with enabled and triggered tasks under the default autocode scheduler, the output of this system is as shown in figure 8-2. The top signal (corresponding to the triggered task) shows a latency of two cycles relat...

  • Page 215

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-5 autocode reference scheduler pipeline section that these latencies are caused by the single posting stage per scheduler invocation in the default autocode scheduler, and by the output posting policy assigned to enabled bl...

  • Page 216

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-6 ni.Com triggers/enables have gone high are queued for execution. Then, in stage d, atr tasks whose output posting times have arrived and anc tasks that have just been queued for execution in stage c are marked for output posting, which i...

  • Page 217

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-7 autocode reference queue tasks stage for that scheduler invocation has already passed; thus, the triggered task cannot be queued for execution until 0.7 sec. At the time that it is queued, it sets its time delay for 0.1 s...

  • Page 218

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-8 ni.Com now the inherent problem in the standard scheduler is clear. From launch to output posting, you suffer a two-cycle delay for triggered tasks, and a three-cycle delay for enabled tasks, instead of the standard unit cycle delay pres...

  • Page 219: Sim Cdelay Scheduler

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-9 autocode reference sim cdelay scheduler as stated at the outset, the goal of this project was to develop a new autocode scheduler, runnable on real-time targets, which mimics the behavior of sim with cdelay ( actiming off...

  • Page 220

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-10 ni.Com triggers arriving too quickly can prevent a task from ever posting any output. You must build an alternative autocode scheduler incorporating the new pipeline stages presented above, and change the transition diagrams of many of ...

  • Page 221

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-11 autocode reference figure 8-6. New std for atr triggered tasks figure 8-7. New std for atr triggered tasks idle running blocked task done timer is zero and enable, reset timer and post outputs timer is zero and !Enable, ...

  • Page 222

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-12 ni.Com these transition diagrams, together with the diagrams in chapter 4, managing and scheduling applications , of the autocode user guide , define the behavior of tasks under the sim with cdelay scheduler. They encompass all of the c...

  • Page 223

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-13 autocode reference datastore priority problem as mentioned, you must find some way to enforce the priority of writers to datastores in the generated code. Each datastore register can be written to independently, so each ...

  • Page 224

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-14 ni.Com for tsk /* loop from low to high priority */ if tsk.Ready_to_post_outputs() if tsk.Prio() > reg_prio /* higher priorities are larger */ write_register(tsk.Output()); /*write to datastore register*/ in the generated code, the prio...

  • Page 225

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-15 autocode reference figure 8-8. Latencies present in the autocode scheduler template configuration for enhanced performance as mentioned in a previous section, there are drawbacks to re-executing an atr task when it is re...

  • Page 226

    Chapter 8 autocode sim cdelay scheduler autocode reference 8-16 ni.Com at the template level, the default sim with cdelay atr triggered task behavior of re-queueing a task for execution on receipt of a new trigger before the outputs have been posted can be turned off by replacing the segment call si...

  • Page 227

    Chapter 8 autocode sim cdelay scheduler © national instruments corporation 8-17 autocode reference that repeated until no new tasks where queued for execution. Given such an implementation, the chained anc problem would disappear. However, under such a design, scheduler execution time would be varia...

  • Page 228: Global Scope Signals and

    © national instruments corporation 9-1 autocode reference 9 global scope signals and parameterless procedures this chapter discusses global scope signals and parameterless procedures. Introduction the memory and performance requirements of real-time production code force the issue of global variable...

  • Page 229: Data Monitoring/injection

    Chapter 9 global scope signals and parameterless procedures autocode reference 9-2 ni.Com these new features address the following two uses: • data monitoring/injection —the safe access to local subsystem signals for the purpose of monitoring the signal’s value during the execution of the model. Thi...

  • Page 230

    Chapter 9 global scope signals and parameterless procedures © national instruments corporation 9-3 autocode reference memory address, and that string is accessible through template tokens during code generation. Note be careful when selecting only a partial subset of block outputs as global scope wh...

  • Page 231

    Chapter 9 global scope signals and parameterless procedures autocode reference 9-4 ni.Com limitations this section identifies some of the limitations of scoped output. Unsupported blocks the following list presents the blocks that do not support scoped outputs. • blocks that are not supported by aut...

  • Page 232: Parameterless Procedure

    Chapter 9 global scope signals and parameterless procedures © national instruments corporation 9-5 autocode reference parameterless procedure a parameterless (argument-less) procedure is a procedure that uses global variable(s) to pass input(s) into and/or output(s) out of the procedure. Each input ...

  • Page 233

    Chapter 9 global scope signals and parameterless procedures autocode reference 9-6 ni.Com note ni suggests that you adopt a naming convention for all of your global variables used for parameterless procedure signals. For example, specify all of the names with a leading “g,” like gthrottlevalue . Out...

  • Page 234

    Chapter 9 global scope signals and parameterless procedures © national instruments corporation 9-7 autocode reference condition block code generation the condition block supports the use of parameterless procedures. In the nodefault and sequential modes, the condition block will not buffer the globa...

  • Page 235

    Chapter 9 global scope signals and parameterless procedures autocode reference 9-8 ni.Com note you must write template code to customize the declarations of these variables, which includes usage of the memory address string because this is target/compiler specific information. Issues and limitations...

  • Page 236

    Chapter 9 global scope signals and parameterless procedures © national instruments corporation 9-9 autocode reference connection to external output if a signal that is used as input to a global scope procedure input or a global scope procedure output is connected to a external output pin, be aware t...

  • Page 237: Command Options

    Chapter 9 global scope signals and parameterless procedures autocode reference 9-10 ni.Com analyzer and autocode warnings the analyzer reports questionable connectivities or situations regarding usage of the global scope signals. Also, autocode might report additional warnings during code generation...

  • Page 238: Technical Support and

    © national instruments corporation a-1 autocode reference a technical support and professional services visit the following sections of the national instruments web site at ni.Com for technical support and professional services: • support —online technical support resources at ni.Com/support include...

  • Page 239: Index

    © national instruments corporation i-1 autocode reference index a add and subtract macros, 2-40 arguments ucb-ada fixed calling, 3-12 ucb-c fixed calling, 2-13 arithmetic macros, 2-35 array iinfo, 5-17 ip, 5-16, 5-17 r_p for vectorized code, 6-4 rinfo, 5-17 rp, 5-16, 5-17 subscripts vectorized code,...

  • Page 240

    Index autocode reference i-2 ni.Com compile_ada_sa.Sh compilation script, 3-11 compile_c_sa.Sh compilation script, 2-11 compiling, 2-1 condition block. See generated code architecture, condition code condition superblock, 9-7 conditions and actions, 5-23 configuration file. See rtos, configuration f...

  • Page 241

    Index © national instruments corporation i-3 autocode reference _.A extension (ada), 3-3 compile_ada_sa.Sh, 3-11 compile_c_sa.Sh, 2-11 sa_defn.A, 3-4 sa_defn.H, 2-3, 2-4 sa_defn_.A, 3-5 sa_fmath.A, 3-4 sa_fmath_.A, 3-4, 3-5 sa_fuzzy.A, 3-4 sa_fuzzy.H, 2-4 sa_fuzzy_.A, 3-4 sa_fx.H, 2-32 sa_fx_externs...

  • Page 242

    Index autocode reference i-4 ni.Com bitwise functions, 3-26 comparing to sim results, 3-35 compilation example, 3-21 compiler problems, 3-35 conversion functions, 3-27, 3-31 creating instances of functions, 3-17 data types, 3-17 division function, 3-31 explicit rounding conversion, 3-32 files in the...

  • Page 243

    Index © national instruments corporation i-5 autocode reference olvarblk option, 7-4 onorestart option, 7-5 propagating constants (opc option), 7-13 removing restart capability, 7-5 reusing temporary block outputs, 7-11 reusing temporary block outputs as specified, 7-11 variable block optimization, ...

  • Page 244

    Index autocode reference i-6 ni.Com distributed memory architecture, 5-44 mapping command options, 5-45 shared memory architecture, 5-43 callouts, 5-44 optimization for read-from variable blocks, 5-4 sequencer block, 5-41 similarities to compiler, 5-1 single-rate system, 5-8 software constructs, 5-3...

  • Page 245

    Index © national instruments corporation i-7 autocode reference l local variable blocks, 5-40, 5-41 local variables, 5-27 m macro interface, 2-27 files needed, 2-27 macro procedure superblocks. See generated code architecture, macro procedure superblocks math_lib (ada), 3-5 matrixinverse, 7-17 matri...

  • Page 246

    Index autocode reference i-8 ni.Com r r_p, 5-9 ucb fixed call argument, ada, 3-12 rapid prototyping, 1-2 real-time code generating, 3-16 real-time file, 3-16 related publications, 1-4 reusable procedures example, 2-22 generated subsystem function, 2-25 generated ucb wrapper function, 2-24 generating...

  • Page 247

    Index © national instruments corporation i-9 autocode reference sa_fxdiv_long.C file, 2-32, 2-34 sa_fxdiv_short.C file, 2-34 sa_fxlimit.H file, 2-32, 2-33 sa_fxm.H file, 2-32, 2-33 sa_fxm_f.C file, 2-34 sa_fxm_f.H file, 2-33 sa_fxmp.H file, 2-32, 2-33 sa_fxmp_f.H file, 2-33 sa_fxmul_byte.C file, 2-3...

  • Page 248

    Index autocode reference i-10 ni.Com shared memory callouts, 5-50 fixed-point callouts ada, 5-47 c, 5-46 shared variable block support, 5-47 simulation, stand-alone, 2-1 soft-subscript, 5-29 software (ni resources), a-1 software constructs. See generated code architecture, software constructs stand-...

  • Page 249

    Index © national instruments corporation i-11 autocode reference template code for variable block structures, 5-48 timing overflow, 2-8 training and certification (ni resources), a-1 troubleshooting (ni resources), a-1 u u (ucb fixed call argument) ada, 3-12 c, 2-13 ucb, 2-3, 2-20, 3-4 arguments c, ...

  • Page 250

    Index autocode reference i-12 ni.Com x x (ucb fixed call argument) ada, 3-12 c, 2-13 xd (ucb fixed call argument) ada, 3-12 c, 2-13 xinput array, 2-10 xmath {matrixx,ascii}, 2-7 xoutput array, 2-10 y y (ucb fixed call argument) ada, 3-12 c, 2-13.