Benutzeranleitung / Produktwartung NI MATRIX des Produzenten National Instruments
Zur Seite of 250
NI MA TRIXx TM AutoCode TM Reference AutoCode Reference April 2007 370768C-01.
Support Worldwide Technical Support and Product Info rmation ni.com National Instruments Corporate Headquarters 11500 North Mopac Expressway Aust in, Texas 78759-3504 USA Tel: 512 683 0100 Worldwide O.
Important Information Warranty The media on which you receive Natio nal In struments software are warranted not to fail to execute programming instructi ons, due to defects in materials and workmanship, for a period of 90 days from date of shipment, as eviden ced by receipts or other documentat ion.
Conventions The follo wing con ventions are used in this manual: < > Angle brackets that cont ain numbers s eparated by an ellipsis represent a range of v alues 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.
© National Instruments Corporatio n v AutoCode Reference Contents Chapter 1 Introduction Manual Organization .................... ............... .............. .............. .............. .............. .......... 1-1 General Information .........
Contents AutoCode Reference vi ni.com Linking Procedures with R eal-Time Applications or Si mulator ........ ............ 2-22 Invoking Generated Proc edures Directly ............. ............ ........... ...... 2-22 Invoking Procedures Using Generat ed UCB Wrapper Function .
Contents © National Instruments Corporatio n vii AutoCode Reference External_Input ( ) Proced ure .................... .............. .............. ............. 3-10 External_Output( ) Procedure ......... ............... .............. ............
Contents AutoCode Reference viii ni.com Chapter 4 Generating Code for Real -Time Operating Systems Real-Time Operating System Conf iguration File....... .............. .............. .............. ......... 4-1 Configuration Items ................. .
Contents © National Instruments Corporation ix AutoCode Reference System External Interface Laye r ..................................................... ............ .... 5-7 Discrete Subsystem Interface Layer ............ ...........................
Contents AutoCode Reference x ni.com States ............ .............. .............. .............. .............. .............. ............... .............. 5-26 Local Variables and Phases ................ ............... .............. ........
Contents © National Instruments Corporation xi AutoCode Reference Definitions and Conventions ................. .............. .............. .............. .............. .. 5-45 Shared Memory Fixed-Point Callouts in AutoCode/C ................. ...
Contents AutoCode Reference xii ni.com Chapter 7 Code Optimization Read from Variable Blocks ....................... .............. .............. .............. .............. ............ 7-1 Restart Capability ....... .............. .............. .
Contents © National Instruments Corporation xiii AutoCode Reference Variable Block Aliasing ................ .............. ................. .............. ....... 9-4 Monitored Signals within a Procedur e SuperBlock .......... ................ 9-4 Monitoring Procedure External Output s .
© National Instruments Corporatio n 1-1 AutoCode Reference 1 Introduction This manual provides referen ce material for using AutoCode to wr ite production quality code using gra phical tool s.
Chapter 1 Introduction AutoCode Reference 1-2 ni.com • Chapter 8, AutoC ode Sim Cdelay Scheduler , discusses the Sim Cdelay low-latency scheduler. • Chapter 9, Global Scope Signals and Param eterless Procedures , discusses additional signals and procedures.
Chapter 1 Introduction © National Instruments Corporatio n 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.
Chapter 1 Introduction AutoCode Reference 1-4 ni.com Related Publications National Instruments provides a complete library of publications to suppo rt its products.
© National Instruments Corporatio n 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 si mulation and testing.
Chapter 2 C La nguage Reference AutoCode Reference 2-2 ni.com Stand-Alone Librar y This section describes the system-sp ecific and target-specific s tand-alone ( sa ) files supplied with your system.
Chapter 2 C La nguage Referenc e © National Instruments Corporatio n 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 follo wing header f iles a v ailable locally: sa_sys.
Chapter 2 C La nguage Reference AutoCode Reference 2-4 ni.com Data T ypes Several of the target-specifi c utilities are inv olved with d ata 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 your C compiler .
Chapter 2 C La nguage Referenc e © National Instruments Corporatio n 2-5 AutoCode Reference to. For example, RT_I NTEGER can be redefined as long int if arithmetic ov erflow becomes a problem on a giv en platform. T arget-Specific Utilities Target-specific uti lit ies (in sa_utils.
Chapter 2 C La nguage Reference AutoCode Reference 2-6 ni.com The sa_utils.c f ile contains comm ents about each of th e routines as they are used for comparing simulation wi th generated code results. After you generate code, link the generated code wit h sa_*.
Chapter 2 C La nguage Referenc e © National Instruments Corporatio n 2-7 AutoCode Reference T wo error functions are provided, fatalerr( ) and error( ) . The fatalerr( ) function reports exception conditions detected by the functions in the sa_utils.
Chapter 2 C La nguage Reference AutoCode Reference 2-8 ni.com the comments there and adjust the limi ts accordingly , then recompile and relink the sa_utils.c fil e . ERROR OPENING THE INPUT FILE ERROR OPENING THE OUTPUT FILE A problem was encountered opening the input or output file.
Chapter 2 C La nguage Referenc e © National Instruments Corporatio n 2-9 AutoCode Reference Implementation_Initialize( ) Function void Implementation_Initialize (RT_F LOAT *BUS_IN RT_INTEGER, NI, RT_FLOAT BUS_OUT, RT _INTEGER NO, RT_FLOAT SCHEDULER_FREQ); In the default version of sa_utils.
Chapter 2 C La nguage Reference AutoCode Reference 2-10 ni.com External_Input ( ) Function RT_INTEGER External_Input(void) External_Input( ) is for use in the simu lation compari son mode; it reads in external in put data from your specified FSAVE input file.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-11 AutoCode Reference Linking Handwritten UCBs wi th AutoCode Applications To write code for UserCode Blocks (UCBs), refer to the sa_user.c file, which is provided in your src distribution directory.
Chapter 2 C La nguage Reference AutoCode Reference 2-12 ni.com Figure 2-1. Example UserCo de Func tion File (sa_user .c) The $ucb directi ve is recognized and inte rpreted by the automatic linking fac.
Chapter 2 C La nguage Referenc e © 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.
Chapter 2 C La nguage Reference AutoCode Reference 2-14 ni.com The operations within UCBs are controlled by the ar gument INFO , a pointer to a structure of type STATUS _RECORD that is passed as part .
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-15 AutoCode Reference Figure 2-2. Linking Handwritten UCBs with AutoCode Applications Generate A utoCode Application dsp . c usr_dsp. c (Handwritten UCB usin g sa_user . c example) compile and link Fil e Na me: usr_d sp.
Chapter 2 C La nguage Reference AutoCode Reference 2-16 ni.com Linking Handwritten UCBs (for AutoCode) with SystemBuild After you have w ritten a UCB to cr eat e an AutoCode appl ication, you can use the same UCB for simulat ion. Sy stemBuild can automatically compile and link your UserCode functio n into the simulation engine (release 4.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-17 AutoCode Reference Figure 2-3. Linking Handwritten UCBs with the SystemBuild Simulator The arguments to a UCB written onl y for linking wi th the SystemBuild simulator (usi ng usr01.
Chapter 2 C La nguage Reference AutoCode Reference 2-18 ni.com applications, make sure you adapt th e same algorithm in the body of a function using the AutoCode UCB arguments as in sa_user.c . V ariable Interface UCB The preceding sections described the fixed interface; however, a UCB can also use the variable interface option.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-19 AutoCode Reference As previously stated, the inputs and outputs of the UCB will hav e the same data type as specified in the model diagram. Inputs ar e passed by v alue while outputs are passed by reference.
Chapter 2 C La nguage Reference AutoCode Reference 2-20 ni.com Linking a V ariable Interfac e UCB with the Simulator Unlike the fixed interface which provide s an automatic method for linking with the Simulator, the variable int erface is too complicated for that method.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-21 AutoCode Reference proc_ucb_hook . Refer to the T emplate Pr ogr amming Language User Guide . Figure 2-4. Lin king Generated Re usable Procedures Procedure Generate Reusable Procedure Filename: myproc.
Chapter 2 C La nguage Reference AutoCode Reference 2-22 ni.com Linking Procedures with Real-T ime Applications or Simul ator Generate reusable procedures from your Procedure SuperBlo cks as described in this chapter and in Chapter 3, Ada Language Reference .
Chapter 2 C La nguage Referenc e © 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 ini tialization only .
Chapter 2 C La nguage Referenc e AutoCode Reference 2-24 ni.com point to the ap propriate global variables. A pointer to this o bject will be passed as argument I to the procedure. 5. In v oke the procedure using po inters to the objects created in steps 1 through 4.
Chapter 2 C La nguage Referenc e © 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.
Chapter 2 C La nguage Reference AutoCode Reference 2-26 ni.com data-typed v ariables re flecting each subsystem in put signal and type. The outputs to the subsystem are pro vided by the argument Y , a pointer to a stru cture named _Subsys_ number _out .
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-27 AutoCode Reference number—for each integer item and the sign are ma naged by the code generator. Arithmetic expressions ar e scaled to emulate a fixed-point capability, and all expressi ons involving the item are coded to be consistent with the chosen radix position.
Chapter 2 C La nguage Reference AutoCode Reference 2-28 ni.com language and replace the supplied macros (or functions) with your (assembly) functions so that you can ta ke full advantage of the processor’ s arithmetic capabilities.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-29 AutoCode Reference A typical fix ed-point type looks like the following: R T_USHOR T06 where USHOR T stands for unsigned short, and 06 indicates the radix position. Fixed-point v ariables that are al ways pos iti ve in nature can be declared as unsigned.
Chapter 2 C La nguage 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 definit ions.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-31 AutoCode Reference The UTs appear as typedef statements in the ge nerated C code. Fo r example: typedef volts RT_SBYTE03; This code defines the data type called v olts to be a signed byte with radix positi on 3.
Chapter 2 C La nguage 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 fix ed-point con version macros. sa_fxp.h Contains fix ed-point con version macros with ov erflow protection.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-33 AutoCode Reference sa_fx_externs.c Contains def initions for extern variables such as mask b uf fers that are read only . Function Interface The function interface files are: sa_types.
Chapter 2 C La nguage Reference AutoCode Reference 2-34 ni.com sa_fxsub_byte.c Contains f ixed-point subtraction functions for byte data type. sa_fxsub_short.c Contains f ixed-point subtraction functions for short data type. sa_fxsub_long.c Contains f ixed-point subtraction functions for long data type.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-35 AutoCode Reference Fixed-Point Conversion and Arithmetic Macros Although this section explains differen t fi xed-point operations in terms of macros, all of these operations are su pported as fun ctions in the function interface.
Chapter 2 C La nguage Reference AutoCode Reference 2-36 ni.com Figures 2-6 through 2-8 show ho w th e con version macros are named. Notice that macro names ha ve no embedded spaces.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-37 AutoCode Reference Figure 2-7. AutoCode/C Conversion Macros for Fixed-to-Integer Conversions For e xample, the macro to con v ert an unsigned 8-bit number to an integer number with a shift of rp bits, and with overflo w protection is: iALIGNubp(n,rp) Figure 2-8.
Chapter 2 C La nguage Reference AutoCode Reference 2-38 ni.com Arithmetic Macros The arithmetic macros perform additi on, subt raction, multiplication, and division. The top level macros for arith metic operations are present in the sa_fxm.h and sa_fxmp.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-39 AutoCode Reference T ab le 2-7 sho ws permissible operand and result sizes for the arithmetic macros.
Chapter 2 C La nguage Reference AutoCode Reference 2-40 ni.com Implementation of the Ad dition and Subtraction Macros AutoCode has two implem entations of the addition and subtraction macros: • Macr.
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-41 AutoCode Reference Align the radix positions of n1 and n2 to the r adix position of the result before subtracting (that is, shift n1 left by three bits, and shift n2 left by two bits).
Chapter 2 C La nguage Reference AutoCode Reference 2-42 ni.com 0^1111111 (n2' = (127,r7) , decimal v alue = .9921875) ___________ 0^0000000 (n3 = (0,r7) , decimal v alue = 0.0) In Example 2 -3, method 1 is more accurate than method 2, but it is also le ss ef ficient because it in v olves a 16-bit sub t ra c t io n .
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-43 AutoCode Reference the maximum possible value representa ble in 32 bits—is returned. This multiplication process can be expe nsive because it involves several multiplication an d addition operations to produce an i ntermediate result.
Chapter 2 C La nguage Reference AutoCode Reference 2-44 ni.com in terms of speed, but is needed to co mpute an accurate result. By changing this behavior , you can speed up the operation if you are willing to give up some accuracy .
Chapter 2 C La nguage Referenc e © National Instruments Corporation 2-45 AutoCode Reference For e xample, the macro to check an 8-bit unsigned number and an 8-bit signed number for equality an d prod.
© National Instruments Corporatio n 3-1 AutoCode Reference 3 Ada Language Reference This chapter discusses files used to interface AutoCode and the generated Ada code to your specific pl atform and target proce ssor. This chapter also discusses target-specific utilities needed fo r simulation and testing.
Chapter 3 Ada Language Reference AutoCode Reference 3-2 ni.com Supplied T emplates ada_rt.tpl T emplate The ada_rt.tpl templa te is the default when gener ating Ada code. This template uses Ada tasks to implement the scheduling mechanism for the model.
Chapter 3 A da Language Refe rence © National Instruments Corporatio n 3-3 AutoCode Reference Stand-Alone Librar y This section describes the system-sp ecific and target-specific s tand-alone ( sa_* ) files supplied with your system.
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 fi le. When you compile sa_utils.a/.ada , you must make the following f iles from the source distribution directory av ailable locally: – sa_utils_.
Chapter 3 A da Language Refe rence © National Instruments Corporatio n 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 f iles are listed in Ta b l e 3 - 3 .
Chapter 3 Ada Language Reference AutoCode Reference 3-6 ni.com T arget-Specific Utilities The target-specific utilities in the sa_utils.a or sa_utils.ada file perform hardware-, application-, and Ada-specific tasks th at are required for simulation and testing.
Chapter 3 A da Language Refe rence © National Instruments Corporatio n 3-7 AutoCode Reference The sa_utils.a or sa_utils.ada f ile contains comm ents about each of the routines as they are used for com paring simulation w ith generated code results.
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 th e USR01 rout ine for meanings of UCB errors. Y ou are allowed to e xtend the scope of these messages, so it might be one of yours.
Chapter 3 A da Language Refe rence © National Instruments Corporatio n 3-9 AutoCode Reference By default, sev eral error conditio ns are trapped in the procedure Implementation_Initialize of sa_utils.a/.ada , b ut you can expand this capability in your own v ersions of the program, detecting your own error conditions and adding your own messages.
Chapter 3 Ada Language Reference AutoCode Reference 3-10 ni.com These messages indicate that the sizes of the time vector and input array hav e exceeded one or more of the stor age allocation size l imits established by sa_utils.
Chapter 3 A da Language Refe rence © 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 b y the scheduler .
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,.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-13 AutoCode Reference The operations within U CBs are controlled by the INFO ar gument, a record of RT_STATUS_RECORD type that .
Chapter 3 Ada Language Reference AutoCode Reference 3-14 ni.com Procedure SuperBlocks This section describes how to generate an d link Procedure Supe rBlocks. Generating Reusable Procedures Generate reusable procedures from your Procedure SuperBlo cks as described in Chapter 2, Using AutoCode , of the AutoCode User Guide .
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-15 AutoCode Reference ------------------------------------ -------------------------------- --- -- Wrapper around the procedure.
Chapter 3 Ada Language Reference AutoCode Reference 3-16 ni.com Ada Fixed-Point Arithmetic This section describes the implement ation of fixed-point arithm etic in AutoCode/Ada.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-17 AutoCode Reference Fixed-Point Data T ypes Fixed-point type declaration s exist in the file named: sa_fxptypes_.a and is provided in the System-Specific Files src (source) directory.
Chapter 3 Ada Language Reference AutoCode Reference 3-18 ni.com Package Dependencies The fixed-point AutoCode/ Ada archit ecture forces a dependency among the supplied and gen erated code for a mod el that uses any fixed-po int types. This dependency affects compilation order within an Ada Library.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-19 AutoCode Reference Generated Code with Fixed-Point V ariables Fixed-point arithmetic operations are accomplis hed by overloading the standard arithmetic oper ator s for the fi xed-point types.
Chapter 3 Ada Language Reference AutoCode Reference 3-20 ni.com System-Level Parameters to Generat e User T ypes Table 3-6 describes new sy stem-level pa rameters that are used to generate the USER_TYPES package.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-21 AutoCode Reference frequently overflo wing, a di ff erent data type shoul d be selected. If you are concerned about performance and th e use of an e xception handle r for detecting overflo w , the g eneric functio ns can be changed.
Chapter 3 Ada Language Reference AutoCode Reference 3-22 ni.com 1. Build a model —Use th e SuperBlock Editor to construct a model that uses fix ed-point types for input/o utput signals.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-23 AutoCode Reference 4. Compile the generated files —T wo source files are generated, gaintest.
Chapter 3 Ada Language Reference AutoCode Reference 3-24 ni.com Table 3-9. Generic Functio n Summary Function Na me Purpose FIXED_ADD Addition of two f ixed-point values. FIXED_SUB Subtraction of two fix ed-point values. FIXED_MUL Multiplication of two fixed-point v alues.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-25 AutoCode Reference LONGINTCAST Fix ed-poin t v alue to RT_LONG_INTEGER con version. LONGINTCAST_TRUNC Fix ed-poi nt v alue to RT_LONG_INTEGER con version using truncation. LONGINTCAST_ROUND Fix ed-poi nt v alue to RT_LONG_INTEGER con version using rounding.
Chapter 3 Ada Language Reference AutoCode Reference 3-26 ni.com Bit-Wise Functions A restricted set of bit-wise operatio ns have been defined for certain fixed-point types. These functions exist in the SA_FIXED_BITWISE_FUNCTIONS package found in the sa_fxpbit_.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-27 AutoCode Reference Conversion Function Instantiations The RT_FIXED_OPERATORS package contains instan tiations of functio ns that represent conversion of values to and from a fixed-point type.
Chapter 3 Ada Language Reference AutoCode Reference 3-28 ni.com Sample Package Example 3-3 shows a gener ated RT_FIXED_OPERATORS package. Example 3-3 Generated RT_FI XED_OPERATORS Package ------------------------------------ -------------------------------- ------- -- AutoCode/Ada (TM) Code Generator 7.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-29 AutoCode Reference function “>=” is new SA_FIXED_GENERI CS.GREATEREQUAL(SA_FIXED.RT_SSHO RT14, SA_FIXED.RT_SSHORT08); --pragma inline (">="); function ">=" (LEFT, RIGHT : SA_ FIXED.
Chapter 3 Ada Language Reference AutoCode Reference 3-30 ni.com The selection of the intermediate type is perfo rmed by the code generator . The selection in volves a set of rules that rely upon w ord size extens ion. W ord size extension is selecting a f ixed- point type with a larger number of bits that can be used to represent model numbers.
Chapter 3 A da Language Refe rence © 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 combinati on of fixed-point arguments.
Chapter 3 Ada Language Reference AutoCode Reference 3-32 ni.com no chance of overflow. To support thes e issues there are three types of conversion functions: • Language-defined con version • T runcation con v ersion • Explicit rounding conv ersion These con versions are describe d in the following sections.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-33 AutoCode Reference For these types of con versions, the la nguage-defined con version is used. In general, when an explicit con ver sion is required and there is no specification of which to choose, AutoCode/Ada will select the explicit rounding conv ersion.
Chapter 3 Ada Language Reference AutoCode Reference 3-34 ni.com The data in the sp_fxp parameters represent th e operators and con version used in the currently scoped subsyste m or procedure. No assumptions can be made about the order within a given list parameter .
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-35 AutoCode Reference Known Ada Compiler Problems The architecture of Au toCode/Ada Fixed-Point heavil y relies upon overloaded operators and generic function inst antiation.
Chapter 3 Ada Language Reference AutoCode Reference 3-36 ni.com • Floating-Point T extual Representation —The values generated from a stand-alone simulation are con verted to a textual (ASCII) representation. That representation in t extual form might no t quite be as accurate as possible.
Chapter 3 A da Language Refe rence © National Instruments Corporation 3-37 AutoCode Reference Example 3-6 Example Code C ausing Ambiguous Selection of Overloaded Operators function "*" (lef.
© National Instruments Corporatio n 4-1 AutoCode Reference 4 Generating Code for Real-T ime Operating Systems This chapter describes the RTOS c onfiguration file and functionality provided for generating co de for real-time operating systems.
Chapter 4 Generating Code for Real-Time Operating Systems AutoCode Reference 4-2 ni.com Configuration Items The following is a list of configuratio n attributes for each type of AutoCode component.
Chapter 4 Generating Code for Real-Time Operating Systems © National Instruments Corporatio n 4-3 AutoCode Reference T able Naming Convention Tables are given a name to identify the contents of the data co ntained therein. Table names are specified in the same form as Xmath variables, partition.
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 T able Table 4-2 is a single element table cons isting of the p riority assigned to the scheduler task.
Chapter 4 Generating Code for Real-Time Operating Systems © National Instruments Corporatio n 4-5 AutoCode Reference Example 4-3 Subsys tem Table Example rtos.
Chapter 4 Generating Code for Real-Time Operating Systems AutoCode Reference 4-6 ni.com Example 4-4 Interrupt Table Example rtos.intrsupblk = Interrupt | Priority Stack Size Processor Vector Mode Flag.
Chapter 4 Generating Code for Real-Time Operating Systems © National Instruments Corporatio n 4-7 AutoCode Reference Startup Procedure SuperBlock T able Table 4-6 consists of configuration information for all start up procedure SuperBlocks in th e model.
Chapter 4 Generating Code for Real-Time Operating Systems AutoCode Reference 4-8 ni.com Example 4-7 Processor IP Table Example rtos.IPprsrmap = Processor | IP Name ------------------------------------ -------------------------------- 1 | 127.0.0.1 2 | 133.
Chapter 4 Generating Code for Real-Time Operating Systems © National Instruments Corporatio n 4-9 AutoCode Reference configuration f ile is updated. Also, the updated configuration file is stored in the same directory where the gene rated code is placed.
© National Instruments Corporatio n 5-1 AutoCode Reference 5 Generated Code Architecture This chapter supplies more details about the content and framework of the generated code. This includes st orage usage, various procedures, specialized blocks, and subsystems.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-2 ni.com Signal Naming A signal in t he diagram is represented as a variable in the ge nerated code. Within the diagram, signals can have two names: a label and a name . The signal’s label can appear in the diag ram while a signal’s name does not appear.
Chapter 5 Generated Code Architecture © National Instruments Corporatio n 5-3 AutoCode Reference Global Storage In a strict modular programming paradig m, global storage is strictly avoided. However, global storage can be used safely and provid es significant benefits in terms of code size and speed.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-4 ni.com • Write-T o V ariable Block (ALL Addressing mode) —These blocks ex ecute after all other types of blocks within the subsystem , procedure or sequence frame.
Chapter 5 Generated Code Architecture © National Instruments Corporatio n 5-5 AutoCode Reference Subsystems This section describes the design and operation of subsystems.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-6 ni.com T o p-Level SuperBlock The term Top-Level SuperBlock is often used . This term describes the SuperBlock that was the root of the Analyzer’s pr ocessing of the SuperBlock hierarchy into su bsystems, that is, a starting point for the translation.
Chapter 5 Generated Code Architecture © National Instruments Corporatio n 5-7 AutoCode Reference Figure 5-1 illustrates the interface laye rs. The layers are described in the subsections shown in the f igure.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-8 ni.com Discrete Subsystem Interface Layer This layer comes in two variations to allow for bot h an optimized and general solution.
Chapter 5 Generated Code Architecture © National Instruments Corporatio n 5-9 AutoCode Reference This sample and hold mechani sm guarantees determini stic behavior for all possible connectivities and is implemented using a technique called double buf fering.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-10 ni.com Procedure Data Procedure SuperBlocks have inp uts, outputs and states ind ependent of the subsystem from which the procedure is cal led. This is required to properly implement the characteristics of a pro cedure; those characteristics include reusability and reentrancy.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-11 AutoCode Reference system, because ordering of the outp uts in a single-rate system is maintained. In a multi-rate system, du plicates can be safely eliminated because of the sample and hold mechan ism.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-12 ni.com Unrolled Interface There is another form of the proced ural interface, th e unrolled interface ( No-UY ). This interface does not use U - and Y -structures to pass the inputs and outputs.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-13 AutoCode Reference Note I f you specify a specific parti tion with the %var name in the block form (that is, A.GAIN ), that %v ar is directly us ed, not indirectly referenced.
Chapter 5 Generate d 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.
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.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-16 ni.com mixed data-typed v ariables reflecti ng each procedure output signal and type. The states of the procedur e are prov ided by the ar gument S, a pointer to a structu re named _ procedure name _s .
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 v alues used by algorithms of blocks in t he procedure.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-18 ni.com Extended Procedure Information Structure The -epi option specifies that additiona l elements to all standard procedure SuperBlock’s info structure are to be generated. Currently, only one additional element is generate d.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-19 AutoCode Reference Notice the relativ e numbering within a task/pro cedure type. Also, be aware that standard procedures are not given a unique identif ier for the purposes of the caller_id element.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-20 ni.com ho wev er , is to create additional sp ace when declaring a variable of the info structure’ s type and for the new code generated with the -epi option, which assumes the f iel d ex ists in all proc edure info structures.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-21 AutoCode Reference Asynchronous Procedures Asynchronous Procedures are procedures th at are not regularly scheduled to be executed or directly called from a subsystem or St andard Procedure.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-22 ni.com Changing %var V alu es During Startup A special feature of the Startup allows the value of a %var to be set at run-time through a Global Vari able Block that has the same name as the %var.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-23 AutoCode Reference The BlockScript block allows you to specify conditions and actio ns, define block inputs, ou tputs, and paramet ers, and specify thei r data types and dimensions.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-24 ni.com In Example 5-5, alpha, beta, and g amma are the variables to be used as representations for the inpu ts. Alpha is a scalar re presenting th e input from pin 1. Beta is an array of integers representing inputs pins 2 through 6.
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 phase s are intended to be used in a consistent way, just like the standard blocks.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-26 ni.com Default Phase If you do not specify a ph ase and/or all code i s not contained within an IF statement guarded by a phase environmen t variable, that code is generated in the Output phase and, if there is a St ate phase, that code also is generated in the State phase.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-27 AutoCode Reference Local Va riables and Phases A local variable cannot be used to pass data between phases, because the different phases occur at different lo cations in the execution orde r of the whole subsystem or procedure.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-28 ni.com new_total = y; endif; Example 5-8 Generated C ode 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.
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 simil ar to the discrete equivalents, except that State data is integrated by the integrato r algorithm.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-30 ni.com In Example 5-9, a hard-subscript, i , is used to access both inputs an d outputs. The reason i is a hard-subscript is that the range of i —that is, the val ues of 1 thro ugh to the numb er of inputs ( u.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-31 AutoCode Reference Example 5-11 Local Variables Used to Al low Loops in Scalar Code Generation Inputs: u; Outputs: y; float u(:), y(u.size), local_u(u.siz e), local_y(y.size); integer i,j; for i = 1:u.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-32 ni.com • FOR Loop—Can generate either a rolled or unrolled loop depending upon the range of the lo op subscript and wheth er or not scalar code is generated. Examples of Rolled and Unrolled Loops Example 5-12 Unrolled Loop from Example 5-9 /***** Output Update.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-33 AutoCode Reference Parameters Parameters represent data that can be used to pr ovide data to tun e the algorithm by representing coefficients in equations or persistent data somewhat like states.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-34 ni.com Example 5-14 BlockScript Block Exam ple with Updating of a Parameter Inputs: u; Outputs: y; Environment: (OUTPUT, INIT); Parameter.
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.
Chapter 5 Generate d 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 Bl ockScript Block Example 5-16 /***** Output Update. *****/ /* ---------------------------- Blo ckScript Block */ /* {deadbsb.
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 not easily modeled within the diagram.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-38 ni.com Parameterized UCB Callout A UCB can be defined with %var para meterized data for the UCB’s real parameters ( RP ) and inte ger parameters ( IP ). When used, AutoCode generates code that p a s s e s t h e % v a r variable as the actual of the UCB callout.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-39 AutoCode Reference Software Constructs These blocks provide the software constructs that are ty pically found in any imperative programming language su ch as C, Pascal, and FORTRAN.
Chapter 5 Generate d 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 respons ible for properly detecting an exit condition and using it as an input t o a BREAK Block insid e the loop.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-41 AutoCode Reference The Read from V ariable Block optimi zat ion also is support ed for Local V ariable Blocks. Refer to Chapter 7, Code Optimizat ion , for more detail s on optimization.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-42 ni.com representative of a sequence of equations. These equations are sensitive (that is, potentially numerically un stable) to the integration algorithm and order in which the equations ar e computed.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-43 AutoCode Reference • Algebraic loop s are not supported . • AutoCode only p erforms a single initi alization pass at time = 0.0. This corresponds to the Syst emBuild Simulation options of INITMODE=0 or ACTIMING .
Chapter 5 Generate d Code Architecture AutoCode Reference 5-44 ni.com Distributed Memor y Architecture AutoCode also suppor ts a multiprocesso r architecture that uses distributed memory instead of shared memo ry.
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,siz e) 4.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-46 ni.com • SLONG stands for signed long. • ULONG stands for unsigned long. The naming con vention of the callout s uses the terms listed abov e and associates from right to left. The fo llo wing is an example of a callout.
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_macr.
Chapter 5 Generate d 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 informatio n about the shared variable blocks is accessible from within the template usin g parameter information.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-49 AutoCode Reference /**** declare pointer to shared vari ables ****/ volatile struct _shared_varblk *isi_ varblk[1] = {&am.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-50 ni.com Shared Memor y Callout Option AutoCode supports a shared memory cal lout for all acc ess to elements in shared memory. Callouts are generated when the -smco option is specified. The previous discussion about shared variable blocks still applies.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-51 AutoCode Reference proc2_4_2 = Read_Shared_Varblk_Fl oat(&isi_varblk[0]->block5[1]); Leave_Shared_Varblk_Section(4.
Chapter 5 Generate d Code Architecture AutoCode Reference 5-52 ni.com The formal argument represents the gl obal reference number for which the v ariable block is being accessed. Th e default implementation of those simply calls the Disable( ) function.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-53 AutoCode Reference The formal argument represents the gl obal reference number for which the v ariable block is being accessed. The second formal argume nt, caller_id , represents a unique identif ier for the caller .
Chapter 5 Generate d 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 ar gument represents the global reference number for which the variable block is being accessed.
Chapter 5 Generated Code Architecture © National Instruments Corporation 5-55 AutoCode Reference The following code uses the En ter_Shared_Varblk... syntax for shared variable block generated code with callouts, using t he -vbco and -epi options.
© National Instruments Corporatio n 6-1 AutoCode Reference 6 V ectorized Code Generation This chapter discusses various w ays to generate vectorized code. This includes describing the options availab le, design gui delines, and implementatio n details ab out the vectorized code.
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 Gener ated for Gain Block Example void subsys_1(U, Y) struct _Sys_ExtIn *U; struct _Subsys_1_out *Y; { static RT_INTEGER iinfo[4]; /******* Initialization.
Chapter 6 Vectorized Code Generation © National Instruments Corporatio n 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 v alue i is the range <1.
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<10;cnt++ ) { R_P[cnt] = _R_P[cnt]; } SUBSYS_PREINIT[1] = FALSE; return; } /***** Output Update.
Chapter 6 Vectorized Code Generation © National Instruments Corporatio n 6-5 AutoCode Reference addition to issues w ith the standard block library, all general BlockScript Blocks within the diagram are impl emented as 1-based arrays. If the subscript can be evaluated at generation-time, the 0-based subscript wi ll be used.
Chapter 6 Vectorized Code Generation AutoCode Reference 6-6 ni.com Figure 6-1. Poorly Connected Gain Block Example 6-3 Generated Code fo r 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.
Chapter 6 Vectorized Code Generation © National Instruments Corporatio n 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.
Chapter 6 Vectorized Code Generation AutoCode Reference 6-8 ni.com V ector 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 th is type of labeling as a definition of which pins are to be an array.
Chapter 6 Vectorized Code Generation © National Instruments Corporatio n 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 declara tions.
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; static const RT_FLOAT _R_P[11] = {0.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-11 AutoCode Reference } SUBSYS_PREINIT[1] = FALSE; return; } /***** Output Update.
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 declara tions.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-13 AutoCode Reference RT_FLOAT Brake; RT_FLOAT Gear; RT_FLOAT Clutch; /***** Algorithmic Local Varia bles. *****/ RT_INTEGER i; RT_INTEGER j; RT_INTEGER k; /******* Initialization.
Chapter 6 Vectorized Code Generation AutoCode Reference 6-14 ni.com k = k + 1; } } k = 1; for (i=1; i<=5; i++) { Y->delayed_pulse[-1+i] = X- >sensor_delay[-1+k]; k = k + 1; } /* --------------------------- - Gain Block */ /* {VecEx..2} */ Throttle = -8.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-15 AutoCode Reference Note The examples within this section assume maximal vectorization unless otherwi se noted. Multiple Arrays within a Block All blocks support multiple vectors (arrays) as both outputs and inpu ts.
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 Varia bles. *****/ RT_INTEGER i; /******* Initialization.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-17 AutoCode Reference The interesting part is that of the last gain blo ck ( gain..99 ). Notice that although two distinct arrays are used as input, because the input arrays are connected contiguously , the code is rolled into two separate loops.
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 Sp lit Vector (for Figure 6-4) /***** Output Update. *****/ /* --------------------------- - Gain Block */ /* {gain.
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. No tice that AutoCode was only able to vectorize two inputs while th e remaining fou r were unrolled.
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<=5; i++) { top[-1+i] = R_P[-1+i]*U->ga in_1[-1+i]; } /* --------------------------- - Gain Block */ /* {gain.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-21 AutoCode Reference Y ou shou ld notice two things in the code shown in Example 6-8. First, the gain block added to mer ge the data is generated as copies from the respectiv e inputs into the single arra y .
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.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-23 AutoCode Reference Eliminating Copy-Back There are many design ways to eliminat e or hide the extra copies of the copy-back.
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 ve.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-25 AutoCode Reference top[-1+i] = R_P[-1+i]*U->ga in_1[-1+i]; } /* --------------------------- - Procedure Super Block */ /* {vecproc.3} */ vecproc(&top[0], &Y->vecproc_3 _1[0], &vecproc_3_i); iinfo[0] = vecproc_3_i.
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.
Chapter 6 Vectorized Code Generation © National Instruments Corporation 6-27 AutoCode Reference ------ Swap state pointers. ------ XTMP := X; X := XD; XD := XTMP; INIT := FALSE; end; V ectorization of the BlockScript Block The general BlockScript block is commonly used to im plement very complicated or custo m algorithms w ithin a single blo ck.
Chapter 6 Vectorized Code Generation AutoCode Reference 6-28 ni.com Matrix Outputs When you provide matricized output labeli ng for a block, AutoCode generates the resulting “matrix” as a si ngle-dimensional array, even in Ada.
© National Instruments Corporatio n 7-1 AutoCode Reference 7 Code Optimization This chapter explains the details of generating pro duction quality code for micro controller-based applications. Generally, micro con troller-based applications have stringent requirements for code size and execu tion speed.
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_PREINIT[1] = FALSE; return; } /***** Output Update.
Chapter 7 Code Optimization © National Instruments Corporatio n 7-3 AutoCode Reference Example 7-2 Code Generated with Va riable 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_INTEGER iinfo[4]; /***** Local Block Outputs.
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 opt imization only if it is safe to do so. There could be circumstan ces that could po tentially prevent this optimization from taking place.
Chapter 7 Code Optimization © National Instruments Corporatio n 7-5 AutoCode Reference Write to the same variable block. Due to the cyclic nature of loops, any Write to V a riable block inside the loop appears in between the Read from V ariable block out side the loop and its use inside the loop.
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 Varia bles.
Chapter 7 Code Optimization © National Instruments Corporatio n 7-7 AutoCode Reference the buf fer _R_P and the initialization code are optimized aw ay . Instead, the buff e r R_P (parameter array), states, deriv ati ves, and info structures are initialized directly in the declaratio n portion.
Chapter 7 Code Optimization AutoCode Reference 7-8 ni.com Merging INIT Sections Most of the dynamic blocks have explicit ini tialization, output update and state update sections. The initializat ion section is guarded by an INIT Boolean variable that is TRUE only for the first time a subsystem or a procedure is called.
Chapter 7 Code Optimization © National Instruments Corporatio n 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.
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.
Chapter 7 Code Optimization © National Instruments Corporation 7-11 AutoCode Reference In Example 7-5, both time delay block s hav e separate INIT sect ions. In Example 7-6, the initialization code for these blocks is m erged along with the subsystem initialization sect ion.
Chapter 7 Code Optimization AutoCode Reference 7-12 ni.com Example 7-7 shows code generated wit hout the reuse opt ion, and Example 7-8 shows code generated from the same models wi th the maximal reuse option. Example 7-7 Code Fragment wi thout Reuse Optimization /***** Local Block Outputs.
Chapter 7 Code Optimization © National Instruments Corporation 7-13 AutoCode Reference } Y->model_5_1 = X->model_5_S1; /* ---------------------------- Gai n Block */ /* {model..2} */ model_2_1 = 2.0*U->model_1; /* ---------------------------- Sum of Vectors */ /* {model.
Chapter 7 Code Optimization AutoCode Reference 7-14 ni.com All of the blocks can accept constants as inputs. If any input is a v ailable during code generation time as a co nstant , the constant is used instead of a symbol name (or variable name). This applies to blocks of both categories.
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 Outputs.
Chapter 7 Code Optimization AutoCode Reference 7-16 ni.com input of the gain blo ck and the expression 2.0 * const_2 is ev aluated to 4 as the value of const_2_1 is 2. Hence, the subsystem output gets the va lu e 4 . The command-line opti on for in voking this optimization is -Opc .
Chapter 7 Code Optimization © National Instruments Corporation 7-17 AutoCode Reference constant block is optimized away , including the ou tput variable. Also notice that the existing Constant Propag atio n optimization can be used with the constant block, but will only operate on scalar pieces of the constant block output.
Chapter 7 Code Optimization AutoCode Reference 7-18 ni.com If you hav e decided on the MatrixRigh tDi vide block, the tips for op timizing the inputs are much the same as for th e MatrixIn verse block. In this case there are two inputs, A and B, and both are modified by the callout algorithm.
Chapter 7 Code Optimization © National Instruments Corporation 7-19 AutoCode Reference Summar y All of the optimizations discussed so far can be used at the same time without limitations.
© National Instruments Corporatio n 8-1 AutoCode Reference 8 AutoCode Sim Cdelay Scheduler This chapter discusses the Sim Cdelay low-latency sched uler. Introduction The default AutoCode scheduler is based on high throughp ut. Latency is acceptable as long as scheduler interrup t times are frequent.
Chapter 8 AutoCode Sim Cdelay S cheduler 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.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporatio n 8-3 AutoCode Reference Standard AutoCode Scheduler To illustrate the behavior of the standard AutoCode schedu ler with trig.
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-4 ni.com Figure 8-1. Model with Enabled and T riggered T asks Under the default AutoCode scheduler, the output of this system is as shown in Figure 8-2.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporatio n 8-5 AutoCode Reference Scheduler Pipeline section that these latencies are caused by the single posting stage per scheduler in v ocation in the default AutoCode scheduler , and by the output posting policy assigned to enabled blocks in the default scheduler .
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-6 ni.com triggers/enables have gone hig h are que ued 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.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporatio n 8-7 AutoCode Reference queue tasks stage for that scheduler in v ocation 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.
Chapter 8 AutoCode Sim Cdelay S cheduler 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-c ycle delay for tr.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporatio n 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-tim e targets, which mimics th e behavior of Sim with Cdelay ( actiming off).
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-10 ni.com triggers arriving too quickly can pr ev ent a task from e ver posting an y output.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporation 8-11 AutoCode Reference Figure 8-6. New STD for A TR T riggered T asks Figure 8-7.
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-12 ni.com These transition diagrams, together with the diagrams in C hapter 4, Managing and Scheduling Appli cations , of the AutoCode User Guide , define the behavior of tasks under the Sim with Cdelay schedul er .
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporation 8-13 AutoCode Reference DataStore Priority Problem As mentioned, you must fin d some way to enforce the priori ty of writers to DataStores in the generated code.
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-14 ni.com for tsk <- low_prio_tsk..high_prio_t sk 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.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporation 8-15 AutoCode Reference Figure 8-8. Latencies Present in the AutoCode Scheduler T emplate Configuration for Enhanced Perform.
Chapter 8 AutoCode Sim Cdelay S cheduler AutoCode Reference 8-16 ni.com At the template level, the def ault Sim with Cdelay A TR triggered task behavior of re-queueing a task for ex ecution on receipt.
Chapter 8 AutoCode Sim Cdelay Scheduler © National Instruments Corporation 8-17 AutoCode Reference that repeated until no new tasks wher e queued for execution.
© National Instruments Corporatio n 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 requirem ents of real-time production code force the issue of glo bal variables.
Chapter 9 Global Scope Signals and Paramete rless Procedures AutoCode Reference 9-2 ni.com These ne w features address the following two uses: • Data Monitoring/Injection —The safe access to local subsystem signals for the purpose of monitoring th e signal’ s value during the ex ecution of the model.
Chapter 9 Global Scope Signal s and Parame terless Procedures © National Instruments Corporatio n 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 out puts as Global Scope when generating vectorized code .
Chapter 9 Global Scope Signals and Paramete rless 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 bl ocks that do not support scoped outputs.
Chapter 9 Global Scope Signal s and Parame terless Procedures © National Instruments Corporatio n 9-5 AutoCode Reference Parameterless Procedure A parameterless (argument-less) procedur e is a procedure that uses global variable(s) to pass input(s) into and/or ou tput(s) out of the procedure.
Chapter 9 Global Scope Signals and Paramete rless Procedures AutoCode Reference 9-6 ni.com Note NI suggests that you adopt a naming conv ention for all of your global v ariables used for parameterless procedure signals. For exampl e, specify all of the names with a leading “g, ” like gThrottleValue .
Chapter 9 Global Scope Signal s and Parame terless Procedures © National Instruments Corporatio n 9-7 AutoCode Reference Condition Block Code Generation The Condition Block supports the use of parameterless procedures.
Chapter 9 Global Scope Signals and Paramete rless Procedures AutoCode Reference 9-8 ni.com Note Y ou mu st write template code to customi ze the declarations of these variables, which includes usage of the Memory Address st ring because this is tar get/compiler specif ic information.
Chapter 9 Global Scope Signal s and Parame terless Procedures © National Instruments Corporatio n 9-9 AutoCode Reference Connection to External Output If a signal that is used as input to a Global Sc.
Chapter 9 Global Scope Signals and Paramete rless Procedures AutoCode Reference 9-10 ni.com Analyzer and AutoCode W arnings The Analyzer reports questionable connect ivities or situations regarding usage of the Global Scope signals. Also, AutoCod e might report additional warnings during code generation.
© National Instruments Corporatio n A- 1 AutoCode Refer ence A T echnical Support and Professional Ser vices Visit the following sections of the National Instruments Web site at ni.com for technical support an d professional services: • Support —Online technical support resources at ni.
© National Instruments Corporatio n 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, 6-4 asynchronous procedures.
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.
Index © National Instruments Corporatio n 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.
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 func.
Index © National Instruments Corporatio n I-5 AutoCode Reference Olvarblk option, 7-4 Onorestart option, 7-5 propagating constants (O pc option), 7-13 removing restart capability, 7-5 reusing tempora.
Index AutoCode Reference I-6 ni.com distributed memory architecture, 5-44 mapping command optio ns, 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.
Index © National Instruments Corporatio n I-7 AutoCode Reference L local variabl e blocks, 5-40 , 5-41 local variables, 5-27 M macro interface, 2-27 files needed, 2-27 Macro Procedure SuperBlocks.
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 procedu.
Index © National Instruments Corporatio n 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.
Index AutoCode Reference I-10 ni.com shared memory callouts, 5-50 fixed-point callouts Ada, 5-47 C, 5-46 shared variable block sup port, 5-47 simulation, stand-alone, 2-1 soft-subscript, 5-29 software (NI resources), A-1 software constructs.
Index © National Instruments Corporation I-11 AutoCode Reference template code for variable block structures, 5-48 timing overflow, 2-8 training and certificatio n (NI resources), A-1 troubleshooting.
Index AutoCode Reference I-12 ni.com X X (UCB fixed call argument) Ada, 3-12 C, 2-13 XD (UCB fixed call argumen t) Ada, 3-12 C, 2-13 XINPUT array, 2-10 Xmath {matrixx,ascii}, 2-7 XOUTPUT array, 2-10 Y.
Ein wichtiger Punkt beim Kauf des Geräts National Instruments NI MATRIX (oder sogar vor seinem Kauf) ist das durchlesen seiner Bedienungsanleitung. Dies sollten wir wegen ein paar einfacher Gründe machen:
Wenn Sie National Instruments NI MATRIX noch nicht gekauft haben, ist jetzt ein guter Moment, um sich mit den grundliegenden Daten des Produkts bekannt zu machen. Schauen Sie zuerst die ersten Seiten der Anleitung durch, die Sie oben finden. Dort finden Sie die wichtigsten technischen Daten für National Instruments NI MATRIX - auf diese Weise prüfen Sie, ob das Gerät Ihren Wünschen entspricht. Wenn Sie tiefer in die Benutzeranleitung von National Instruments NI MATRIX reinschauen, lernen Sie alle zugänglichen Produktfunktionen kennen, sowie erhalten Informationen über die Nutzung. Die Informationen, die Sie über National Instruments NI MATRIX erhalten, werden Ihnen bestimmt bei der Kaufentscheidung helfen.
Wenn Sie aber schon National Instruments NI MATRIX besitzen, und noch keine Gelegenheit dazu hatten, die Bedienungsanleitung zu lesen, sollten Sie es aufgrund der oben beschriebenen Gründe machen. Sie erfahren dann, ob Sie die zugänglichen Funktionen richtig genutzt haben, aber auch, ob Sie keine Fehler begangen haben, die den Nutzungszeitraum von National Instruments NI MATRIX verkürzen könnten.
Jedoch ist die eine der wichtigsten Rollen, die eine Bedienungsanleitung für den Nutzer spielt, die Hilfe bei der Lösung von Problemen mit National Instruments NI MATRIX. Sie finden dort fast immer Troubleshooting, also die am häufigsten auftauchenden Störungen und Mängel bei National Instruments NI MATRIX gemeinsam mit Hinweisen bezüglich der Arten ihrer Lösung. Sogar wenn es Ihnen nicht gelingen sollte das Problem alleine zu bewältigen, die Anleitung zeigt Ihnen die weitere Vorgehensweise – den Kontakt zur Kundenberatung oder dem naheliegenden Service.