National Instruments AutoCode NI MATRIX Reference
National Instruments AutoCode NI MATRIX Reference

National Instruments AutoCode NI MATRIX Reference

National instruments ni matrixx reference manual
Table of Contents

Advertisement

Quick Links

NI MATRIXx
TM
AutoCode
Reference
TM
AutoCode Reference
April 2007
370768C-01

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AutoCode NI MATRIX and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for National Instruments AutoCode NI MATRIX

  • Page 1 NI MATRIXx AutoCode Reference AutoCode Reference April 2007 370768C-01...
  • Page 2 For further support information, refer to the Technical Support and Professional Services appendix. To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback. © 2007 National Instruments Corporation. All rights reserved.
  • Page 3: Important Information

    Instruments Corporation. National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license or other legal restriction.
  • Page 4 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<3..0>. » The » symbol leads you through nested menu items and dialog box options to a final action.
  • Page 5: Table Of Contents

    Linking Handwritten UCBs (for AutoCode) with SystemBuild ...2-16 Variable Interface UCB...2-18 Interface Ordering ...2-18 Inputs and Outputs ...2-18 Function Prototype...2-19 Linking a Variable Interface UCB with the Simulator ...2-20 Procedure SuperBlocks...2-20 Generating Reusable Procedures...2-20 Linking Procedures with the SystemBuild Simulator ...2-20 © National Instruments Corporation AutoCode Reference...
  • Page 6 Contents 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 Using Generated Subsystem Function ... 2-25 C Fixed-Point Arithmetic ... 2-26 Fixed-Point AutoCode/C Implementation ... 2-26 Generated Code with Fixed-Point Variables ...
  • Page 7 Explicit Rounding Conversion...3-32 Using System-Level Parameters to Generate Instantiations ...3-33 Using Subsystem-Level Parameters to Generate Instantiations...3-33 System Scope Operators and Conversions...3-34 Known Ada Compiler Problems ...3-35 Comparing Results to SystemBuild’s Simulator...3-35 No-Op Conversion Function ...3-36 © National Instruments Corporation Contents AutoCode Reference...
  • Page 8 Contents Chapter 4 Generating Code for Real-Time Operating Systems Real-Time Operating System Configuration File... 4-1 Configuration Items ... 4-2 Table Syntax ... 4-2 Table Naming Convention... 4-3 Table Column Contents ... 4-3 Table Orderings ... 4-3 File Comments... 4-3 RTOS Configuration File Contents... 4-3 Processors Table ...
  • Page 9 Background...5-21 Startup...5-21 Changing %var Values During Startup...5-22 Condition Block ...5-22 Default Mode...5-22 No-Default Mode...5-22 Sequential Mode...5-22 BlockScript Block...5-22 Inputs and Outputs...5-23 Environment Variables...5-24 Local Variables...5-24 Init, Output, and State Phases...5-25 Default Phase ...5-26 © National Instruments Corporation Contents AutoCode Reference...
  • Page 10 Contents States ... 5-26 Local Variables and Phases ... 5-27 Discrete Semantics ... 5-27 Continuous Semantics ... 5-29 Looping Concepts ... 5-29 Terminology ... 5-29 Loops and Scalar Code ... 5-29 Rolling Loops with Scalar Code Generation ... 5-30 Vectorized Code ... 5-31 Types of Loops ...
  • Page 11 Split-Merge Inefficiency ...6-17 Split Vector ...6-17 Merge ...6-19 External Outputs...6-21 Copy-Back ...6-21 Eliminating Copy-Back...6-23 Other Copy-Back Scenarios...6-23 Vectorized Standard Procedure Interface...6-23 Ada Array Aggregates and Slices...6-25 Vectorization of the BlockScript Block...6-27 Matrix Outputs ...6-28 © National Instruments Corporation Contents AutoCode Reference...
  • Page 12 Contents Chapter 7 Code Optimization Read from Variable Blocks ... 7-1 Restart Capability ... 7-5 Merging INIT Sections... 7-8 Reuse of Temporary Block Outputs ... 7-11 Reuse Temporaries as Specified ... 7-11 Maximal Reuse of Temporaries ... 7-11 Constant Propagation... 7-13 Optimizing with Matrix Blocks...
  • Page 13 Connection to External Output ...9-9 Recommendations ...9-9 Naming Convention ...9-9 Model Documentation...9-9 Explicit Sequencing ...9-9 Analyzer and AutoCode Warnings ...9-10 Changing Scope Class...9-10 Command Options ...9-10 Appendix A Technical Support and Professional Services Index © National Instruments Corporation xiii Contents AutoCode Reference...
  • Page 14: Manual Organization

    • • • • • • © National Instruments Corporation Chapter 1, Introduction, provides an overview of the rapid prototyping concept, the automatic code generation process, and the nature of real-time generated code. Chapter 2, C Language Reference, discusses files used to interface...
  • Page 15: General Information

    Chapter 1 Introduction • • This guide also has an Index. General Information As an integral part of the rapid prototyping concept, AutoCode lets you generate high-level language code from a SystemBuild block diagram model quickly, automatically, and without programming skills. The AutoCode User Guide describes the processes for generating code, including the parameters that you must use.
  • Page 16: Structure And Content Of The Generated Code

    MATRIXx CD. Additional Netscape Information For more information on Netscape products, visit the Netscape Web site at http://home.netscape.com © National Instruments Corporation Generating code for use within real-time operating systems Code architecture Vectorized code generation Chapter 1...
  • Page 17: Related Publications

    Chapter 1 Introduction 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: • • • • •...
  • Page 18: C Language Reference

    % acc -DSOLARIS -o simulation simmodel.c sa_*.o -lm Note This example assumes the stand-alone library was compiled into separate object files into the current working directory and that the stand-alone header files also exist in the current working directory. © National Instruments Corporation AutoCode Reference...
  • Page 19: Stand-Alone Library

    This section describes the system-specific and target-specific stand-alone System-Specific Files National Instruments furnishes files to interface AutoCode and the generated code to your development platform (AIX, Compaq, HP, SGI, Solaris, Windows) and to the target processor in your test bed or rapid-prototyping system.
  • Page 20 SystemBuild model includes UCBs. Refer to the Linking Handwritten UCBs (for AutoCode) with SystemBuild information. • Table 2-3 summarizes the most significant header files. The indicates stand-alone. © National Instruments Corporation UNIX $CASE/ACC/templates c_sim.tpl, c_intgr.tpl c_sim.dac...
  • Page 21 Chapter 2 C Language Reference sa_sys.h sa_types.h sa_defn.h sa_intgr.h sa_fuzzy.h sa_utils.h sa_math.h sa_time.h sa_user.h Data Types Several of the target-specific utilities are involved with data types (in the the C Code Generator: RT_FLOAT RT_INTEGER RT_BOOLEAN At compilation, you must make available the which declares these types.
  • Page 22: Target-Specific Utilities

    The routines are shown in Table 2-4. Enable( ) Disable( ) Background( ) Error( ), fatalerr( ) Implementation_Initialize( ) © National Instruments Corporation Chapter 2 can be redefined as RT_INTEGER ) perform hardware, application, sa_utils.c file or keep separate versions sa_utils.c...
  • Page 23: Enable( ), Disable( ), And Background( ) Functions

    Chapter 2 C Language Reference Implementation_Terminate( ) External_Input( ) External_Output( ) Signal_Remote_Dispatch( ) are used for comparing simulation with generated code results. After you generate code, link the generated code with (refer to Chapter 2, Using AutoCode, of the AutoCode User Guide). For example, on UNIX platforms: cc -o gen_ap gen_ap .c $ISI/ACC/src/sa_*.o -l other libraries...
  • Page 24: Fatalerr( ): Stand-Alone Utilities Detected Errors

    The following messages indicate that the size of the input file has exceeded one or more of the storage allocation size limits established by . These limits are at the very beginning of the sa_utils.c #defined header, just after the header statements. Refer to sa_utils.c #include © National Instruments Corporation AutoCode Reference...
  • Page 25: Error: Conditions Detected In The Generated Code

    Chapter 2 C Language Reference the comments there and adjust the limits accordingly, then recompile and relink the ERROR OPENING THE INPUT FILE ERROR OPENING THE OUTPUT FILE A problem was encountered opening the input or output file. Possible causes include a file protection violation. UNKNOWN ERROR A value of the for the switch-case statement.
  • Page 26: Implementation_Initialize( ) Function

    These might include, but are not limited to, the following: • • • © National Instruments Corporation sa_utils.c input file. In the version of this routine FSAVE Initialize the interrupt system of the target computer.
  • Page 27: External_Input ( ) Function

    Chapter 2 C Language Reference External_Input ( ) Function RT_INTEGER External_Input(void) External_Input( ) reads in external input data from your specified appears in input vector ( conversion is required in this version of the generated code, because all data is passed as arrays of type SCHEDULER_STATUS and is passed to the target version of...
  • Page 28: Linking Handwritten Ucbs With Autocode Applications

    USR01, refer to callout 2 of Figure 2-1—is renamed, all other occurrences of USR01 in changed appropriately, including the occurrence in directive to callout 1 of Figure 2-1. © National Instruments Corporation distribution directory. file contains an example of a UCB function declaration sa_user.c Implementing Handwritten UCBs ) for automatic compilation.
  • Page 29 Chapter 2 C Language Reference facility of the simulator in SystemBuild to distinguish between UCBs written for simulation purposes using SystemBuild only and UCBs written for linking with AutoCode applications. The exact name of the UCB function must be specified in the used for simulation using SystemBuild.
  • Page 30: Implementing Handwritten Ucbs

    R_P[ ] RT_FLOAT I_P[ ] RT_INTEGER © National Instruments Corporation ) are passed to each call to the UCB. The sizes of arrays must be entered into the UCB dialog to ensure that A pointer to representing operation requests and status.
  • Page 31 Chapter 2 C Language Reference The operations within UCBs are controlled by the argument to a structure of type argument list for each UCB (located in typedef struct STATUS_RECORD The following example shows the general form of UCB equations for AutoCode and indicates how the control the computations.
  • Page 32 (Handwritten UCB using sa_user © National Instruments Corporation y (k) = -1/2*y(k-2) + 3* u(k) + u(k-2); which leads to the State-Space realization: x1(k+1) = x2(k) x2(k+1) = -1/2* x1(k) - 1/ 2*u(k) y(k) = x1(k) + 3*u (k)
  • Page 33: Linking Handwritten Ucbs (For Autocode) With Systembuild

    Chapter 2 C Language Reference 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 the simulation engine (release 4.0 and later).
  • Page 34 AutoCode generated code. If you have handwritten code for simulation with SystemBuild using the UCB format usr01.c © National Instruments Corporation Figure 2-3. Linking Handwritten UCBs with the SystemBuild Simulator ) are inherently different than the arguments usr01.c...
  • Page 35: Variable Interface Ucb

    Chapter 2 C Language Reference applications, make sure you adapt the same algorithm in the body of a function using the AutoCode UCB arguments as in Variable Interface UCB The preceding sections described the fixed interface; however, a UCB can also use the variable interface option.
  • Page 36: Function Prototype

    UCB. Function Prototype National Instruments recommends that you create a function prototype for your variable interface UCB functions. This will provide some additional checking that the compiler can do to ensure that the generated interface matches what you expected without your implementation of the UCB function.
  • Page 37: Linking A Variable Interface Ucb With The Simulator

    Chapter 2 C Language Reference 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 create a “wrapper” function that interfaces between the Simulator and your code.
  • Page 38 SUPER BLOCK Procedure Procedure myproc.c © National Instruments Corporation . Refer to the Template Programming Language User simulation (automatic compiling and linking of myproc.c int. new UCB shared library) Generate Reusable Procedure Figure 2-4. Linking Generated Reusable Procedures 2-21...
  • Page 39: Linking Procedures With Real-Time Applications Or Simulator

    Chapter 2 C Language Reference Linking Procedures with Real-Time Applications or Simulator Generate reusable procedures from your Procedure SuperBlocks as described in this chapter and in Chapter 3, link generated reusable procedures with your own application or simulator you have the three following options: •...
  • Page 40 Generate Reusable Procedure © National Instruments Corporation Create an object of type _ procedure name _s procedure will be stored and initialize all members of the object to 0.0. This should be done during initialization only. A pointer to this object will be passed as argument S to the procedure.
  • Page 41: Invoking Procedures Using Generated Ucb Wrapper Function

    Chapter 2 C Language Reference Several of the previous steps are exercised by the other two methods for invoking generated procedures described in the Real-Time Applications or Simulator Invoking Procedures Using Generated UCB Wrapper Function section and Use the generated UCB wrapper and subsystem code as a guide. The UCB wrapper is generated for the purpose of re-entrancy, thus producing extra copy in and out of parameter and states variables and control and status arrays, while the subsystem code is not re-entrant—that is, the states and...
  • Page 42: Invoking Procedures Using Generated Subsystem Function

    The inputs to the subsystem are provided by the argument _Subsys_ number _in © National Instruments Corporation properly. Refer to the SystemBuild User Guide for an explanation of . Only the first four elements of this array will be used by the rinfo generated procedure.
  • Page 43: C Fixed-Point Arithmetic

    Chapter 2 C Language Reference data-typed variables reflecting each subsystem input signal and type. The outputs to the subsystem are provided by the argument to a structure named data-typed variables reflecting each subsystem output signal and type. The following overall steps need to be taken to invoke the subsystem function: C Fixed-Point Arithmetic Fixed-point calculations provide significant advantages over floating-point...
  • Page 44 However, you can write functions in assembly © National Instruments Corporation The default and most commonly used one is the macro interface where the fixed-point operations are encoded as macros.
  • Page 45: Generated Code With Fixed-Point Variables

    Chapter 2 C Language Reference 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 using fixed-point variables—such as the examples provided in this chapter—will differ from code generated for models using floating-point, integer, or logical signals in the following areas:...
  • Page 46 RT_SSHORT13 SS13; RT_SSHORT15 SS15; RT_SSHORT15 SS15_1; RT_USHORT14 US14; RT_USHORT10 US10; RT_SSHORT13 SS13_1; RT_SSHORT12 SS12; RT_SSHORT08 SS8; © National Instruments Corporation Table 2-6. AutoCode/C Data Types (Continued) Number Signed or of Bits Unsigned unsigned RT_USHORT (radix 00) RT_USHORTxx (xx = radix 48 to –16)
  • Page 47: User Types

    Chapter 2 C Language Reference 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_FLOAT ExtIn [NUMIN+1]; static RT_FLOAT ExtOut [NUMOUT+1]; /******** Procedures’ declarations ********/ /******* Procedure: proc *******/ /***** Inputs type declaration.
  • Page 48: Overflow Protection

    The default is to generate protected macros. Stand-Alone Files All of the stand-alone files, with the exception of common prefix © National Instruments Corporation Chapter 2 statements in the generated C code. For typedef section and the...
  • Page 49: Macro Interface

    Chapter 2 C Language Reference Macro Interface The macro interface files are: sa_types.h sa_fx.h sa_fxp.h sa_fxr.h sa_fxm.h sa_fxmp.h sa_fx_temps.h sa_fxprv.h sa_fxscale.h sa_fxlimit.h sa_fxadd_byte.c sa_fxadd_short.c sa_fxadd_long.c sa_fxsub_byte.c sa_fxsub_short.c sa_fxsub_long.c sa_fxmul_long.c sa_fxdiv_long.c AutoCode Reference Updated to include fixed-point types. Contains fixed-point conversion macros. Contains fixed-point conversion macros with overflow protection.
  • Page 50: Function Interface

    © National Instruments Corporation Chapter 2 Contains definitions for extern variables such as mask buffers that are read only. Updated to include fixed-point types. Contains fixed-point conversion macros with overflow protection. Contains fixed-point relational macros.
  • Page 51 Chapter 2 C Language Reference sa_fxsub_byte.c sa_fxsub_short.c sa_fxsub_long.c sa_fxmul_byte.c sa_fxmul_short.c sa_fxmul_long.c sa_fxdiv_byte.c sa_fxdiv_short.c sa_fx_f.c sa_fxp_f.c sa_fxm_f.c sa_fxdiv_long.c sa_fx_externs.c These stand-alone files have naming conventions based on the functionality of the macros and whether or not the macros support overflow protection. Refer to the contains macros performing arithmetic functions that do not have overflow protection, but file...
  • Page 52: Fixed-Point Conversion And Arithmetic Macros

    #define SHRsbpt(x,y) ((x) >> (y)) #define SHRsspt(x,y) ((x) >> (y)) #define SHRslpt(x,y) ((x) >> (y)) © National Instruments Corporation Conversion macros that convert one type of number to another. Refer to the Conversion Macros section. Arithmetic macros that perform addition, subtraction, multiplication, or division.
  • Page 53 Chapter 2 C Language Reference Figures 2-6 through 2-8 show how the conversion macros are named. Notice that macro names have no embedded spaces. sr wr ALIGN so wo p q(n, rp) For example, the macro to convert an unsigned 8-bit number to a signed 8-bit number with a shift of sbALIGNubp(n,rp) AutoCode Reference...
  • Page 54 Figure 2-8. AutoCode/C Conversion Macros for Integer-to-Fixed Conversions For example, the macro to convert an integer number to a signed 8-bit number with a shift of sbALIGNip(n,rp) © National Instruments Corporation Chapter 2 n = Fixed-point operand to align rp = Number of bits to shift (if rp <...
  • Page 55: Arithmetic Macros

    Chapter 2 C Language Reference 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 macros that are defined either in whether or not they are overflow protected. The macros for addition and subtraction also make use of addition and subtraction functions defined in sa_fxmp.c Figure 2-9 shows how the arithmetic macros are named.
  • Page 56: Operation

    The macro to multiply two 16-bit signed numbers with overflow protection and produce a 16-bit signed result is: ssMUL_ss_ssp(n1,n2,rp1,rp2,rp3) The macro to divide two 32-bit signed numbers with overflow protection and produce a 32-bit signed result is: slDIV_sl_slp(n1,n2,rp1,rp2,rp3) © National Instruments Corporation Operand 2 Size byte byte short short...
  • Page 57: Implementation Of The Addition And Subtraction Macros

    Chapter 2 C Language Reference Implementation of the Addition and Subtraction Macros AutoCode has two implementations of the addition and subtraction macros: • • For example, when using wordsize extension in an 8-bit processor, addition of two 8-bit operands results in a 16-bit addition operation, because the 8-bit addition macro internally extends the wordsize of the operands from 8 bits to 16 bits.
  • Page 58 Detect overflow before aligning to radix position 7, correct overflow (that is, use maximum number possible) 0^1111111 0^1111111 — © National Instruments Corporation to the radix position of the result left by three bits, and shift , and store the result in n1' = (136,r7) n2' = (128,r7) , decimal value = .0625)
  • Page 59: Selecting Wordsize Extension In The Preprocessor Macro

    Chapter 2 C Language Reference 0^1111111 (n2' = (127,r7) ___________ 0^0000000 (n3 = (0,r7) In Example 2-3, method 1 is more accurate than method 2, but it is also less efficient because it involves a 16-bit subtraction. This is important for those using 8-bit processors but will probably not be as significant for those using 16-bit or 32-bit processors.
  • Page 60: 32-Bit Division

    – (r2) – (r3) where it will be a fast-shift-based division. The iterative division method is costly © National Instruments Corporation be the dividend with radix value , and be the result with radix value ≤...
  • Page 61: Fixed-Point Relational Macros

    Chapter 2 C Language Reference 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 division macros, refer to the SystemBuild User Guide.
  • Page 62: Some Relevant Issues

    Some Relevant Issues • • • © National Instruments Corporation The fixed-point macros used by AutoCode-generated files are defined in the files and are available to you for making modifications. If the AutoCode macros are changed, the results might not match the Sim results.
  • Page 63: Ada Language Reference

    Table 3-1, try one of the versions identified for your platform type. If the code compiles, it will most likely work. The names of the run-time environments correspond to the names of directories within the AutoCode distribution. © National Instruments Corporation AutoCode Reference...
  • Page 64: Supplied Templates

    Chapter 3 Ada Language Reference Solaris, UNIX HP-UX/DOS Windows 2000/NT/9x/DOS Supplied Templates ada_rt.tpl Template template uses Ada tasks to implement the scheduling mechanism for the model. This template supports fixed-point arithmetic. ada_sim.tpl Template scheduler. The subsystems and procedures of a model execute as fast as possible.
  • Page 65: Stand-Alone Library

    Notes: SA files for Alsys Ada compiler. Directory: Files: Notes: SA files for VERDIX Ada compiler. © National Instruments Corporation ) files supplied with your system. Specification files have the suffix systems. Body files have the suffix Table 3-2. Distribution Directories and Files...
  • Page 66 Chapter 3 Ada Language Reference Table 3-2. Distribution Directories and Files (Continued) Category Templates Directory: $CASE/ACA/templates Templates: ada_intgr.tpl Compiled Template: ada_sim.dac Demos Directory: • • • • • For use with generated Ada code, mathematical functions are supplied in functions that are needed to support AutoCode/Ada generated programs can be found in the AutoCode/Ada supplied package These functions are required even if they are supported by your native Ada AutoCode Reference...
  • Page 67: Data Types

    Certain global record, array, and exception types are also defined in this file. The record type sa_types_.a/.ada © National Instruments Corporation . The MATH_LIB sa_time.a/.ada function.
  • Page 68: Target-Specific Utilities

    Chapter 3 Ada Language Reference Target-Specific Utilities The target-specific utilities in the perform hardware-, application-, and Ada-specific tasks that are required for simulation and testing. They can be modified to support the generated code on the target computer. As furnished, these routines simulate I/O operations that would occur in a simulation environment, using import files created using MATRIXx.
  • Page 69: Enable( ), Disable( ), And Background( ) Procedures

    Math Error encountered in task n Check your model for possible overflows, divisions by zero, and so on. User code error encountered in task n © National Instruments Corporation Post external outputs. Multiprocessor implementations only; signal secondary processors that a dispatch table is available.
  • Page 70: Implementation_Initialize( ) Procedure

    Chapter 3 Ada Language Reference 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.
  • Page 71 *** First time point must be zero. An input time vector must start at zero. *** Time vector size exceeds storage limit. *** Input array size exceeds storage limit. © National Instruments Corporation Chapter 3 sa_utils.a/.ada procedure. file are listed below. These messages pertain to the...
  • Page 72: Implementation_Terminate( ) Procedure

    Chapter 3 Ada Language Reference 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 very beginning of the stand-alone utilities file, just after the trademark notice.
  • Page 73: External_Output( ) Procedure

    ( The computations performed by UCBs can update both block states and outputs. © National Instruments Corporation is much the same; it returns an input vector from External_Input( ) , which is passed to it by the scheduler.
  • Page 74: Calling Ucbs

    Chapter 3 Ada Language Reference 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(U'first), U(U'first+1), ...
  • Page 75 To link UCBs (either handwritten or generated) with generated scheduled subsystem code, compile the UCBs, required scheduled subsystem code and link them together to build an application. © National Instruments Corporation An array of integer parameters. The number of integer parameters.
  • Page 76: Procedure Superblocks

    Chapter 3 Ada Language Reference 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 AutoCode User Guide. You have an option to call the generated algorithmic procedures directly (refer to Example 3-1), passing it pointers to record objects as arguments, or you can call the hook routine with a fixed UCB calling style interface, passing it arguments, which are arrays and values.
  • Page 77 : in out RT_FLOAT_AY; : in : in out RT_FLOAT_AY; : in : in out RT_FLOAT_AY; : in out RT_INTEGER_AY) is begin myproc(ptr_of(myproc_12_u'address), ptr_of(myproc_12_y'address), ptr_of(myproc_12_i'address)); end myproc_hook; © National Instruments Corporation use myproc_pkg; RT_DURATION; RT_FLOAT_AY; RT_INTEGER; RT_FLOAT_AY; RT_INTEGER; RT_INTEGER; 3-15 Chapter 3...
  • Page 78: Ada Fixed-Point Arithmetic

    Chapter 3 Ada Language Reference 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 arithmetic chapter that explains the basics of fixed-point arithmetic and the use of fixed-point arithmetic in SystemBuild models.
  • Page 79: Fixed-Point Data Types

    The file name convention uses an underscore before the extension to denote a file containing a package specification. extension is arbitrary as different platforms use different extensions, like © National Instruments Corporation –radix . Thus, a fixed-point type with a delta of 0.125 is a fixed-point type .
  • Page 80: Package Dependencies

    Chapter 3 Ada Language Reference 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. Figure 3-1 illustrates the imposed dependency. In the figure, a package that is beneath a package and connected to a package above it by an arrow is said to be dependent on the package that is above.
  • Page 81: Generated Code With Fixed-Point Variables

    The package name must be used to refer to a user type for declaring variables. © National Instruments Corporation The package name must be used when referring to a fixed-point type. Explicitly defined conversion functions are used to convert a fixed-point value to any other numeric type.
  • Page 82: System-Level Parameters To Generate User Types

    Chapter 3 Ada Language Reference System-Level Parameters to Generate User Types Table 3-6 describes new system-level parameters that are used to generate n_user_defined_type_i usertype_name_ls usertype_basename_ls Overflow Protection Overflow is defined as loss of significance—that is, a computation resulting in a value that cannot be represented in the range of a specific fixed-point type.
  • Page 83: Stand-Alone Files

    This section illustrates the steps required to generate and compile a model that includes fixed-point types. For the purpose of this example, assume a top-level superblock name of © National Instruments Corporation Table 3-7. Fixed-Point Stand-Alone Files Package Name gaintest...
  • Page 84 Ada Code Generation and continue. Example 3-2 shows a sample transcript that should appear in the Xmath window during code generation. National Instruments Corporation.* Portions U.S. Patent. Compile the stand-alone files—Before compiling the generated Ada code, all of the stand-alone files must be compiled into the Ada Library.
  • Page 85: Fixed-Point Type Declarations

    Table 3-9 summarizes the functions and their purpose. Refer to the package specification for more details. © National Instruments Corporation Compile the generated files—Two source files are generated, gaintest.a fxp_gaintest_.a imposed package dependencies (refer to the...
  • Page 86 Chapter 3 Ada Language Reference FIXED_ADD FIXED_SUB FIXED_MUL FIXED_DIV FIXED_IDENTITY SIGNEDNEGATION UNSIGNEDNEGATION SIGNEDABS UNSIGNEDABS LESSTHAN GREATERTHAN LESSEQUAL GREATEREQUAL INTCAST INTCAST_TRUNC INTCAST_ROUND AutoCode Reference Table 3-9. Generic Function Summary Function Name Addition of two fixed-point values. Subtraction of two fixed-point values. Multiplication of two fixed-point values.
  • Page 87 BOOLEANCAST INTFIXEDCAST LONGINTFIXEDCAST BOOLEANFIXEDCAST FLOATFIXEDCAST FLOATFIXEDCAST_TRUNC FLOATFIXEDCAST_ROUND FIXED_CAST FIXED_CAST_TRUNC FIXED_CAST_ROUND NOOPCAST © National Instruments Corporation Table 3-9. Generic Function Summary (Continued) Function Name Fixed-point value to RT_LONG_INTEGER Fixed-point value to RT_LONG_INTEGER truncation. Fixed-point value to RT_LONG_INTEGER rounding. Fixed-point value to conversion.
  • Page 88: Bit-Wise Functions

    Chapter 3 Ada Language Reference 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 three functions: value. The functions are overloaded to accept values that are of a fixed-point type with radix 0.
  • Page 89: Conversion Function Instantiations

    Fixed to Fixed (different types) Fixed to Fixed (different types, truncation) Fixed to Fixed (different types, round) Fixed to Fixed (same type, no-op cast) © National Instruments Corporation package contains instantiations of functions RT_FIXED_OPERATORS Table 3-10. Conversion Function Naming Conventions...
  • Page 90: Sample Package

    Sample Package Example 3-3 shows a generated Example 3-3 Generated RT_FIXED_OPERATORS Package --------------------------------------------------------------------------- AutoCode/Ada (TM) Code Generator 7.X National Instruments Corporation, Austin, Texas --------------------------------------------------------------------------- -- rtf filename -- Filename -- Dac filename -- Generated on -- Dac file created on Fixed Point Operator Instantiation Package with SA_TYPES;...
  • Page 91: Addition And Subtraction Functions

    The two operands are converted to the intermediate type (IT), and then the operation is performed. Then, the result is converted to the result type RESULT_TYPE result type. © National Instruments Corporation generic functions implement addition FIXED_ADD FIXED_SUB ). Loss of significance can occur when converting to the...
  • Page 92 Chapter 3 Ada Language Reference 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 can be used to represent model numbers.
  • Page 93: Multiplication And Division Functions

    RT_SSHORT03 However, when converting a value that has a type of greater accuracy to a type that has a lesser accuracy, loss of precision will occur, but there is © National Instruments Corporation Chapter 3 RT_SSHORT01 will not lose accuracy, unless the value overflows.
  • Page 94: Language-Defined Conversion

    Chapter 3 Ada Language Reference no chance of overflow. To support these issues there are three types of conversion functions: • • • These conversions are described in the following sections. Language-Defined Conversion The Ada language provides four data type conversions. The rules in Ada that govern the conversion are explicit except for one detail.
  • Page 95: Using System-Level Parameters To Generate Instantiations

    After all of the subsystems and procedures are generated, you must call the subsystem or procedure is scoped, all of the © National Instruments Corporation function collect_fxpdata( ) parameters are empty. After being called, all of the operators and...
  • Page 96: System Scope Operators And Conversions

    Chapter 3 Ada Language Reference The data in the used in the currently scoped subsystem or procedure. No assumptions can be made about the order within a given list parameter. However, the nth element in one list does relate to the nth element in another list, depending on the purpose of the lists.
  • Page 97: Known Ada Compiler Problems

    The following examples are possible reasons and solutions for the problem: • • © National Instruments Corporation Round and Truncation—By default, the SystemBuild Simulator performs fixed-point data conversions using truncation as the rounding mode. The Ada language always uses some type of rounding mode other than truncation.
  • Page 98: No-Op Conversion Function

    Chapter 3 Ada Language Reference Toward 0 Away from 0 Positive Infinity Negative Infinity To Odd To Even • • No-Op Conversion Function The purpose of the so-called no-op conversion function is to provide a hint to the compiler to select the proper overloaded operator. Without such a hint, there can be situations where the selection of the appropriate overloaded operator is ambiguous.
  • Page 99 The second assignment is not ambiguous because the TO_SLO function is forcing the there is only one operator that satisfies the second example. © National Instruments Corporation --ambiguous --unambiguous expression function is unary and not overloaded. Therefore, the unary subexpression to return a SL0 result.
  • Page 100: Generating Code For Real-Time Operating Systems

    RTOS configuration tables with a focus on our intended usage of the data and template parameters. The RTOS file cannot be used with any of the Note options. -prio © National Instruments Corporation -pmap -smap , or -bmap -imap...
  • Page 101: Table Syntax

    Chapter 4 Generating Code for Real-Time Operating Systems Configuration Items The following is a list of configuration attributes for each type of AutoCode component. • • • • • • • • Table Syntax This section provides information about the RTOS configuration tables. AutoCode Reference Number of processors Scheduler priority...
  • Page 102: Table Naming Convention

    Example 4-1 shows an example of a processors table. Column Data Name Type Integer © National Instruments Corporation Chapter 4 Generating Code for Real-Time Operating Systems . RTOS does not look at the specifier is case sensitive. name Table 4-1. Processors Table Contents...
  • Page 103: Scheduler Priority Table

    Chapter 4 Generating Code for Real-Time Operating Systems Example 4-1 Processors Table Example rtos.processors = 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_priority. Example 4-2 shows an example of a scheduler priority table.
  • Page 104: Interrupt Procedure Superblock Table

    Priority Integer Stack Size Integer Processor Integer Vector Integer Mode Flags String © National Instruments Corporation Chapter 4 Generating Code for Real-Time Operating Systems Stack Size 4096 4096 8192 intrsupblk Table 4-4. Interrupt Table Contents Template Parameter Containing the Data...
  • Page 105: Background Procedure Superblock Table

    Chapter 4 Generating Code for Real-Time Operating Systems Example 4-4 Interrupt Table Example rtos.intrsupblk = Interrupt Priority ---------------------------------------------------------------------- catch_it sigio_io keypad Background Procedure SuperBlock Table Table 4-5 consists of configuration information for all background procedure SuperBlocks in the model. Each row is identified by the name of the SuperBlock.
  • Page 106: Startup Procedure Superblock Table

    IP name. Each row is identified by the processor number. The table is named Column Data Name Type IP Number String © National Instruments Corporation Chapter 4 stupsupblk Table 4-6. Startup Table Contents Template Parameter Containing the Data proc_processor_map_li[] proc_ordering_li[] Ordering .
  • Page 107: Version Table

    Chapter 4 Generating Code for Real-Time Operating Systems Example 4-7 Processor IP Table Example rtos.IPprsrmap = Processor | IP Name -------------------------------------------------------------------- 127.0.0.1 133.65.32.111 Version Table Table 4-8 is a single element table consisting of the version number of the format of the configuration tables. The table is named Example 4-8 shows a version table.
  • Page 108 Refer to the Template Programming Language User Guide for template examples. © National Instruments Corporation Chapter 4 Generating Code for Real-Time Operating Systems AutoCode Reference...
  • Page 109: Generated Code Architecture

    A default name is a combination of the block name and block identification number as found in the diagram. If the block has no name, the enclosing SuperBlock name is used to form the name. © National Instruments Corporation AutoCode Reference...
  • Page 110: Signal Naming

    Chapter 5 Generated Code Architecture 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 not appear.
  • Page 111: Global Storage

    The following is a summary of when the block will execute. • © National Instruments Corporation Read-From Variable Block (ALL Addressing mode)—These blocks execute before any other type of block within the subsystem, procedure, or sequence frame. The data from the variable block is copied into local variables.
  • Page 112: Global Variable Block And %Var Equivalence

    Chapter 5 Generated Code Architecture • • Global Variable Block and %var Equivalence If a Global Variable Block and a %var use the same name, only one variable is generated and that variable will be used for all instances of the %var and Variable Block.
  • Page 113: Subsystems

    SuperBlocks identified as one subsystem, and creates a block ordering. As a result, AutoCode knows nothing about SuperBlocks and can generate only what the Analyzer partitioned into subsystems. © National Instruments Corporation Discrete and Continuous SuperBlocks Versus Subsystems Block Ordering...
  • Page 114: Top-Level Superblock

    Chapter 5 Generated Code Architecture 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 translation.
  • Page 115: Scheduler External Interface Layer

    Top-Level SuperBlock. Therefore, data copied into and out of this layer is subject to a data type conversion into the all-float Scheduler interface. © National Instruments Corporation External SUBSYSTEM...
  • Page 116: Discrete Subsystem Interface Layer

    Chapter 5 Generated Code Architecture 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 subsystem external inputs and the other the subsystem external outputs.
  • Page 117: Static Data Within Subsystems

    State data is managed within the subsystem and involves swapping pointers representing the current and next states. © National Instruments Corporation is an array that contains flags that indicate the phase and error iinfo...
  • Page 118: Procedure Data

    Chapter 5 Generated Code Architecture 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 include reusability and reentrancy. Therefore, for each instance of a call to a procedure SuperBlock within a subsystem, a set of static variables is created for each of the structures that describe the definition of the procedure.
  • Page 119: Error Handling

    The following briefly describes the type of structures required for this interface. • • • © National Instruments Corporation option is specified for code generation. Input—Also called the -structure and contains the inputs of the procedure. The inputs are in the order specified in the procedure definition’s external inputs.
  • Page 120: Unrolled Interface

    Chapter 5 Generated Code Architecture Unrolled Interface There is another form of the procedural interface, the unrolled interface No-UY and outputs. The input/output signals are passed as separate arguments to the function. • • • Phases and Error Handling The phases and error handling within a Standard Procedure is equivalent to the implementation within a subsystem.
  • Page 121 _foo_y *Y; struct _foo_info *I; RT_INTEGER *iinfo = &I->iinfo[0]; /***** Output Update. *****/ /* ---------------------------- /* {foo..2} */ Y->foo_2_1 = (*I->GAIN)*U->foo_1; iinfo[1] = 0; © National Instruments Corporation Chapter 5 Gain Block */ 5-13 Generated Code Architecture AutoCode Reference...
  • Page 122 Chapter 5 Generated Code Architecture 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; static struct _foo_y foo_2_y; static struct _foo_info foo_2_i; static struct _foo_u foo_12_u;...
  • Page 123: Procedure Arguments

    The outputs to the procedure are provided by the argument Y, a pointer to a structure named © National Instruments Corporation Chapter 5 Procedure SuperBlock */ . This structure is composed of _ procedure name _u .
  • Page 124 Chapter 5 Generated Code Architecture 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 double-buffered private states used in the procedure, a flag to toggle the private states from one buffer to another, and the states structures of all procedures nested in the procedure.
  • Page 125 _ procedure name _info after the Xmath variables used. You need to initialize these pointers. © National Instruments Corporation Table 5-1. Description of Element iinfo in Structure _procedure name_info Error flag.
  • Page 126: Extended Procedure Information Structure

    Chapter 5 Generated Code Architecture Extended Procedure Information Structure procedure SuperBlock’s only one additional element is generated. It is named type declaration (in C) with and without the are declared when generating Ada code. Example 5-2 Regular Procedure struct _proc1_info { RT_INTEGER iinfo[5];...
  • Page 127: Compatibility Issues

    The old procedure will have been generated without the existence of the new element and thus its presence in the structure will not affect the previously generated code as that code never references it. Its effect, © National Instruments Corporation Table 5-3. Procedure Ordering Task/Procedure element.
  • Page 128: Macro Procedure

    Chapter 5 Generated Code Architecture however, is to create additional space when declaring a variable of the structure’s type and for the new code generated with the which assumes the field exists in all procedure the old procedure cannot call a procedure generated with the extended field in the without the extended structure, it is not possible to generate valid code if Macro Procedure...
  • Page 129: Asynchronous Procedures

    = 0.0 but after all of the subsystems have executed their PREINIT phase. © National Instruments Corporation There are no external inputs and no external outputs. Dynamic blocks, that is, blocks with explicit states, are not supported.
  • Page 130: Changing %Var Values During Startup

    Chapter 5 Generated Code Architecture 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 variations of the Condition Block: Default, No-Default, and Sequential.
  • Page 131: Inputs And Outputs

    : data; outputs: control; float data(:), control(data.size); © National Instruments Corporation Create the names of the variables to be used as inputs and outputs. The order of this signature is critical as it provides a mapping to the input/output pins of the block.
  • Page 132: Environment Variables

    Chapter 5 Generated Code Architecture 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 follows as an array of floats representing pins 7 through 10.
  • Page 133: Init, Output, And State Phases

    = 0.0 for the Init/Output phase, whereas the AutoCode simulation only executes the time = 0.0 Init/Output phase once. Refer to the INITMODE option for the SystemBuild Simulator for more information about its initialization behavior. © National Instruments Corporation Init—The intent is to initialize any local, output, state, or parameter variable.
  • Page 134: Default Phase

    Chapter 5 Generated Code Architecture 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 is generated in the State phase.
  • Page 135: Local Variables And Phases

    Environment: (INIT, OUTPUT, STATE); States: current_total; Next_States: new_total; float u,y,current_total, new_total; if OUTPUT then if INIT then current_total = 0.0; endif; y = u + current_total; endif; if STATE then © National Instruments Corporation Chapter 5 5-27 Generated Code Architecture AutoCode Reference...
  • Page 136 Chapter 5 Generated Code Architecture 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}}; /***** Current and Next States Pointers. *****/ static struct _Subsys_1_states *X = &ss_1_states[0];...
  • Page 137: Continuous Semantics

    Parameters and local variables of the BlockScript can be either scalar or arrays. This means that only hard-subscripts can be used with inputs, outputs, and states for scalar code generation. © National Instruments Corporation Chapter 5 5-29 Generated Code Architecture...
  • Page 138: Rolling Loops With Scalar Code Generation

    Chapter 5 Generated Code Architecture In Example 5-9, a hard-subscript, outputs. The reason the values of 1 through to the number of inputs ( the code is generated. AutoCode then can unroll the loop so as to translate y(i) Example 5-9 Hard-Subscript Used to Access an Array Inputs: Outputs: y;...
  • Page 139: Vectorized Code

    • © National Instruments Corporation Generation) and at the most basic level, it means that arrays will be Loop—Always generate a rolled loop for both scalar and WHILE vectorized code.
  • Page 140: Examples Of Rolled And Unrolled Loops

    Chapter 5 Generated Code Architecture • Loop Type WHILE Loop Type WHILE Examples of Rolled and Unrolled Loops Example 5-12 Unrolled Loop from Example 5-9 /***** Output Update. *****/ /* ---------------------------- /* {bsb..2} */ bsb_1 = indata_1 * 2; bsb_2 = indata_2 * 4; bsb_3 = indata_3 * 6;...
  • Page 141: Parameters

    National Instruments does not recommend that you replace all uses of states with Note parameters. Rather, this section points out a special-case method to code a BlockScript block to produce more efficient code for simple cases of persistent data.
  • Page 142 Chapter 5 Generated Code Architecture 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;...
  • Page 143: Optimizations

    = 0.001; if threshold < 0.005 then for i = 1:y.size do y(i) = u(i) / threshold; endfor; else © National Instruments Corporation Chapter 5 statements. If the guard of the 5-35 Generated Code Architecture option for statement...
  • Page 144: Implicit Type Conversion

    Chapter 5 Generated Code Architecture 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. *****/ /* ---------------------------- /* {deadbsb..2} */ for (i=1; i<=5; i++) { deadbsb[-1+i] = U->deadbsb[-1+i]/0.001; Notice that in the generated code, only the true-branch of the BlockScript hard-coded.
  • Page 145: Usercode Block

    This is exactly what is meant with indirect terms and this warning will not cause a computational error, assuming the UCB obeys its own indirect term specification. © National Instruments Corporation UCBs intended to be linked directly back into the SystemBuild Simulator...
  • Page 146: Parameterized Ucb Callout

    Chapter 5 Generated Code Architecture Parameterized UCB Callout A UCB can be defined with %var parameterized data for the UCB’s real parameters ( generates code that passes the %var variable as the actual of the UCB callout. A new option, subsystem code and passes the temporary arrays as actuals of the UCB callout.
  • Page 147: Software Constructs

    AutoCode implements this construct as a while statement in C and as a loop statement in Ada. © National Instruments Corporation IfThenElse Blocks (for conditional execution) WHILE Blocks (for iterative computations)
  • Page 148: Break Block

    Chapter 5 Generated Code Architecture 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 input to the BREAK Block is TRUE, then the loop that is immediately enclosing the BREAK Block is exited.
  • Page 149: Sequencer Block

    This limitation is required to prevent unexpected results of the execution order. From a continuous point of view, the continuous subsystem is © National Instruments Corporation Chapter 5 Code Optimization, for more details...
  • Page 150: Explicit Phases

    Chapter 5 Generated Code Architecture 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 subsystems or procedures introduces arbitrary boundaries within the equation sorting that can affect the stability of the total system.
  • Page 151: Multiprocessor Code Generation

    Sample and Hold Phase of Subsystem 1 subsys_1_in.throttle = ss5_outr->throttle; subsys_1_in.Brake = mbuf->sys_extin.Brake; subsys_1_in.PDown = mbuf->sys_extin.PDown; © National Instruments Corporation Algebraic loops are not supported. AutoCode only performs a single initialization pass at time = 0.0. This corresponds to the SystemBuild Simulation options of...
  • Page 152: Distributed Memory Architecture

    Chapter 5 Generated Code Architecture 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, and passes all of the necessary data to the callout.
  • Page 153: Mapping Command Options

    The following list presents the terms commonly used when referring to the shared memory callouts. • • • • • • © National Instruments Corporation Copy a block of local data into shared data: UPDATE_MBUF_WITH_LOCBLK(dest,src,size) Copy shared data into local data: GET_LOCF_FROM_MBUFF(dest,src) GET_LOCB_FROM_MBUFB(dest,src) GET_LOCI_FROM_MBUFI(dest,src) GET_LOCF_FROM_MBUFI(dest,src)
  • Page 154: Shared Memory Fixed-Point Callouts In Autocode/C

    Chapter 5 Generated Code Architecture • • 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_LOCSBYTE(x, y) The value of the local variable shared memory variable assume that the data type of Shared Memory Fixed-Point Callouts in AutoCode/C...
  • Page 155: Shared Variable Block Support

    It is your responsibility to create the pointers, data structures, and shared memory region for the multiprocessor target hardware. Also, use the variable block callouts to ensure coherency of the shared data. © National Instruments Corporation convert_macro_name -smco ). This is to provide indirection into the shared memory...
  • Page 156 Chapter 5 Generated Code Architecture 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 Template Code to Generate Required Shared Variable Block Structures @IFF multiprocessor_b@@ @shared_count = 0@@ /****...
  • Page 157 Enter_Shared_Varblk_Section(4); isi_varblk[0]->block5[0] = proc2_4_1; isi_varblk[0]->block5[1] = proc2_4_2; Leave_Shared_Varblk_Section(4); © National Instruments Corporation #pragmas Create a structure (record) containing the name and data type of the shared variable blocks in the model. This structure should be visible to the code on each processor, or must be declared static. The source file(s) for each processor must have a declaration of the structure.
  • Page 158: Shared Memory Callout Option

    Chapter 5 Generated Code Architecture Shared Memory Callout Option AutoCode supports a shared memory callout for all access to elements in shared memory. Callouts are generated when the The previous discussion about shared variable blocks still applies. However, the generated code is different, and you must supply the definitions of the callouts.
  • Page 159: Global Variable Block Callouts

    Entering Non-Shared (Local) Critical Section The prototype of the callout for entering a non-shared global variable block critical section is: void Enter_Local_Varblk_Section(RT_INTEGER index); procedure Enter_Local_Varblk_Section(index : RT_INTEGER); © National Instruments Corporation Chapter 5 option is used. -epi 5-51 Generated Code Architecture...
  • Page 160 Chapter 5 Generated Code Architecture The formal argument represents the global reference number for which the variable block is being accessed. The default implementation of those simply calls the Leaving Non-Shared (Local) Critical Section The prototype of the callout for leaving a non-shared global variable block critical section is: void Leave_Local_Varblk_Section(RT_INTEGER index);...
  • Page 161: Shared Global Variable Blocks

    The prototype of the callout for leaving a local variable block critical section is: void Leave_Shared_Varblk_Section(RT_INTEGER processor, RT_INTEGER index); procedure Leave_Shared_Varblk_Section(processor : RT_INTEGER; © National Instruments Corporation , represents a unique identifier for the caller. The default Enter_Local_Varblk... options. -epi proc2_4_1 = block5[0];...
  • Page 162 Chapter 5 Generated Code Architecture 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. The following code uses the shared variable block generated code with callouts, using the Enter_Shared_Varblk_Section(1, 4);...
  • Page 163 It is not possible to mix code with shared variable blocks generated with the option and code with shared variable blocks generation without -epi prototypes of the shared variable block callouts are the same. © National Instruments Corporation Enter_Shared_Varblk... options. proc2_4_1 = isi_varblk[0]->block5[0];...
  • Page 164: Vectorized Code Generation

    For this example, assume a 10 input/output gain block with various gain parameters connected directly to the subsystem external input and output. © National Instruments Corporation Signals are represented as arrays instead of scalars in the generated code...
  • Page 165: Scalar Gain Block Example

    Chapter 6 Vectorized Code Generation 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 iinfo[4]; /******* Initialization.
  • Page 166: Vectorized Gain Block Example

    RT_FLOAT _R_P[10] = {1.2, 2.3, 3.4, 4.5, 5.6, 6.7, /***** Algorithmic Local Variables. *****/ RT_INTEGER i; /******* Initialization. *******/ © National Instruments Corporation Y(i) is the ith output U(i) is the ith input GainParameter(i) is the ith gain value i is the range <1..x>, where x is the number of outputs of the block...
  • Page 167: Array Subscripts

    Chapter 6 Vectorized Code Generation if (SUBSYS_PREINIT[1]) { iinfo[0] = 0; iinfo[1] = 1; iinfo[2] = 1; iinfo[3] = 1; for( cnt=0;cnt<10;cnt++ ) { R_P[cnt] = _R_P[cnt]; SUBSYS_PREINIT[1] = FALSE; return; /***** Output Update. *****/ /* ---------------------------- /* {gain..2} */ for (i=1;...
  • Page 168: Signal Connectivity

    The diagram in Figure 6-1 represents poor input connectivity that prevents a rolled loop. Refer to Example 6-3. © National Instruments Corporation Chapter 6 Vectorized Code Generation...
  • Page 169 Chapter 6 Vectorized Code Generation 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. *****/ static RT_FLOAT R_P[5]; RT_INTEGER cnt; static const RT_FLOAT _R_P[5] = {1.2, 2.3, 3.4, 4.5, 5.6}; /***** Algorithmic Local Variables.
  • Page 170: Vectorization Modes

    This vectorization mode (mode code generation within the same system. This mode also is called vector-by-label because the labels/names of the signals determine if a vector is generated. © National Instruments Corporation Chapter 6 Gain Block */ , where is the mode. The vectorization...
  • Page 171: Vector Labels And Names

    Chapter 6 Vectorized Code Generation 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 of which pins are to be an array.
  • Page 172 /***** States type declaration. *****/ struct _Subsys_1_states { RT_FLOAT sensor_delay[5]; 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]; © National Instruments Corporation Chapter 6 Figure 6-2. Example Model Diagram Vectorized Code Generation AutoCode Reference...
  • Page 173 Chapter 6 Vectorized Code Generation 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; static const RT_FLOAT _R_P[11] = {0.1, 0.0, 0.0, 0.0, 0.0, /***** Local Block Outputs.
  • Page 174 = k + 1; /***** Swap state pointers. *****/ XTMP = X; X = XD; XD = XTMP; INIT = 0; © National Instruments Corporation Chapter 6 Time Delay */ Gain Block */ Time Delay */ 6-11 Vectorized Code Generation...
  • Page 175 Chapter 6 Vectorized Code Generation 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_FLOAT sensor_12; RT_FLOAT sensor_4; RT_FLOAT sensor_1; /***** States type declaration. *****/ struct _Subsys_1_states { RT_FLOAT sensor_delay[5];...
  • Page 176 SUBSYS_PREINIT[1] = FALSE; return; /***** Output Update. *****/ /* ---------------------------- /* {VecEx..12} */ if (INIT) { k = 0; for (i=1; i<=5; i++) { X->sensor_delay[k] = R_P[i]; © National Instruments Corporation Chapter 6 Time Delay */ 6-13 Vectorized Code Generation AutoCode Reference...
  • Page 177: Vectorization Features

    Chapter 6 Vectorized Code Generation k = k + 1; k = 1; for (i=1; i<=5; i++) { Y->delayed_pulse[-1+i] = X->sensor_delay[-1+k]; k = k + 1; /* ---------------------------- /* {VecEx..2} */ Throttle = -8.7*U->sensor_5; Pedal = -7.6*U->sensor_11; Brake = -6.5*U->sensor_12; Gear = -5.4*U->sensor_4;...
  • Page 178: Multiple Arrays Within A Block

    RT_INTEGER iinfo[4]; /***** Parameters. *****/ static RT_FLOAT R_P[20]; RT_INTEGER cnt; static const RT_FLOAT _R_P[20] = {1.2, 2.3, 3.4, 4.5, 5.6, © National Instruments Corporation Chapter 6 Figure 6-3. Multiple Array Mode 1.2, 2.3, 3.4, 4.5, 5.6, 6-15 Vectorized Code Generation...
  • Page 179 Chapter 6 Vectorized Code Generation /***** Local Block Outputs. *****/ RT_FLOAT top[5]; RT_FLOAT bottom[5]; /***** Algorithmic Local Variables. *****/ RT_INTEGER i; /******* Initialization. *******/ if (SUBSYS_PREINIT[1]) { iinfo[0] = 0; iinfo[1] = 1; iinfo[2] = 1; iinfo[3] = 1; for( cnt=0;cnt<20;cnt++ ) { R_P[cnt] = _R_P[cnt];...
  • Page 180: Split-Merge Inefficiency

    Hence, one would say that you are using a split vector. Consider the diagram in Figure 6-4 and the generated code in Example 6-7. © National Instruments Corporation Chapter 6 gain..99...
  • Page 181 Chapter 6 Vectorized Code Generation Example 6-7 Generated Code for Split Vector (for Figure 6-4) /***** Output Update. *****/ /* ---------------------------- /* {gain.top.2} */ for (i=1; i<=5; i++) { top[-1+i] = R_P[-1+i]*U->gain_1[-1+i]; /* ---------------------------- /* {gain.bottom.1} */ for (i=1; i<=5; i++) { bottom[-1+i] = R_P[4+i]*U->gain_1[4+i];...
  • Page 182: Merge

    Consider the model shown in Figure 6-5 that is similar to Example 6-7, and the generated code in Example 6-8. © National Instruments Corporation Change the design so that the inputs naturally form the array, that is, merging multiple blocks into one block.
  • Page 183 Chapter 6 Vectorized Code Generation Example 6-8 Generated Code (for Figure 6-5) /***** Output Update. *****/ /* ---------------------------- /* {gain.top.2} */ for (i=1; i<=5; i++) { top[-1+i] = R_P[-1+i]*U->gain_1[-1+i]; /* ---------------------------- /* {gain.bottom.1} */ for (i=1; i<=5; i++) { bottom[-1+i] = R_P[4+i]*U->gain_1[4+i]; /* ---------------------------- /* {gain.merge.12} */ merged_data[0] = top[2];...
  • Page 184: External Outputs

    AutoCode preserves the array for the gain block, but copies the pieces of the array that are external output into the -structure. © National Instruments Corporation Chapter 6 -structure. It contains only those -structure instead of using local storage.
  • Page 185 Chapter 6 Vectorized Code Generation 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. *****/ /* ---------------------------- /* {gain.top.2} */ for (i=1; i<=5; i++) { top[-1+i] = R_P[-1+i]*U->gain_1[-1+i];...
  • Page 186: Eliminating Copy-Back

    Figure 6-7 shows an example of this feature, and Example 6-10 shows the code generated. © National Instruments Corporation Use Mixed Vectorization mode and force scalars to be used for the block is sparse external outputs. This eliminates rolling of the block algorithm while eliminating the copy.
  • Page 187 Chapter 6 Vectorized Code Generation 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_info *I; /**** some code deleted ****/ /***** Output Update. *****/ /* ---------------------------- /* {vecproc..2} */ for (i=1;...
  • Page 188: Ada Array Aggregates And Slices

    ------ Algorithmic Local Variables. ------ i_1 : RT_INTEGER; j : RT_INTEGER; k_1 : RT_INTEGER; begin -------- Initialization. -------- if SUBSYS_PREINIT(1) then iinfo(0..3) := (0,1,1,1); © National Instruments Corporation Chapter 6 Procedure Super Block */ 6-25 Vectorized Code Generation AutoCode Reference...
  • Page 189 Chapter 6 Vectorized Code Generation 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; SUBSYS_PREINIT(1) := FALSE; return; end if;...
  • Page 190: Vectorization Of The Blockscript Block

    • For more information about the BlockScript block, refer to the Block © National Instruments Corporation It is an error to use both soft-subscript and scalar code generation. Only 8-nested loops are supported. Bounds checks are not performed for a soft-subscript array access.
  • Page 191: Matrix Outputs

    Chapter 6 Vectorized Code Generation 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 vector-labeled block are identical, provided the number of elements in the matrix matches the number in the vector.
  • Page 192: Code Optimization

    Example 7-1 Code Generated without Variable Block Optimization /* Model variable definitions */ RT_FLOAT var; RT_FLOAT var1; void subsys_1(U,Y) struct _Sys_ExtIn *U; struct _Subsys_1_out *Y; © National Instruments Corporation Vectorized Code Generation, explains the first step in this AutoCode Reference...
  • Page 193 Chapter 7 Code Optimization 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_PREINIT[1] = FALSE; return; /***** Output Update.
  • Page 194 = new_12_1; /* ---------------------------- /* {new..5} */ Y->new_5_1 = U->new_1 - new_11_1; if (iinfo[1]) { SUBSYS_INIT[1] = FALSE; © National Instruments Corporation Chapter 7 Read from Variable */ Read from Variable */ Sum of Vectors */ Write to Variable */...
  • Page 195 Chapter 7 Code Optimization 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. AutoCode looks for the presence of a write-to-the-same-variable block between the Read from Variable block statement and its use in later computations.
  • Page 196: Restart Capability

    /***** Parameters. *****/ static RT_FLOAT R_P[8]; RT_INTEGER cnt; © National Instruments Corporation 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.
  • Page 197 Chapter 7 Code Optimization 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 iupper; RT_FLOAT uval; RT_INTEGER k; RT_FLOAT alpha;...
  • Page 198 /***** Algorithmic Local Variables. *****/ RT_INTEGER ilower; RT_INTEGER iupper; RT_FLOAT uval; RT_INTEGER k; RT_FLOAT alpha; © National Instruments Corporation and the initialization code are optimized away. Instead, the _R_P (parameter array), states, derivatives, and Chapter 7 Code Optimization structures are...
  • Page 199: Merging Init Sections

    Chapter 7 Code Optimization 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 procedure is called.
  • Page 200 = 0; iinfo[1] = 1; iinfo[2] = 1; iinfo[3] = 1; X = &ss_1_states[0]; XD = &ss_1_states[1]; © National Instruments Corporation Time Delay */ Time Delay */ Sum of Vectors */ Gain Block */ Sum of Vectors */ Gain Block */...
  • Page 201 Chapter 7 Code Optimization X->proc_22_S1 = 0.0; X->proc_24_S1 = 0.0; XD->proc_22_S1 = 0.0; XD->proc_24_S1 = 0.0; /* ---------------------------- /* {proc..22} */ X->proc_22_S1 = 0.0; /* ---------------------------- /* {proc..24} */ X->proc_24_S1 = 0.0; SUBSYS_PREINIT[1] = FALSE; return; /***** Output Update. *****/ /* ---------------------------- /* {proc..22} */ proc_22_1 = X->proc_22_S1;...
  • Page 202: Reuse Of Temporary Block Outputs

    Again, a temporary variable is reused only if it is not needed in any further computations. The command-line option brings about this optimization. © National Instruments Corporation Reuse whenever specified (by the user) Maximal reuse (reuse whenever possible)
  • Page 203 Chapter 7 Code Optimization 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_FLOAT model_2_1;...
  • Page 204: Constant Propagation

    (cannot propagate constants), are from other palettes such as DYN, SGN, and NTP. These blocks do not propagate outputs even if all of their inputs are constants. Code is generated for such blocks. © National Instruments Corporation Gain Block */ Sum of Vectors */...
  • Page 205 Chapter 7 Code Optimization 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 limitation to this optimization is that a block cannot propagate constants or even accept constants as inputs if its inputs or outputs contain vectors.
  • Page 206 As all of the inputs to the summation block are constants (5 and 3), AutoCode computes the output of the summation block at code generation time ( © National Instruments Corporation Algebraic Expression */ Algebraic Expression */...
  • Page 207: Optimizing With Matrix Blocks

    Chapter 7 Code Optimization input of the gain block and the expression 4 as the value of value 4. The command-line option for invoking this optimization is Optimizing with Matrix Blocks Outputs labeled as matrices are generated as vectors, so most matrix blocks can be optimized by following the rules you would follow for any other vectorized block: •...
  • Page 208: Optimizing With Callout Blocks

    AutoCode generates output matrices in row-major order, whereas the LINPACK callouts are written expecting column-major inputs. Solving AX = B under such mismatched conditions requires an extra transpose-copy not required to solve XA = B. © National Instruments Corporation Chapter 7 7-17 Code Optimization...
  • Page 209 Chapter 7 Code Optimization 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.
  • Page 210: Summary

    C or Ada source code. The executable (or the object) file size depends on the compiler used for compiling the source code. Execution speed of an application ultimately depends on the target processor. © National Instruments Corporation Output (X) Input A Mandatory copy-in...
  • Page 211: Autocode Sim Cdelay Scheduler

    Despite these limitations, it is vastly superior to the default AutoCode scheduler at latency reduction. The remainder of this chapter describes a new AutoCode scheduler that matches the Sim with Cdelay behavior and is capable of executing on © National Instruments Corporation actiming Sim with Cdelay Sim without Cdelay , while preserving determinacy.
  • Page 212: Task Posting Policies

    Chapter 8 AutoCode Sim Cdelay Scheduler 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 Policies The task characteristics that have the most impact on scheduler design are task type, and output posting policy.
  • Page 213: Standard Autocode Scheduler

    SuperBlocks, it is helpful to consider the diagnostic model shown in Figure 8-1, which features such SuperBlocks driven by a 5 Hz pulse train and fed a time signal as input. © National Instruments Corporation Chapter 8 AutoCode Sim Cdelay Scheduler...
  • Page 214 Chapter 8 AutoCode Sim Cdelay Scheduler 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 relative to its trigger input (immediately below), while the lower signal (corresponding to the enabled task) shows a latency of three cycles relative to its enable input.
  • Page 215: Scheduler Pipeline

    Stage B is where any interpolation occurs to generate internally needed timepoints from an irregularly-spaced input vector. In stage C, tasks whose launch times have arrived or whose © National Instruments Corporation Chapter 8 Time Figure 8-2.
  • Page 216 Chapter 8 AutoCode Sim Cdelay Scheduler 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 is stage E.
  • Page 217: Managing Datastores In The Scheduler

    (single) output posting stage so that lower priority tasks fire first, but the same constraint will become of key importance (and a potential stumbling point) when it comes time to implement the new scheduler. © National Instruments Corporation Chapter 8 AutoCode Sim Cdelay Scheduler AutoCode Reference...
  • Page 218 Chapter 8 AutoCode Sim Cdelay Scheduler 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 present on real-time hardware for free-running periodic tasks.
  • Page 219: Sim Cdelay Scheduler

    Conversely, with Sim with Cdelay, the trigger is immediately acted on, even though the outputs have not been posted. Notice that this has the unfortunate consequence that a sequence of © National Instruments Corporation Chapter 8 off). Sim with Cdelay differs...
  • Page 220: State Transition Diagrams Of Tasks Under Sim Cdelay

    Chapter 8 AutoCode Sim Cdelay Scheduler 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 the task types to reflect changed output posting, enable, and retriggering policies.
  • Page 221 © National Instruments Corporation Chapter 8 Timer is zero and !enable, reset timer Timer is zero and BLOCKED !enable, reset timer and post outputs task done IDLE Timer is zero and enable, reset timer and post outputs Timer greater than zero, decrement it Figure 8-6.
  • Page 222: Implementing The Sim Cdelay Autocode Scheduler

    Chapter 8 AutoCode Sim Cdelay Scheduler 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 changes to the default scheduler outside the scheduler pipeline, and embody the new output posting, enable, and retriggering policies.
  • Page 223: Datastore Priority Problem

    <- low_prio_tsk..high_prio_tsk do { /* loop from low to high priority */ if tsk.ready_to_post_outputs() { write_register(tsk.output()); reg_prio = tsk.prio(); /* Queue Tasks */ © National Instruments Corporation Chapter 8 /*write to datastore register*/ /*save priority of writer*/ 8-13 AutoCode Sim Cdelay Scheduler...
  • Page 224: Using The Sim Cdelay Scheduler

    Chapter 8 AutoCode Sim Cdelay Scheduler for tsk <- low_prio_tsk..high_prio_tsk do { /* 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 priorities of all DataStore registers in Alpha are stored in a single, file-scoped array called optimized away if Alpha is empty.
  • Page 225: Template Configuration For Enhanced Performance

    AutoCode retriggering policy can be recaptured by using the STD for ATR tasks shown in Chapter 4, Managing and Scheduling Applications, of the AutoCode User Guide, in lieu of Figure 8-7. © National Instruments Corporation Chapter 8 Time Figure 8-8. Latencies Present in the AutoCode Scheduler...
  • Page 226: Shortcomings Of The Sim Cdelay Scheduler

    Chapter 8 AutoCode Sim Cdelay Scheduler 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 NoRetrigger_style_ATR_Idle global timeline enable policy, replacing it with the default sync...
  • Page 227 ANC chain but has a fixed-length pipeline. An evaluation of the trade-offs between the relaxation approach and the fixed pipeline approach must be done before such potentially dangerous changes are made to any scheduler. © National Instruments Corporation 8-17 AutoCode Reference...
  • Page 228: Global Scope Signals And Parameterless Procedures

    • • • • • • © National Instruments Corporation Model-level specification of global signals Specification of a memory address that can be attached to each global signal Specification of which procedure inputs and/or outputs are to be global variables...
  • Page 229: Data Monitoring/Injection

    Chapter 9 Global Scope Signals and Parameterless Procedures These new features address the following two uses: • • Data Monitoring/Injection Data monitoring is the ability to have read-only access signals within a subsystem from outside the subsystem by some external agent outside the scope of the SystemBuild model.
  • Page 230: Generating Code For Monitored Signals

    Note You must write template code to customize the declarations of these variables. That includes usage of the Memory Address string, as this is target/compiler specific information. © National Instruments Corporation Chapter 9 Global Scope Signals and Parameterless Procedures gtype_b...
  • Page 231: Limitations

    Chapter 9 Global Scope Signals and Parameterless Procedures 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. • • • • Connection to External Output It is possible to connect a Global Scope output to a subsystem/system external output pin.
  • Page 232: Parameterless Procedure

    Carefully consider using this type of procedure, as it requires significant effort to design your model correctly without the safety net of AutoCode managing the generated variables. National Instruments recommends that only advanced users of SystemBuild and AutoCode use this feature.
  • Page 233: Output Specification

    Chapter 9 Global Scope Signals and Parameterless Procedures NI suggests that you adopt a naming convention for all of your global variables used Note for parameterless procedure signals. For example, specify all of the names with a leading “g,” like gThrottleValue Output Specification Procedure outputs are specified from the basic blocks that connect to the...
  • Page 234: Condition Block Code Generation

    Guide for more information about these tokens. The default template uses the following tokens to declare the variables. sgtype_nmembers_i sgtype_members_ls sgtype_members_typ_pfix_ls sgtype_members_memaddr_ls sgtype_blk_list_li © National Instruments Corporation Chapter 9 Global Scope Signals and Parameterless Procedures Generated Code Architecture. sgtype_b sgtype_members_size_li...
  • Page 235: Issues And Limitations

    Chapter 9 Global Scope Signals and Parameterless Procedures You must write template code to customize the declarations of these variables, Note which includes usage of the Memory Address string because this is target/compiler specific information. Issues and Limitations This section identifies some other items that you should be aware of if you intend to use parameterless procedures.
  • Page 236: Connection To External Output

    This is critical when you are reusing a parameterless procedure or even the global variable itself. © National Instruments Corporation Chapter 9 Global Scope Signals and Parameterless Procedures AutoCode Reference...
  • Page 237: Analyzer And Autocode Warnings

    Chapter 9 Global Scope Signals and Parameterless Procedures 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. Evaluate these warnings and verify that the generated code is what you expect.
  • Page 238: Technical Support And Professional Services

    Technical Support and Professional Services Visit the following sections of the National Instruments Web site at ni.com • • • If you searched your local office or NI corporate headquarters. Phone numbers for our worldwide offices are listed at the front of this manual. You also can visit...
  • Page 239 C fixed-point arithmetic. See fixed-point, C caller-id, 5-18 calling UCBs, 3-12 callouts global variable block, 5-51 non-shared global variable blocks © National Instruments Corporation critical section with epi option, 5-52 critical section without epi option, 5-51 non-shared variable blocks, 5-51 pairs, 5-51 parameterized UCB, 5-38...
  • Page 240 Index 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 file CONTINUE Block, 5-40 continuous subsystems. See subsystems, continuous conventions used in the manual, iv conversion macros, 2-35 critical section...
  • Page 241 2-34 sa_fxp_f.h, 2-33 sa_fxpbit.a, 3-21 sa_fxpbit_.a, 3-21 sa_fxpgenerics.a, 3-21 sa_fxpgenerics_.a, 3-21 sa_fxprv.h, 2-32, 2-33 sa_fxptypes_.a, 3-21 © National Instruments Corporation sa_fxr.h, 2-32, 2-33 sa_fxscale.h, 2-32, 2-33 sa_fxsub_byte.c, 2-34 sa_fxsub_byte.c file, 2-32 sa_fxsub_long.c, 2-32, 2-34 sa_fxsub_short.c, 2-32, 2-34 sa_fxtemps.h, 2-32, 2-33 sa_intgr.h, 2-4...
  • Page 242 Index 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 src directory, 3-21 fixed-point data types, 3-23 fixed-point variables, 3-19 floating-point textual...
  • Page 243 5-24 example with parameter, 5-34 example with states, 5-27, 5-30, 5-31 generated code optimizations, 5-35 constant propagation, 5-35 © National Instruments Corporation dead code elimination, 5-35 implicit type conversion, 5-36 special directives, 5-36 inputs, 5-23 local variables, 5-24...
  • Page 244 Index 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-39 subsystems. See subsystems symbolic names default, 5-1 generation of by AutoCode, 5-2 UCB.
  • Page 245 Macro Procedure SuperBlocks. See generated code architecture, Macro Procedure SuperBlocks MATH_LIB (Ada), 3-5 MatrixInverse, 7-17 MatrixLeftDivide, 7-17 MatrixRightDivide, 7-17 National Instruments support and services, A-1 NIP (UCB variable interface argument) Ada, 3-13 NRP (UCB variable interface argument) Ada, 3-12 NU (UCB fixed call argument)
  • Page 246 Index 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, 3-14 linking, 2-15, 2-17, 2-21, 2-22 (Ada), with user real-time applications or simulator, 3-14 (C), with user real-time applications...
  • Page 247 3-4, 3-5 sa_types.h file, 2-4, 2-32, 2-33 sa_types_.a file, 3-4, 3-5 sa_types_.ada file, 3-5 sa_user.a file, 3-5 © National Instruments Corporation sa_user.c file, 2-11 sa_user.h file, 2-3, 2-4 sa_user_.a file, 3-4, 3-11 sa_utils.a file, 3-4 sa_utils.ada file, 3-6 sa_utils.c file, 2-3, 2-5, 2-6...
  • Page 248 Index 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-alone simulation, 2-1 stand-alone utility file, 2-3, 3-4 standard procedures.
  • Page 249 UserCode Block (see UCB), 3-4 utility routines (Ada) background, 3-6 disable, 3-6 enable, 3-6 error, 3-6 external_input, 3-6, 3-10 external_output, 3-7, 3-11 © National Instruments Corporation fatalerr, 3-6 implementation_initialize, 3-6, 3-8, 3-10 implementation_terminate, 3-6 rewriting, 3-6 signal_remote_dispatch, 3-7 target-specific, 3-6 utility routines (C), 2-5...
  • Page 250 Index 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 AutoCode Reference Y (UCB fixed call argument) Ada, 3-12 C, 2-13 I-12 ni.com...

This manual is also suitable for:

Autocode ni matrixx

Table of Contents