SIMULINK Dynamic System Simulation for MATLAB Modeling Simulation Implementation Target Language Compiler Reference Guide Version 1
How to Contact The MathWorks: 508-647-7000 Phone 508-647-7001 Fax The MathWorks, Inc. 24 Prime Park Way Natick, MA 01760-1500 Mail http://www.mathworks.com Web Anonymous FTP server Newsgroup ftp.mathworks.com comp.soft-sys.matlab support@mathworks.com suggest@mathworks.com bugs@mathworks.com doc@mathworks.com subscribe@mathworks.com service@mathworks.com info@mathworks.
Contents Using the Target Language Compiler with Real-Time Workshop 1 Using the Target Language Compiler . . . . . . . . . . . . . . . . . . . 1-2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 A Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Files . . . . . . . . . . . . . . . . . . . . . Target Files . . . . . . . . . . . . . System Target Files . . . . Block Target Files . . . . . . ....... ....... .......
Multiple Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . %foreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . %for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . %roll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Object-Oriented Facility for Generating Target Code . . . . . . . GENERATE and GENERATE_TYPE Functions . . . . . . . . Output File Control . .
Coding Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 Writing a Block Target File . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Block Setup Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . BlockInstanceSetup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . BlockTypeSetup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Output Block Functions . . . . . . . . . . . . . . . . . . . . . . . . . . Enable .
LibCacheNonFiniteAssignment . . . . . . . . . . . . . . . . . . . . . . Built-In TLC Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . STRINGOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . EXISTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 3-30 3-30 3-30 3-30 Inlining an S-Function . . . . . . . . . . . . . . . . .
LibDataOutputPortWidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LibDataStoreMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LibDeclareRollVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LibDefineIWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LibDefinePWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . LibDefineRWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
model.rtw A B Model.rtw File Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2 Model.rtw File Contents — System Record . . . . . . . . . . . . . . . A-11 Model.rtw File Contents — Block Specific Records . . . . . . . . . A-17 Model.rtw File Contents — Linear Block Specific Records . . . A-51 Target Language Compiler Error Messages Target Language Compiler Library Error Messages C blkiolib.tlc Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 Using the Target Language Compiler with Real-Time Workshop Using the Target Language Compiler . . . . . . . . . 1-2 Introduction . . . . . . . . . . . . . . . . . . . . . 1-2 A Basic Example . . . . . . . . . . . . . . . . . . . 1-5 Files . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Target Files . . . . . . . . . . . . . . . . . . . . . 1-10 Where to Go from Here . . . . . . . . . . . . . . .
1 Using the Target Language Compiler with Real-Time Workshop Using the Target Language Compiler Introduction The Target Language Compiler™ is a tool that is included with Real-Time Workshop® (RTW) and enables you to customize the C code generated from any Simulink® model. Through customization, you can produce platform-specific code or incorporate algorithmic changes for performance, code size, or compatibility with existing methods that you prefer to maintain.
Using the Target Language Compiler For those familiar with HTML, Perl, and MATLAB®, you will find that the Target Language Compiler borrows ideas from each of them. It has the mark-up-like notion of HTML, and the power and flexibility of Perl and other scripting languages. It has the data handling power of MATLAB. The Target Language Compiler is designed for one purpose—to convert the model description file, model.rtw, (or similar files) into target specific code or text.
1 Using the Target Language Compiler with Real-Time Workshop Simulink Model (sample.mdl) Real-Time Workshop *.tlc sample.rtw Target Files Target Language Compiler sample.c sample.h sample.prm Figure 1-1: The Target Language Compiler Process 1-4 sample.
Using the Target Language Compiler By modifying the target files (also referred to as TLC files, for example, basic.tlc), you can customize the output generated by the Target Language Compiler. For more information on creating TLC files, see Chapter 3, “Writing Target Language Files.” A Basic Example The Real-Time Workshop graphical user interface provides a menu that automates the entire process of generating a model.
1 Using the Target Language Compiler with Real-Time Workshop This file shows the structure of the small.rtw file. CompiledModel { Name "small" Version "2.
Using the Target Language Compiler } Block { Type Name Identifier TID RollRegions NumDataInputPorts DataInputPort { Width SignalSrc } ParamSettings { PortNumber OutputLocation } } Outport "/Out" Out 0 [0] 1 1 [B0] 1 Y0 } . . .
1 Using the Target Language Compiler with Real-Time Workshop To use the Target Language Compiler on small.rtw to generate all associated RTW code, enter: tlc –r small.rtw MATLAB/rtw/c/grt/grt.tlc –IMATLAB/rtw/c/tlc Note: To use the Target Language Compiler and its associated files, you must know where MATLAB is installed on your system. MATLAB provides a command that returns this information.
Using the Target Language Compiler These files contain the fully documented C code that represents your Simulink model. At this point, you can use the C code as a stand-alone external simulation on a target machine. This example shows only the basic operation of the Target Language Compiler. Numerous options are available and are explained throughout this manual.
1 Using the Target Language Compiler with Real-Time Workshop Files The Target Language Compiler works with various sets of files to produce its results. The complete set of these files is called a TLC program. This section describes the TLC program files. Target Files Target files are the set of files that are interpreted by the Target Language Compiler to transform the intermediate RTW code (model.rtw) produced by Simulink into target-specific code.
Files mdlwide.tlc, which contains all of the settings and parameter values that control generic C code generation. The set of system target files includes: System Target File Purpose grt.tlc System target file for generic real-time code generator mdlwide.tlc General C code target file provided by The MathWorks mdlhdr.tlc Creates everything in the header file, model.h mdlbody.tlc Creates the source file, model.c mdlreg.tlc Creates the model registration file, model.reg mdlparam.
1 Using the Target Language Compiler with Real-Time Workshop Where to Go from Here The remainder of this book contains both explanatory and reference material for the Target Language Compiler. Use this chart to help determine which chapters are most relevant for you. 1-12 Chapter Description 1. Using the Target Language Compiler with Real-Time Workshop Provides overview information of the Target Language Compiler and its files. 2.
2 Working with the Target Language Why Use the Target Language Compiler? . . . . . . . 2-2 The model.rtw File . . . . . . . . . . . . . . . . . 2-3 Compiler Directives . . . . . . . . . . . . . Syntax . . . . . . . . . . . . . . . . . . . Comments . . . . . . . . . . . . . . . . . Line Continuation . . . . . . . . . . . . . . Target Language Values . . . . . . . . . . . . Target Language Expressions . . . . . . . . . Formatting . . . . . . . . . . . . . . . . . Conditional Inclusion . . . . . . . . . . . .
2 Working with the Target Language Why Use the Target Language Compiler? If you simply need to produce ANSI C code from a Simulink model, you do not need to use the Target Language Compiler. If you need to customize the output of Real-Time Workshop, the Target Language Compiler is the mechanism that you would use. Some uses of the Target Language Compiler are: • You need to change the way code is generated for a particular Simulink block. • You need to inline S-functions in your model.
The model.rtw File The model.rtw File Real-Time Workshop generates a model.rtw file from your Simulink model. The model.rtw file is a hierarchical database whose contents provide a description of the individual blocks within the Simulink model. model.rtw is an ASCII file of parameter-value pairs stored in a hierarchy of records defined by your model.
2 Working with the Target Language Scope 1 Scope 2 Scope 3 Scope 4 2-4 CompiledModel { Name Version . . . System { Type Name Identifier NumBlocks Block { Type Name Identifier TID RollRegions NumDataOutputPorts DataOutputPortIndices Parameters Parameter { Name Value String } Parameter { Name Value String } Parameter { Name Value String } } . . } } "gain1" "1.
The model.rtw File This example shows several records and corresponding subrecords by use of arrows. Parameter (Scope 4) is a subrecord of Block (Scope 3), which is a subrecord of System (Scope 2), which in turn is a subrecord of CompiledModel (Scope 1). The model.rtw file uses curly braces { and } to open and close scopes. Using scopes, you can access any value within the model.rtw file. The scope in this example begins with CompiledModel. You use periods (.) to access values within particular scopes.
2 Working with the Target Language Compiler Directives Syntax A target language file consists of a series of statements of the form %keyword [argument1, argument2, …] where keyword represents one of the Target Language Compiler’s directives, and [argument1, argument2, …] represents expressions that define any required parameters. For example, %assign sysNumber = sysIdx + 1 uses the %assign directive to change the value of the sysNumber parameter.
Compiler Directives Table 2-1: Target Language Compiler Directives (Continued) Type Construct Conditional inclusion %if constant-expression %else %elseif constant-expression %endif %switch constant-expression %case constant-expression %default %break %endswitch Multiple inclusion %foreach identifier = constant-expression /* Loops from 0 to N – 1 */ %break %continue %endforeach %roll identifier = roll-vector-expression, identifier = threshold-expression, block-expression [, type-string [,expression-lis
2 Working with the Target Language Table 2-1: Target Language Compiler Directives (Continued) Type Construct Output file control %openfile x optional-string "optional-mode" %closefile %selectfile identifier Input file control %include string %addincludepath string Debug statements %error tokens %warning tokens %trace tokens %exit tokens Macro definition %define identifier opt-argument-list replacement-list %undef Identifier definition %assign [::]expression = constant-expression Scoping %with
Compiler Directives Use the /%...%/ construct to delimit comments within your code. Use the %% construct for line-based comments; all characters from %% to the end of the line become a comment. Nondirective lines, that is, lines that do not have % as their first nonblank character, are copied into the output buffer verbatim. For example, /* Initialize sysNumber */ int sysNumber = 3; copies both lines to the output buffer.
2 Working with the Target Language Target Language Values Table 2-2 shows the types of values you can use within the context of expressions in your target language files: Table 2-2: Target Language Values 2-10 Value Type String Example Description "Boolean" 1==1 Result of a comparison or other Boolean operator. Note: There are no Boolean constants, and Boolean values are 1 or 0 as in C. 1 is still a number and not a Boolean value. "File" %openfile x String buffer opened with %openfile.
Compiler Directives Table 2-2: Target Language Values (Continued) Value Type String Example Description "Matrix" Matrix (3,2) [ [ 1, 2] [3 , 4] [ 5, 6] ] Matrices are simply lists of vectors. The individual elements of the matrix do not need to be the same type, and can be any type except vectors or matrices. "Number" 15 An integer number. "Range" 1:5 A range of integers between 1 and 5, inclusive, cannot be specified except in the .
2 Working with the Target Language Table 2-2: Target Language Values (Continued) 2-12 Value Type String Example Description "String" "Hello, World" ASCII character strings. In all contexts, two strings in a row are concatenated to form the final value, as in "Hello, " "World", which is combined to form "Hello, World". These strings include all of the ANSI C standard escape sequences such as \n, \r, \t, etc. "Subsystem" A subsystem identifier.
Compiler Directives Target Language Expressions In any place throughout a target file, you can include an expression of the form %. The Compiler replaces expression with a calculated replacement value based upon its type. Integer constant expressions are folded and replaced with the resultant value; string constants are concatenated (e.g., two strings in a row "a" "b" are replaced with "ab"). % /* * * * * Evaluates the expression.
2 Working with the Target Language This statement would cause an error if foo was undefined. Table 2-3: Target Language Expressions 2-14 Expression Definition constant Any constant parameter value, including vectors and matrices. variable-name Any valid in-scope variable name, including the local function scope, if any, and the global scope. ::variable-name Used within a function to indicate that the function scope is ignored when looking up the variable. See “Identifier Definition” on page 2-37.
Compiler Directives Table 2-3: Target Language Expressions (Continued) Expression Definition –expr Unary minus negates the expression. The argument must be numeric. +expr No effect; the operand must be numeric. ~expr Bitwise negation of the operand. The argument must be integral. expr* expr Multiply the two expressions together; the operands must be numeric. expr/ expr Divide the two expressions; the operands must be numeric.
2 Working with the Target Language Table 2-3: Target Language Expressions (Continued) 2-16 Expression Definition expr– expr Subtracts the two expressions; the operands must be numeric. expr<< expr Left shifts the left operand by an amount equal to the right operand; the arguments must be integral. expr>>expr Right shifts the left operand by an amount equal to the right operand; the arguments must be integral.
Compiler Directives Table 2-3: Target Language Expressions (Continued) Expression Definition expr && expr Performs the logical AND of the two arguments and returns 1 or 0. This can be used on either numeric or Boolean arguments. expr || expr Performs the logical OR of the two arguments and returns 1 or 0. This can be used on either numeric or Boolean arguments. expr ? expr : expr Tests the first expression for logical truth.
2 Working with the Target Language Conditional Inclusion The conditional inclusion directives are %if constant-expression %else %elseif constant-expression %endif and %switch constant-expression %case constant-expression %break %default %endswitch %if The constant-expression must evaluate to an integral expression. It controls the inclusion of all the following lines until it encounters a %else, %elseif, or %endif directive.
Compiler Directives %switch The %switch statement evaluates the constant expression and compares it to all expressions appearing on %case selectors. If a match is found, the body of the %case is included; otherwise the %default is included. %case ... %default bodies flow together, as in C, and %break must be used to exit the switch statement. %break will exit the nearest enclosing %switch, %foreach, or %for loop in which it appears. For example: %switch(type) %case x /* Matches variable x.
2 Working with the Target Language identifier variable. %break and %continue are optional directives that you can include in the %foreach directive: • %break can be used to exit the nearest enclosing %for, %foreach, or %switch statement. • %continue can be used to begin the next iteration of a loop.
Compiler Directives identifier2 specifies the identifier to be used for testing whether the loop was rolled within the body. For example, %for Index = 3, rollvar="i" { int i; for (i=0; i< %; i++) { %body x[%] = system_name[%]; %endbody } } %endfor If the number of nonvirtual subsystems (NumNonVirtualSubsystems) is greater than or equal to 3, the loop is rolled, causing all of the code within the loop to be generated exactly once.
2 Working with the Target Language %roll The syntax of the %roll multiple inclusion directive is: %roll ident1 = roll-vector-exp, ident2 = threshold-exp, ... block-exp [, type-string [,exp-list] ] %break %continue %endroll This statement uses the roll-vector-exp to expand the body of the %roll statement multiple times as in the %foreach statement. If a range is provided in the roll-vector-exp and that range is larger than the threshold-exp expression, the loop will roll.
Compiler Directives LoopTrailer(block, Startidx, Niterations, Nrolled, …). This function is called once for each section that will roll after the body of the %roll statement. RollTrailer(block, …). This function is called once at the end of the %roll statement if any of the ranges caused loop rolling. These functions should output any language-specific declarations, loop code, and so on as required to generate correct code for the loop. An example of a Roller.
2 Working with the Target Language Extending the former example to a loop that rolls: %language "C" %assign ablock = BLOCK { Name "Hi" } %roll Idx = [ 1:20, 21, 22, 23:25, 26:46], lcv = 10, ablock Block[%< lcv == "" ? Idx : lcv>] *= 3.0; %endroll This TLC code produces the output: { int i; for (i = 1; i < 21; i++) { Block[i] *= 3.0; } Block[21] *= 3.0; Block[22] *= 3.0; Block[23] *= 3.0; Block[24] *= 3.0; Block[25] *= 3.0; for (i = 26; i < 47; i++) { Block[i] *= 3.
Compiler Directives appear prior to the first GENERATE or GENERATE_TYPE built-in function call. %language specifies the language as a string. For example: %language "C" All blocks in Simulink have a Type parameter. This parameter is a string that specifies the type of the block, e.g., "Sin" or "Gain". The object-oriented facility uses this type to search the path for a file that implements the correct block. By default the name of the file is the Type of the block with .
2 Working with the Target Language appearing in an implementation file (from outside the specified file) only by using the GENERATE and GENERATE_TYPE special functions. The GENERATE function takes two or more input arguments. The first argument must be a valid scope and the second a string containing the name of the function to call. The GENERATE function passes the first block argument and any additional arguments specified to the function being called.
Compiler Directives Output File Control The structure of the output file control construct is: %openfile string optional-equal-string optional-mode %closefile id %selectfile id The %openfile directive opens a file or buffer for writing; the required string variable becomes a variable of type file. For example: %openfile x %openfile out = "out.h" /% Opens and selects x for writing. %/ /% Opens "out.h" for writing.
2 Working with the Target Language Input File Control The input file control directives are: %include string %addincludepath string The %include directive searches the path for the target file specified by string and includes the contents of the file inline at the point where the %include statement appears. The %addincludepath directive adds an additional include path to be searched when the Target Language Compiler references %include or block target files.
Compiler Directives Typically, %addincludepath directives should be specified in your system target file. Multiple %addincludepath directives will add multiple paths to the Target Language Compiler search path. Errors, Warnings, and Debug Messages The related error, warning, and debug message directives are: %error tokens %warning tokens %trace tokens %exit tokens These directives produce error, warning, or trace messages whenever a target file detects an error condition, or tracing is desired.
2 Working with the Target Language defined in uppercase so that they are visually distinct from other parameters in the .rtw file, and by convention, from user-defined parameters. Table 2-4: TLC Built-in Functions and Values 2-30 Special Macro Name Expansion CAST(expr, expr) The first expression must be a string that corresponds to one of the type names in the Target Language Values table, and the second expression will be cast to that type.
Compiler Directives Table 2-4: TLC Built-in Functions and Values (Continued) Special Macro Name Expansion FORMAT(expr1, expr2) The first expression is a Real value to format. The second expression is either "EXPONENTIAL" or "CONCISE". Outputs the Real value in the designated format where EXPONENTIAL uses exponential notation with 16 digits of precision, and CONCISE outputs the number in a more readable format while maintaining numerical accuracy. GENERATE(expr1, expr2, ...
2 Working with the Target Language Table 2-4: TLC Built-in Functions and Values (Continued) Special Macro Name Expansion GENERATE_TYPE_FUNCTION_EXISTS (expr1, expr2, expr3) Same as GENERATE_FUNCTION_EXISTS except it overrides the Type built into the object. See the description of GENERATE_TYPE for more information. IDNUM(expr) expr must be a string. The result is a vector where the first element is a leading string (if any) and the second element is a number appearing at the end of the input string.
Compiler Directives Table 2-4: TLC Built-in Functions and Values (Continued) Special Macro Name Expansion SIZE(expr[,expr]) Calculates the size of the first expression and generates a two-element, row vector. If the second operand is specified, it is used as an integral index into this row vector; otherwise the entire row vector is returned. SIZE(x) applied to any scalar returns [1 1]. SIZE(x) applied to any scope returns the number of repeated entries of that scope type (e.g.
2 Working with the Target Language Table 2-4: TLC Built-in Functions and Values (Continued) Special Macro Name Expansion STRINGOF(expr) Accepts a vector of ASCII values and returns a string that is constructed by treating each element as the ASCII code for a single character. Used primarily for S-function string parameters in RTW. SYSNAME(expr) Looks for specially formatted strings of the form /y and returns x and y as a 2-element string vector. This is used to resolve subsystem names in RTW.
Compiler Directives Table 2-4: TLC Built-in Functions and Values (Continued) Special Macro Name Expansion TYPE(expr) Evaluates expr and determines the result type. The result of this function is a string that corresponds to the type of the given expression. See value type string in the Target Language Values table for possible values. WHITE_SPACE(expr) Accepts a string and returns 1 if the string contains only whitespace characters ( , \t, \h, \r) and 0 otherwise.
2 Working with the Target Language When calling MATLAB, these conversions are made: TLC Type MATLAB Type "Boolean" or "Number" or “Real” Double Scalar "String" Char Vector "Vector" If the vector is entirely strings, then Char Matrix. If it is entirely numeric, then Double Vector. Otherwise, it is an error.
Compiler Directives Macro Definition To simplify complicated references, target files can define macros that are expanded when they appear in subsequent expressions. %define identifier opt-argument-list replacement-list To undefine a previously defined macro, use: %undef identifier identifier is the name of the macro being defined or undefined; opt-argument-list is either a C macro argument list or is omitted; replacement-list is an expansion list similar to a C language macro.
2 Working with the Target Language Within the scope of a function, variable assignments always create new local variables unless you use the :: scope resolution operator. For example, given a local variable foo and a global variable foo: %function … … %assign foo = 3 … %endfunction In this example, the assignment always creates a variable foo local to the function that will disappear when the function exits. Note that foo is created even if a global foo already exists.
Compiler Directives Creating Records Use the %assign directive to create new records. For example, if you have a record called Rec1 that contains a record called Rec2, and you want to add an additional Rec2 to it, use: %assign tempVar = Rec2 { Name "Name1"; Type "t1" } %assign Rec1 = Rec1 + Rec2 The first statement creates the new Rec2 and the second statement adds the new Rec2 to the existing Rec2.
2 Working with the Target Language This produces: Rec1 { Rec2 { Name Type } Rec2 { Name Type } Rec2 { Name Type } . . } "Name0" "t0" Existing Record "Name1" "t1" First New Record "Name2" "t2" Second New Record Figure 2-2: Creating Multiple Records Adding Parameters to an Existing Record You can use the %assign directive to add a new parameter to an existing record. For example, %assign N = 500 %assign x = Block[Idx] + N %assign myn = Block[Idx].
Compiler Directives adds a new parameter, N, at the end of an existing block with the name and current value of an existing variable as shown in Figure 2-3. It returns the block value. Block { . . . N } New Parameter 500 Figure 2-3: Parameter Added to Existing Record Scoping The structure of the %with directive is: %with expression %endwith The %with directive adds a new scope to be searched onto the current list of scopes. This directive makes it easier to refer to block-scoped variables.
2 Working with the Target Language Variable Scoping The Target Language Compiler uses a form of dynamic scoping to resolve references to variables. This section illustrates the process that the Target Language Compiler performs in determining the values of variables. In the simplest case, to resolve a variable the Target Language Compiler searches the top-level RTW pool followed by the global pool. This illustration shows the search sequence that the Target Language Compiler uses.
Compiler Directives The System[Sysidx] scope is added to the search list, and it is searched before anything else. Global Pool %assign a = … %assign b = … … 3 Top-Level RTW Pool CompiledModel { … } %with CompiledModel. System[Sysidx] 2 1 Figure 2-5: Modifying the Search Sequence Using this technique makes it simpler to access embedded definitions. For example, to refer to the system name without using %with, you would have to use: CompiledModel.System[Sysidx].
2 Working with the Target Language The scoping rules within functions behave differently. A function has its own scope, and that scope gets added to the previously described list as depicted in this figure. Global Pool %assign a = … %assign b = … … 4 Top-Level RTW Pool CompiledModel { … } %with CompiledModel.
Compiler Directives A function optionally returns a value with the %return directive. The returned value can be any of the types defined in the Target Language Values table. In this example, a function, name, returns x, if x and y are equal, and returns z, if x and y are not equal. %function name(x,y,z) void %if x == y %return x %else %return z %endif %endfunction Function calls can appear in any context where variables are allowed.
2 Working with the Target Language Variable Scoping Within Functions Within a function, the left-hand member of any %assign statement defaults to create a new entry in the function’s block within the scope chain, and does not affect any of the other entries. That is, it is local to the function.
Compiler Directives You can override this default behavior by using %assign with the :: operator. For example, %assign ::global = 3 makes global a global variable and initializes it to 3.
2 Working with the Target Language is not searched. Also, if a %with is included within a function, its associated scope is carried with any nested function call.
Compiler Directives %return The %return statement closes all %with statements appearing within the current function. In this example, the %with statement is automatically closed when the %return statement is encountered, removing the scope from the list of searched scopes.
2 Working with the Target Language Target Language Compiler Command Line Arguments To call the Target Language Compiler, use: tlc [switch1 expr1 switch2 expr2 …] filename.tlc Table 2-5 lists the switches you can use with the Target Language Compiler. Order makes no difference. Table 2-5: Target Language Compiler Switches 2-50 Switch Meaning –r filename Reads a database file (such as a .rtw file). Repeat this option multiple times to load multiple database files into the Target Language Compiler.
Target Language Compiler Table 2-5: Target Language Compiler Switches (Continued) Switch Meaning –d[n|g|o] Specifies the level and type of debugging. By default, debugging is off (–do). –d defaults to –dn, or normal mode debugging, and –dg is generate mode debugging. –aident=expr Specifies an initial value for some parameters; equivalent to the %assign command. Use this to control template generation by querying its value. As an example, the command line tlc –r Demo.rtw –v grt.
2 Working with the Target Language The output of the listing file includes the number of times each line is encountered followed by a colon.
Target Language Compiler 1: %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) 1: %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) 1: %assign k = LibBlockParameter(Gain, "", lcv, sigIdx) 1: %if InlineParameters == 1 0: %\ 1: %else 1: % = % * %; 1: %endif 1: %endroll 1: 1: %endfunction 1: 1: %% [EOF] gain.tlc This structure makes it easy to identify branches not taken and to develop new tests that can exercise unused portions of the target files.
2 Working with the Target Language 2-54
3 Writing Target Language Files A Basic Example . . . . . . . . . . . . . . . . . . 3-2 Process . . . . . . . . . . . . . . . . . . . . . . . 3-2 Target Language Compiler Architecture . . . . . . . 3-6 System Target Files . . . . . . . . . . . . . . . . . . 3-6 Block Functions . . . . . . . . . . . . . . . . . . . 3-7 Coding Conventions . . . . . . . . . . . . . . . . 3-8 Writing a Block Target File . . . . . . . . . . . . . 3-15 TLC Block Setup Functions . . . . . . . . . . . . . .
3 Writing Target Language Files A Basic Example This section presents an elementary example of creating a target language file that generates specific text from an RTW model. This example shows the sequence of steps that you should follow in creating and using your own target language files. Process Figure 3-1 shows the Simulink model, basic.mdl.
A Basic Example Selecting Parameters from Simulink’s Simulation menu displays the dialog box shown in Figure 3-2.
3 Writing Target Language Files Clicking the Build button generates the .rtw file, basic.rtw, and executes the system target file, basic.tlc with the –v option, that is specified under Code generation. The structure of basic.rtw is: CompiledModel { Name Version GeneratedOn Solver SolverType StartTime StopTime FixedStepOpts { FixedStep } . . . NumModelInputs NumModelOutputs NumNonVirtBlocksInModel DirectFeedthrough NumContStates NumDiscStates . . . BlockOutputs { NumBlockOutputs BlockOutput { . . .
A Basic Example The file, basic.tlc, is a TLC file that uses the .rtw code to generate text that contains the model’s name, generation date, and its number of continuous states. basic.tlc %with CompiledModel My model's name is: % It was generated on: % And it has % continuous states. %endwith Instead of using the Simulation Parameters dialog from Simulink’s Simulation menu, you could perform the same functions directly from the MATLAB prompt. To create basic.
3 Writing Target Language Files Target Language Compiler Architecture System Target Files Table 3-1 lists the system target files that generate the RTW code. Table 3-1: System Target Files System Target File Purpose grt.tlc Assigns specific variables required for generic real-time code generation, and is the Target Language Compiler entry point. mdlwide.tlc Assigns more generalized variables required for RTW code generation, and is included by grt.tlc. mdlbody.tlc Included by mdlwide.tlc. mdlreg.
Target Language Compiler Architecture Program flow through the system target files avoids multiple passes through the RTW file. You should not change the order of code generation without first performing a thorough analysis of the file dependencies. For example, the parameters structure is not created until all source code has been generated. This technique eliminates unused parameters. Block Functions The functions declared inside each of the block target files are exercised by the system target files.
3 Writing Target Language Files Coding Conventions The following guidelines help ensure that the programming style in each TLC file is consistent, and hence, more easily modifiable. 1 All identifiers in the RTW file begin with a capital letter. For example, NumContStates NumBlocks 10 52 Note that block records that contain a Name identifier should start the name with a capital letter since the Name identifier is often promoted into the parent scope.
Coding Conventions of the Name identifier into the parent block scope is currently done for the Parameter, RWorkDefine, IWorkDefine, and PWorkDefine block records. The TLC assignment directive (%assign) generates a warning if you assign a value to an “unqualified” RTW identifier. For example, %assign TID = 1 will produce an error because TID identifier is not qualified by Block. However, a “qualified” assignment will not generate a warning. %assign Block.
3 Writing Target Language Files inside the library file, it should start with Fcn and the function should be placed at the bottom of funclib.tlc. %% %% Global TLC Functions (start with Lib) %% %function LibGlobalTLCFunction(...) %% %% Local TLC Functions (start with Fcn) %% %function FcnLocalTLCFunction(...) 5 Functions declared inside a block.tlc file start with Fcn. For example, %function FcnMyBlockFunc(...
Coding Conventions Table 3-4: TLC Global Variables Specifying RTW Global Variables Description TLC Global Variable Default Value Block I/O tBlockIO rtB Block Signal Information tModelBlockInfo rtModelBlockInfo Control Port Index tControlPortIdx controlPortIdx Data Store Memory tParameters rtP External Inputs tInput rtU External Outputs tOutput rtY Ground (Unconnected block input) tGROUND rtGROUND Infinity tInf rtInf Integer-Work tRWork rtRWork Minus Infinity tMinusInf rtMinu
3 Writing Target Language Files Table 3-5: TLC Global Variables Specifying RTW Global Functions Description TLC Global Variable Default Value Log variable create function tCreateLogVar rt_CreateLogVar Log variable update function tUpdateLogVar rt_UpdateLogVar Zero-crossing function tZCFcn rt_ZCFcn 7 This convention creates consistent variables throughout the TLC files.
Coding Conventions Notes about this TLC code: Note 1 The code section for each block begins with a comment specifying the block type and name. Note 2 Include a blank line immediately after the end of the function in order to create consistent spacing between blocks in the output code. Note 3 Try to stay within 80 columns per line for the function banner. You might set up an 80 column comment line at the top of each function. As an example, see constant.tlc.
3 Writing Target Language Files Target Language Compiler function library, funclib.tlc, contains this TLC code to prevent multiple inclusion: %if EXISTS("_FUNCLIB_") == 0 %assign _FUNCLIB_ = 1 . . . %endif %% _FUNCLIB_ The name of the variable should be the same as the base filename in uppercase with additional underscores attached at both ends.
Writing a Block Target File Writing a Block Target File To write a block target file, use these polymorphic block functions combined with the Target Language Compiler library functions declared in funclib.tlc. For a complete list of the Target Language Compiler library functions, see Chapter 4, “Target Language Compiler Function Library Reference.” A brief description of the necessary block and library functions follow.
3 Writing Target Language Files %function BlockInstanceSetup(block, system) void %% Rename S-function parameter so that the TLC and %% generated code is more readable (P1 --> Gain) % %% Define the RWork vector to make the code more %% readable, and to allow the RWork to be rolled %% inside the %roll construct. % %endfunction Now you can reference P1 as PrevU in the Target Language Compiler.
Writing a Block Target File As an example, given S-function foo requiring a #define and two function declarations in the header file, you could define the following function.
3 Writing Target Language Files Start(block, system) Include a Start function to place code into MdlStart. The code inside MdlStart executes once and only once. Typically, you include a Start function to execute code once at the beginning of the simulation (e.g., initialize values in the work vectors; see backlash.tlc,) or code that does not need to be re-executed when the subsystem in which it resides enables. See constant.tlc for an example of the Start function.
Writing a Block Target File Update(block, system) Include an Update function if the block has code that needs to be updated each major time step. Code generated from this function is either placed into MdlUpdate or the subsystem’s Update function, depending on whether or not the block resides in a nonvirtual subsystem. See delay.tlc for an example of the Update function. Derivatives(block, system) Include a Derivatives function when generating code to compute the block’s states.
3 Writing Target Language Files The RTW TLC Function Library The file funclib.tlc contains the RTW TLC function library. This file contains the necessary TLC functions required to write a block target file. Chapter 4, “Target Language Compiler Function Library Reference,” contains detailed descriptions of all the TLC functions. This section focuses on the most commonly used TLC functions, providing a general description of the functions.
The RTW TLC Function Library Table 3-6: Common TLC Functions (Continued) LibBlockIWork(iworkRef, ucv, lcv, sigIdx) LibBlockPWork(pworkRef, ucv, lcv, sigIdx) LibCacheNonFiniteAssignment(assignment) LibPrevZCState(ucv, lcv, sigIdx) LibDataStoreMemory(ucv, lcv, varIdx) LibPathName(name) LibIsFinite(value) LibRenameParameter(block, param, newName) LibBlockOutportLocation(ucv, lcv, sigIdx) LibDefineRWork(block, name, width) This call should be made from inside the block’s BlockInstanceSetup function, and adds
3 Writing Target Language Files buffer. The prototypes are placed inside model.h among other generated function prototypes. LibCacheDefine(buffer) LibCacheDefine should be called from inside BlockTypeSetup to cache a #define statement. Each call to this function appends your buffer to the existing cache buffer. The #define statements are placed inside model.h among other generated #define statements.
The RTW TLC Function Library they generate different results depending on whether RTW is in a loop-rolling state, or a non loop-rolling state, respectively. Loop rolling is fully described later in this chapter. In short, however, this function looks at ucv, lcv, and sigIdx, and the RTW state to determine the return value. The variable ucv has highest precedence, lcv has the next highest precedence, and sigIdx has the lowest precedence. That is, if ucv is specified, it will be used.
3 Writing Target Language Files For an example of this function, see gain.tlc. Note 1: Do not use this function to build the address of a parameter. For example, %assign paramAddr = "&%" This may produce a reference to a constant number, for example &4.95 if the value of Gain is 4.95, and RTW is configured to inline parameter values. Use LibBlockParameterAddr to avoid this undesirable behavior. Note 2: Code generation exits if this function is passed a matrix parameter.
The RTW TLC Function Library columns of your matrix. This function will degenerate to a vector or scalar, if needed. Note: Do not use this function to build the address of a parameter. For example, %assign paramAddr = "&%" This may produce a reference to a constant number, for example, &4.95 f the value of TruthTable is 4.95, and RTW is configured to inline parameter values. Instead, use the TLC function LibBlockParameterAddr to avoid this undesirable behavior.
3 Writing Target Language Files LibBlockRWork(rworkRef, ucv, lcv, sigIdx) LibBlockIWork(iworkRef, ucv, lcv, sigIdx) LibBlockPWork(pworkRef, ucv, lcv, sigIdx) The behavior of these functions is similar to LibBlockOutputSignal, except they return the appropriate reference to the block’s RWork, IWork, and PWork. The additional arguments, rworkRef, iworkRef, and pworkRef, are references to the block internal records RWorkDefine, IWorkDefine, and PWorkDefine, respectively.
The RTW TLC Function Library LibRenameParameter(block, param, newName) Given a reference to a block, a reference to a block parameter, and the new name for the block parameter, this function renames the parameter and creates a new reference to the parameter. Most likely, you will call this function from BlockInstanceSetup.
3 Writing Target Language Files Call LibRenameParameter(Block, Parameter[1], "Kp"), which renames P1 to Kp and creates a Kp identifier that references the Parameter[1]. The block record becomes: System { Block { Name "sfunc" Type "S-Function" : Parameter { Name "P1Size" Value [1, 1] String "" } Parameter { Name "Kp" Value 2.
The RTW TLC Function Library Note: By convention, start parameter names with a capital letter since the Name identifier of the Parameter record is promoted into the parent block scope. It is not mandatory that you do so, however, the Target Language Compiler will exit if you attempt this assignment: %assign kp = LibBlockParameter(kp, "", "", 0) The Target Language Compiler exits because it does not know if the first kp is the block identifier kp or a local variable kp.
3 Writing Target Language Files Built-In TLC Functions The most common built-in TLC functions required to write a block target file are STRINGOF, EXISTS, and SIZE. STRINGOF(value) Given an RTW string vector, this function returns the reconstructed string. For example, this function returns the string "float". % The built-in function SIZEOF is commonly used to reconstruct S-function parameters that are literal strings.
Inlining an S-Function Inlining an S-Function When a Simulink model contains an S-function and a corresponding .tlc file, Real-Time Workshop inlines the S-function. Inlining an S-function can produce more efficient code by eliminating the S-function API layer from the generated code. S-functions that are not inlined make calls to all of these seven functions, even if the routine is empty for the particular S-function: S-Function Purpose mdlInitializeSizes Initialize the sizes array.
3 Writing Target Language Files In general, inlining an S-function is especially useful when: • The time required to execute the contents of the S-function is small in comparison to the overhead required to call the S-function. • Certain S-function routines are empty (e.g., mdlUpdate). • The behavior of the S-function changes between simulation and code generation.
Inlining an S-Function { y[0] = u[0] * GAIN; } static void mdlInitializeSampleTimes(SimStruct *S){} static void mdlInitializeConditions(real_T *x0,SimStruct *S) {} static void mdlUpdate(real_T *x, const real_T *u,SimStruct *S, int_T tid) {} static void mdlDerivatives(real_T *dx, const real_T *x const real_T *u, SimStruct *S, int_T tid) {} static void mdlTerminate(SimStruct *S) {} #ifdef MATLAB_MEX_FILE #include "simulink.c" #else #include "cg_sfun.
3 Writing Target Language Files void MdlOutputs(tid) { /* S-Function block: foo */ { Simstruct *s = ssGetSFunction(S, 0); real_T *sfcnU = ssGetU(s); real_T *sfcnX = ssGetX(s); real_T *sfcnY = ssGetY(s); sfcnOutputs(sfcnY, sfcnX, sfcnU, s, tid); } } void MdlUpdate(tid) { /* S-Function block: foo */ { Simstruct *s = ssGetSFunction(S, 0); real_T *sfcnX = ssGetX(s); real_T *sfcnU = ssGetU(s); sfcnUpdate(sfcnX, sfcnU, s, tid); } } 3-34 Unnecessary call to empty function mdlUpdate in foogain.c.
Inlining an S-Function void MdlDerivatives() { /* S-Function block: foo */ { Simstruct *s = ssGetSFunction(S, 0); real_T *sfcnU = ssGetU(s); real_T *sfcnX = ssGetX(s); real_T *sfcndX = ssGetdX(s); Unnecessary call to empty function mdlDerivatives in foogain.c. sfcnDerivatives(sfcndX, sfcnX, sfcnU, s, tid); } } void MdlTerminate() { /* S-Function block: foo */ { Simstruct *s = ssGetSFunction(S, 0); sfcnTerminate(s); } } Unnecessary call to empty function mdlTerminate in foogain.c.
3 Writing Target Language Files /* Register children S-Functions (s-funcs without TLC files) */ { static SimStruct childSFunctions[1]; static SimStruct *childSFunctionPtrs[1]; ssSetSFunctions(S, (SimStruct **) &childSFunctionPtrs[0]); /* S-Function Block: foo */ { static real_T sfcnPeriod[1]; static real_T sfcnOffset[1]; static real_T sfcnTsMap[1]; static mxArray *sfcnParams[1]; extern void foogain(SimStruct *); SimStruct *s = &childrenSFunctions[0]; Note 3 memset((char *) s, 0, sizeof(SimStruct)); ssSe
Inlining an S-Function To avoid unnecessary calls to the S-function and to generate the minimum code required for the S-function, the following TLC file is provided as an example. foogain.
3 Writing Target Language Files By including this simple target file for this S-function block, the code is generated as: void MdlStart(){} void MdlOutputs(tid) { /* S-Function block: foo */ rtB.foo = rtGROUND * rtP.foo.
Inlining an S-Function Note 2 The input to foo is rtGROUND (an RTW global equal to 0.0) since foo is the only block in the model, and its input is unconnected. Had it been connected to block sinewave, the generated line would have been rtB.foo = rtB.sinewave * rtP.foo.gain; Note 3 Including a TLC file for foogain eliminated the need for an S-function registration segment for foogain. This significantly reduces code size.
3 Writing Target Language Files Configurable RTW Variables This table lists the configurable RTW variables. Table 3-7: Configurable RTW Variables Variable Purpose InlineParameters Inlines parameter values in the generated code. Possible values are 0 or 1 with a default of 0. FileSizeThreshold Specifies the maximum number of lines to output to model.c before the file is split into model1.c, model2.c, etc. Default value is 50,000 lines.
Inlining an S-Function Figure 3-3 shows the RTW dialog box with the change to modify the FileSizeThreshold. Figure 3-3: RTW Dialog Box Matrix Parameters in RTW MATLAB matrices are the transpose of RTW matrices, with the exception of S-function blocks, which use the MATLAB representation. MATLAB uses column-major ordering and RTW uses row-major ordering for everything except S-function blocks. The Target Language Compiler follows this behavior to ensure backward compatibility.
3 Writing Target Language Files For example, given the 2-by-3 matrix 1 2 3 4 5 6 model.h defines: typedef struct Parameters_tag = { struct { /* S-function */ real_T matSize[2]; real_T mat[3][2]; } sfuncBlock; struct { /* any non S-function */ real_T mat[2][3]; } nonSfuncBlock; } Parameters; model.
Inlining an S-Function unless it is explicitly accessed by LibBlockParameter or LibBlockParameterAddr.
3 Writing Target Language Files Loop Rolling The best way to explain loop rolling is by example. Figure 3-4 shows a Simulink model with a Gain block.
Loop Rolling The outputs function for the Gain block is: %% Function: Outputs =========================================== %% Abstract: %% Y = U * K %% %function Outputs(block, system) Output /* % Block: % */ %assign rollVars = ["U", "Y", "P"] %roll sigIdx = RollRegions, lcv = RollThreshold, block,...
3 Writing Target Language Files For example, the Gain block in this example is defined in the RTW file as: Block { Type Name Identifier TID RollRegions NumDataInputPorts . . . Parameter { Name Value String } } Gain "/Kp" Kp 0 [0:99, 100, 101, 102:112] 1 1 2 3 4 "Gain" [2.5] "2.
Loop Rolling The generated code for this example is: /* Gain Block: /Kp */ { int_T i1; real_T *u0 = &rtB.Constant1[0]; real_T *y0 = &rtB.Kp[0]; for(i1 = 0; i1 < 100; i1++) { y0[i1] = u0[i1] * rtP.Kp.Gain; } RollRegion 1 rtB.Kp[100] = rtB.Constant2[1] * rtP.Kp.Gain; rtB.Kp[101] = rtB.Constant2[0] * rtP.Kp.Gain; RollRegions 2&3 u0 = &rtB.Constant3[0]; y0 = &rtB.Kp[102]; for(i1 = 0; i1 < 11; i1++) { y0[i1] = u0[i1] * rtP.Kp.Gain; } RollRegion 4 } Note that %roll requires rollVars to be specified.
3 Writing Target Language Files with the %roll that works under both situations. Table 3-8 contains the valid variables assigned to rollVars.
4 Target Language Compiler Function Library Reference LibBlockFunctionExists . . . LibBlockInputSignal . . . . LibBlockIWork . . . . . . . LibBlockMatrixParameterAddr LibBlockMatrixParameter . . LibBlockMode . . . . . . . LibBlockOutportLocation . . LibBlockOutputSignal . . . . LibBlockParameter . . . . . LibBlockParameterAddr . . . LibBlockPWork . . . . . . LibBlockRWork . . . . . . LibBlockSrcSignalIsDiscrete . LibCacheDefine . . . . . . LibCacheFunctionPrototype . LibCacheGlobalPrmData . .
LibBlockFunctionExists Purpose Determines if a given block function exists LibBlockFunctionExists Syntax % Arguments block Reference to a block record. fcn Function to check (e.g., "Outputs"). Returns Value 1 Specified function exists. 0 Specified function does not exist, but TLC file does. –1 Description 4-2 Condition TLC file does not exist. Determines if a given block function exists.
LibBlockInputSignal Purpose Determines the input signal label based on the type of input signal LibBlockInputSignal Syntax % Arguments portNum Integer data input port number. ucv User control variable string. lcv Loop control variable string. sigIdx Integer offset into block signal. Returns The input signal label based on the type of input signal, i.e., U, X, B, or G.
LibBlockIWork Purpose Determines the appropriate iwork element LibBlockIWork Syntax % Arguments iwork Reference to iwork identifier or "" if there are no IWorkDefine records in the block. ucv User control variable string. lcv Loop control variable string. idx Integer index into this iwork. Returns The appropriate iwork element. Description This function returns the appropriate iwork element.
LibBlockMatrixParameterAddr Purpose Determines the address of a block’s matrix parameter LibBlockMatrixParameterAddr Syntax % Arguments param Reference to a block parameter identifier. rucv Row user control variable string. rlcv Row loop control variable string (Not Supported). ridx Integer row index. cucv Column user control variable string. clcv Column loop control variable string (Not Supported).
LibBlockMatrixParameter Purpose Determines the appropriate matrix parameter for a block given the row and column user control variable, loop control variable, and index. LibBlockMatrixParameter Syntax % Arguments param Reference to a block parameter identifier. rucv Row user control variable string. rlcv Row loop control variable string (Not Supported). ridx Integer row index. cucv Column user control variable string.
LibBlockMode Purpose Determines the appropriate block mode LibBlockMode Syntax % Arguments ucv User control variable string. lcv Loop control variable string. modeIdx Integer mode index. Returns The appropriate block mode based on ucv, lcv, and modeIdx. Description LibBlockMode returns the appropriate block mode.
LibBlockOutportLocation Purpose Determines the appropriate identifier for an outport block LibBlockOutportLocation Syntax % Arguments ucv User control variable string. lcv Loop control variable string. sigIdx Integer offset into block signal. Returns The appropriate identifier for an outport block. Description LibBlockOutportLocation returns the appropriate identifier for an outport block. Output location is Y: 4-8 Y.block[ucv] ucv is specified.
LibBlockOutportLocation Output location is B: B.block[ucv] ucv is specified. y0[lcv] lcv is specified and signal is wide. B.block lcv is specified and signal is scalar. B.block[sigIdx] Otherwise. Notes: The index is appropriately replaced with ucv or lcv when specified (ucv has higher precedence than lcv). The width of the output port is determined by the width of the input port.
LibBlockOutputSignal Purpose Determines the block’s output signal. LibBlockOutputSignal Syntax % Arguments portNum Integer port number. ucv User control variable string. lcv Loop control variable string. sigIdx Integer offset into block signal. Returns The block’s output signal. Description LibBlockOutputSignal returns the block’s output signal. The result is determined by the values of ucv, lcv, and sigIdx. The result is as follows: B.
LibBlockParameter Purpose Determines a block’s parameter in the appropriate form depending on the state of loop rolling LibBlockParameter Syntax % Arguments param Reference to a block parameter identifier. ucv User control variable string. lcv Loop control variable string. sigIdx Integer offset into signal. Returns A block’s parameter in the appropriate form depending on the state of loop rolling, InlineParameters, and the specified index.
LibBlockParameter Case Rolling InlineParameters Type Result P Needed in Memory 1 0 1 scalar 4.55 no 2 1 1 scalar 4.55 no 3 0 1 vector 4.55 no 4 1 1 vector p_Gain[i] yes 5 0 0 scalar rtP.blk.Gain no 6 1 0 scalar rtP.blk.Gain no 7 0 0 vector rtP.blk.prm[0] no 8 1 0 vector p_Gain[i] yes Note: Case 4 maintains the parameter even though InlineParameters is selected. Do not use this function if you’re using the result to get the address of a parameter.
LibBlockParameterAddr Purpose Determines the address of a block parameter. LibBlockParameterAddr Syntax % Arguments param Reference to a block parameter identifier. ucv User control variable string. lcv Loop control variable string. idx Integer index. Returns The address of a block parameter. Description LibBlockParameterAddr returns the address of a block parameter as: &P.block.param[ucv] If ucv is specified. &P.block.
LibBlockPWork Purpose Determines the appropriate pwork element LibBlockPWork Syntax % Arguments pwork Reference to pwork identifier or "" if there are no PWorkDefine records in the block. ucv User control variable string. lcv Loop control variable string. idx Integer index into this pwork. Returns The appropriate pwork element. Description LibBlockPWork returns appropriate pwork element.
LibBlockRWork Purpose Determines the appropriate rwork element LibBlockRWork Syntax % Arguments rwork Reference to rwork identifier or "" if there are no RWorkDefine records in the block. ucv User control variable string. lcv Loop control variable string. idx Integer index into this rwork. Returns The appropriate rwork element. Description LibBlockRWork returns appropriate rwork element.
LibBlockSrcSignalIsDiscrete Purpose Determines if the driving signal is discrete LibBlockSrcSignalIsDiscrete Syntax % Arguments portNum Integer data input port number. sigIdx Integer offset into block input signal. Returns 1 (yes) or 0 (no). Description LibBlockSrcSignalIsDiscrete determines if the driving signal is discrete.
LibCacheDefine Purpose Call this function from inside BlockTypeSetup to cache a #define statement. LibCacheDefine Syntax % Arguments buffer Buffer of #define statements to be cached. Description Example LibCacheDefine should be called from inside BlockTypeSetup to cache a #define statement. Each call to this function appends your buffer to the existing cache buffer. The #define statements are placed inside model.h.
LibCacheFunctionPrototype Purpose Call this function from inside BlockTypeSetup to cache a function prototype. LibCacheFunctionPrototype Syntax % Arguments buffer Buffer of function prototypes to be cached. Description Example 4-18 This function should be called from inside BlockTypeSetup to cache a function prototype. Each call to this function appends your buffer to the existing cache buffer. The prototypes are placed inside model.h.
LibCacheGlobalPrmData Purpose Call this function from inside BlockInstanceSetup to cache global block parameter data. LibCacheGlobalPrmData Syntax % Arguments buffer Buffer of global data. Description Example See Also This function should be called from inside BlockInstanceSetup to cache global block parameter data. Each call to this function appends your buffer to the existing cache buffer. The global data is placed inside model.prm.
LibCacheInclude Purpose Call this function from inside BlockTypeSetup to cache a #include statement. LibCacheInclude Syntax % Arguments buffer Buffer of #include statements to be cached. Description Example 4-20 This function should be called from inside BlockTypeSetup to cache a #include statement. Each call to this function appends your buffer to the existing cache buffer. The #include statements are placed inside model.h. %openfile buffer #include "mystuff.
LibCacheNonFiniteAssignment Purpose Call this function from inside BlockInstanceSetup to cache assignments that need to be placed in the registration function because of nonfinite initialization. LibCacheNonFiniteAssignment Syntax % Arguments buffer Buffer to be cached for placement inside the model’s registration function.
LibContinuousState Purpose Determines the block continuous state with optional scalar expansion LibContinuousState Syntax % Arguments ucv User control variable string. lcv Loop control variable string. idx Integer offset into block states. Returns The block continuous state with optional scalar expansion. Description LibContinuousState returns the block continuous state with optional scalar expansion. 4-22 X.c.block[ucv] If ucv is specified.
LibControlPortInputSignal Purpose Determines the appropriate control port input signal depending on the source of the input signal LibControlPortInputSignal Syntax % Arguments portNum Integer control port number, starting from 0. sigIdx Integer offset into the signal, i.e., current index of foreach. Returns The appropriate control port input signal depending on the source of the input signal (i.e., Ui, Xi, Bi, or Gi).
LibConvertZCDirection Purpose Converts Real-Time Workshop zero-crossing direction to a SimStruct representation LibConvertZCDirection Syntax % Arguments direction Zero-crossing direction identifier from the block ZCEvent record. Description LibConvertZCDirection converts RTW zero-crossing direction to a SimStruct representation.
LibDataInputPortWidth Purpose Determines the width of an input port LibDataInputPortWidth Syntax % Arguments portNum Integer input port number (starting from 0). Returns The width of an input port. Description LibDataInputPortWidth returns the width of an input port.
LibDataOutputPortWidth Purpose Determines the width of the block’s output port LibDataOutputPortWidth Syntax % Arguments portNum Integer port number (starting from 0). Returns The width of the blocks output port. Description LibDataOutputPortWidth determines the width of the blocks output port.
LibDataStoreMemory Purpose Determines the appropriate data store memory value LibDataStoreMemory Syntax % Arguments ucv User control variable string. lcv Loop control variable string. variableIdx Integer index into the data store memory variable. Returns The appropriate data store memory value. Description LibDataStoreMemory determines the appropriate data store memory value.
LibDeclareRollVariables Purpose Declares the necessary local variables required for loop rolling LibDeclareRollVariables Syntax % Arguments block Reference to the block record. sigOffset Integer signal offset of current roll region. numIterations Integer number of iterations in current roll region. rolledCount Integer number of times the Target Language Compiler has called roller for a given RollRegion.
LibDeclareRollVariables Table 4-1: Valid rollVars (Continued) Declare All Previous zero-crossing PZC Data store memory DSM Declare Individual For example, rollVars = ["U", "/Gain"] declares all nonscalar block inputs and the specific parameter "Gain". See gain.tlc for an example of this function. Description LibDeclareRollVariables declares the necessary local variables required for loop rolling. See Also roller.
LibDefineIWork Purpose Call this function from inside the block’s BlockInstanceSetup function to define the specified iwork in the block. Syntax % Arguments block LibDefineIWork Reference to the block record. name String that you want to call the iwork. width Integer width of the iwork. Description This call should be made from inside the block’s BlockInstanceSetup function, and adds the specified iwork to the block.
LibDefinePWork Purpose Call this function from inside the block’s BlockInstanceSetup function to define the specified pwork in the block. LibDefinePWork Syntax % Arguments block Reference to the block record. name String that you want to call the pwork. width Integer width of the pwork. Description This call should be made from inside the block’s BlockInstanceSetup function, and adds the specified pwork to the block.
LibDefineRWork Purpose Call this function from inside the block’s BlockInstanceSetup function to define the specified rwork definition in the block. Syntax % Arguments block LibDefineRWork Reference to the block record. name String that you want to call the rwork. width Integer width of this rwork. Description This call should be made from inside the block’s BlockInstanceSetup function, and adds the specified rwork definition to the block.
LibDiscreteState Purpose Determines a block’s discrete state with optional scalar expansion LibDiscreteState Syntax % Arguments ucv User control variable string. lcv Loop control variable string. idx Integer offset into block states. Returns Block’s discrete state with optional scalar expansion. Description LibDiscreteState return a block’s discrete state with optional scalar expansion. X.d.block[ucv] If ucv is specified. xd[lcv] If lcv is specified. X.d.
LibExternalResetSignal Purpose Determines the appropriate reset signal into the reset port depending on the source of input signal LibExternalResetSignal Syntax % Arguments portNum Integer reset port number, starting from 0. sigIdx Integer offset into the signal, i.e., current index of foreach. Returns The appropriate reset signal into the reset port depending on the source of input signal.
LibHeaderFileCustomCode Purpose Places code at the top or bottom of the model’s header file LibHeaderFileCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of file). "trailer" (place at bottom of file). Description Use this function to place code at the top or bottom of the model’s header file by specifying "header" or "trailer", respectively.
LibIndexStruct Purpose Returns an optional index for a structure field LibIndexStruct Syntax % Arguments width Integer width of variable. ucv User control variable string. lcv Loop control variable string. idx Integer index. Returns An optional index for a structure field. Description LibIndexStruct returns an optional index for a structure field. An index into to the signal is returned for wide signals.
LibIsDiscrete Purpose Determines if a block is discrete based on its task identifier (TID) LibIsDiscrete Syntax % Arguments tid Task identifier (i.e., integer index into SampleTime). Returns 1 if discrete, otherwise returns 0. Description Determines if a block is discrete based on its TID. Note that TIDs equal to triggered or constant are not discrete.
LibIsEmpty Purpose Determines if input is an empty string, an empty vector, or an empty matrix array LibIsEmpty Syntax % Arguments input Input variable. Returns 1 if input is an empty string: "", an empty vector: [], or an empty matrix array: [[] []]. Description LibIsEmpty returns 1 if input is an empty string: "", or an empty vector: [], or an empty matrix array: [[] []].
LibIsEqual Purpose Determines if expr1 equals expr2 LibIsEqual Syntax % Arguments expr1 First expression. expr2 Second expression. Returns 1 if expr1 equals expr2, otherwise 0 is returned. Description LibIsEqual returns 1 if expr1 equals expr2, otherwise it returns 0. Note that different type expressions always return 0. That is, “0” does not equal 0.
LibIsFinite Purpose Determines if the number is finite LibIsFinite Syntax % Arguments value Any number including rtInf, rtMinusInf, and rtNaN. Returns 1 if the number is finite, otherwise, it returns 0. Description LibIsFinite returns 1 if the number is finite, otherwise, it returns 0.
LibMapSignalSource Purpose Determines the appropriate source signal given the mapping source and mapping index LibMapSignalSource Syntax % Arguments mappingSource String "U", "X", "B", or "G". mappingIndex Integer index into the map for U, X, B, or G. ucv User control variable string. lcv Loop control variable string. Returns The appropriate source signal given the mapping source and mapping index.
LibMaxBlockIOWidth Purpose Determines the maximum width of the input or output ports LibMaxBlockIOWidth Syntax % Arguments none Returns The maximum width of the output or input ports. Description If the block has output ports, LibMaxBlockIOWidth returns the maximum width of the output ports, otherwise, it returns the maximum width of its input ports.
LibMaxDataInputPortWidth Purpose Determines the maximum width of all the input ports LibMaxDataInputPortWidth Syntax % Arguments none Returns The maximum width of all the input ports. Description LibMaxDataInputPortWidth returns the maximum width of all the input ports.
LibMaxDataOutputPortWidth Purpose Determines the maximum width of all the output ports. LibMaxDataOutputPortWidth Syntax % Arguments none Returns The maximum width of all the output ports. Description LibMaxDataOutputPortWidth returns the maximum width of all the output ports.
LibMdlRegCustomCode Purpose Places code at the top or bottom of the model’s registration function LibMdlRegCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of the model’s registration function by specifying "header" or "trailer", respectively.
LibMdlStartCustomCode Purpose Places code at the top or bottom of the MdlStart function LibMdlStartCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description 4-46 Use this function to place code at the top or bottom of the MdlStart function by specifying "header" or "trailer", respectively.
LibMdlTerminateCustomCode Purpose Places code at the top or bottom of the MdlTerminate function LibMdlTerminateCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of the MdlTerminate function by specifying "header" or "trailer", respectively.
LibOptionalMatrixWidth Purpose Determines the optional width of a matrix LibOptionalMatrixWidth Syntax % Arguments nRows Integer number of rows. nCols Integer number of columns. Returns Description 4-48 Returned Value Data Type Nothing Scalars [nRows] or [nCols] Row or column vector [nRows][nCols] Matrices LibOptionalMatrixWidth returns the optional width of a matrix.
LibOptionalVectorWidth Purpose Determines if length is greater than 1 LibOptionalVectorWidth Syntax % Arguments length Integer vector length. Returns [length] if length is greater than 1, otherwise it returns an empty string. Description LibOptionalVectorWidth returns [length] if length is greater than 1, otherwise it returns an empty string.
LibPathName Purpose Determines the full path of a system LibPathName Syntax % Arguments name String name of system (e.g., "/foo_system"). Returns The full path of a system. Description LibPathName returns the full path of a system. This is a recursive function. Note that the expanded name can be used to locate a Simulink block using open_system at the MATLAB prompt with the result of this function.
LibPrevZCState Purpose Determines the appropriate element for previous zero-crossing state based on ucv, lcv, and pzcIdx. LibPrevZCState Syntax % Arguments ucv User control variable string. lcv Loop control variable string. pzcIdx Integer previous zero-crossing index. Returns The appropriate element for the previous zero-crossing state based on ucv, lcv, and pzcIdx.
LibPrmFileCustomCode Purpose Places code at the top or bottom of the model’s parameter file LibPrmFileCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of file). "trailer" (place at bottom of file). Description 4-52 Use this function to place code at the top or bottom of the model’s parameter file by specifying "header" or "trailer", respectively.
LibRegFileCustomCode Purpose Places code at the top or bottom of the model’s registration file LibRegFileCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of file). "trailer" (place at bottom of file). Description Use this function to place code at the top or bottom of the model’s registration file by specifying "header" or "trailer", respectively.
LibRenameParameter Purpose Renames the parameter and creates a new reference to the parameter LibRenameParameter Syntax % Arguments block Reference to the block record. param Reference to the block parameter identifier. newName New string name for the parameter. Description This call should be made from inside the block’s BlockInstanceSetup function. This function • Renames the parameter to the name specified.
LibSourceFileCustomCode Purpose Places code at the top of the model’s source file LibSourceFileCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of file). Description Use this function to place code at the top of the model’s source file by specifying "header". Custom code is not allowed at the bottom of model.c since placing it at the top of model.reg has the same effect (model.c includes model.
LibSystemDerivativeCustomCode Purpose Places code at the top or bottom of a system’s derivative function LibSystemDerivativeCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of a system’s derivative function by specifying "header" or "trailer", respectively.
LibSystemDisableCustomCode Purpose Places code at the top or bottom of a system’s disable function LibSystemDisableCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of a system’s disable function by specifying "header" or "trailer", respectively.
LibSystemEnableCustomCode Purpose Places code at the top or bottom of a system’s enable function LibSystemEnableCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of a system’s enable function by specifying "header" or "trailer", respectively.
LibSystemInitializeCustomCode Purpose Places code at the top or bottom of a system’s initialize function LibSystemInitializeCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of a system’s initialize function by specifying "header" or "trailer", respectively.
LibSystemOutputCustomCode Purpose Places code at the top or bottom of a system’s output function LibSystemOutputCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description 4-60 Use this function to place code at the top or bottom of a system’s output function by specifying "header" or "trailer", respectively.
LibSystemUpdateCustomCode Purpose Places code at the top or bottom of a system’s update function LibSystemUpdateCustomCode Syntax % Arguments buffer Buffer to append to internal cache buffer. location "header" (place at top of function). "trailer" (place at bottom of function). Description Use this function to place code at the top or bottom of a system’s update function by specifying "header" or "trailer", respectively.
LibSystemUpdateCustomCode 4-62
A model.rtw Model.rtw File Model.rtw File Model.rtw File Model.rtw File Contents . . . . . . . . . . . . . . Contents — System Record . . . . . . Contents — Block Specific Records . . . Contents — Linear Block Specific Records . . . . . A-2 . A-11 . A-17 .
A model.rtw Model.rtw File Contents This appendix describes the contents of the model.rtw file, which is created from your block diagram during the Real-Time Workshop build procedure, and is for use with the Target Language Compiler. The contents of the model.rtw file is a “compiled” version of your block diagram. This appendix is provided so that you can modify the existing code generation or even create a new “code generator” to suit your needs. The general format of the model.
model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name Description RelTol Relative tolerance. AbsTol Absolute tolerance. Refine Refine factor. MaxStep Maximum step size. InitialStep Initial step size. MaxOrder Maximum order for ode15s. } DataLoggingOpts { Data logging record describing the settings of Simulink simulation. (Parameters, workspace, I/O settings) LogT Name of Time variable or "" if not selected to be saved.
A model.rtw Table A-1: Model.rtw File Contents (Continued) A-4 Variable/Record Name Description DirectFeedthrough Does model require its inputs in the MdlOutput function (yes/no)? NumContStates Total number of continuous states in the model. Continuous states appear in your model when you use continuous components (i.e., an Integrator block) that have state(s) that must be integrated by a solver such as ode45. NumDiscStates Total number of discrete states in the model.
model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name Description NumIWork Length of the model integer-work vector (iwork). Integer-work elements are used by blocks that need to keep track of “integer” variables between simulation steps. An example of a block that uses integer-work elements is the Discrete Time Integrator block configured with an external initial condition source. The integer-work element is used as a Boolean to determine when to load the initial condition.
A model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name PeriodAndOffset Description Period and offset for this sample time. } RootSignals { Signal and block information in the root “window.” NumSignals Number of block output signals (including virtual) blocks. Signal { One record for each signal. Block [sysIdx, blockIdx] or block name string if a virtual block. SigLabel Signal label if present. OutputPort [outputPortIndex, outputPortWidth].
model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name Description SLName Unmodified Simulink name. This is only written if it is not equal to Name. Virtual Whether or not the subsystem is virtual. NumSignals Number of block output signals (including virtual) blocks. Signal { One record for each signal. Block [sysIdx, blockIdx] or block name string if a virtual block. OutportBlock This is only present if the signal is emanating from a subsystem.
A model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name Description SLName Unmodified Simulink name. This is only written if it is not equal to Name. MemoryName Name of the data store memory region. Identifier Unique identifier across all data stores. Index [dataStoreIndex, dataStoreWidth]. InitValue Initial value for the data store. } } ExternalInputs { External inputs to the block diagram. NumExternalInputs Number of external input records that follow.
model.rtw Table A-1: Model.rtw File Contents (Continued) Variable/Record Name Description Identifier Unique variable name across all block outputs. SigSrc [systemIndex, blockIndex, outputPortIndex]. SigIdx [blockIOVectorIndex, signalWidth]. SigConnected Vector of length signalWith where each element is either a 1 or 0 indicating whether or not the corresponding output signal is connected. SigLabel Signal label entered by user. TestPoint yes/no.
A model.rtw Table A-1: Model.
model.rtw Model.rtw File Contents — System Record In general, a model can consist of multiple systems. There is one system for the root and one for each nonvirtual subsystem. Each descendent system of the root system is written out using Pascal ordering (deepest first) to avoid forward references. Within each system is a sorted list of blocks. Table A-2: Model.rtw File Contents — System Record Variable/Record Name Description System { One for each system in the model.
A model.rtw Table A-2: Model.rtw File Contents — System Record (Continued) Variable/Record Name A-12 Description OutputUpdateFcn Name of output/update function for trigger or enable_with_trigger systems. NumBlocks Number of blocks in the system. Block { One for each block in the system. Type Block type, i.e., Gain. InMask Yes if this block “lives” within a mask. MaskType Only written out if block is masked.
model.rtw Table A-2: Model.rtw File Contents — System Record (Continued) Variable/Record Name Description FundamentalTID Only written for multirate or hybrid enabled subsystems. This gives the sample time as the greatest common divisor of all sample times in the system. SampleTimeIdx Actual sample time of block. Only written for zero order hold and unit delay blocks. IllegalMTaskTrans yes if there is a sample time transition that would cause multitasking problems. no if transition is fine.
A model.rtw Table A-2: Model.rtw File Contents — System Record (Continued) Variable/Record Name Direction Description Direction of zero-crossing: Falling, Any, Rising. } ZCEvents Specified as [N,I], where N is the number of zero-crossing events and I is the index into the zcEvents vector. ZCEvent { One record for each zero-crossing event. Type Type of zero-crossing: DiscontinuityAtZC, ContinuityAtZC, TriggeredDisconAtZC. Direction Direction of zero-crossing: Falling, Any, Rising.
model.rtw Table A-2: Model.rtw File Contents — System Record (Continued) Variable/Record Name ControlPort { Description One record for control input port. Type Type of control port: enable, trigger, or function-call. Width Length of the signal entering this input port. SignalSrc A vector of length Width where each element specifies the source signal.
A model.rtw Table A-2: Model.rtw File Contents — System Record (Continued) Variable/Record Name StringType Description One of: • "Computed" indicating the parameter is computed from values entered in the Simulink dialog box. • "Variable" indicating the parameter is derived from a single MATLAB variable. • "Expression" indicating the parameter is a MATLAB expression. } ParamSettings { blockSpecificName Optional record specific to block. Block specific settings.
model.rtw Model.rtw File Contents — Block Specific Records The following table describes the block specific records written for the Simulink blocks. Table A-3: Model.rtw File Contents — Block Specific Records Block Type: AbsoluteValue No block specific records. Block Type: Backlash (example with a backlash width of 2.08 and an initial output of [1.86, 2.38]) Parameter { Name "BacklashWidth" Value [2.08] String "2.08" StringType "Expression" } ParamSettings { InitialOutput [1.86, 2.
A model.rtw Table A-3: Model.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) } Block Type: DataStoreWrite ParamSettings { DataStore Region index into data stores list. } Block Type: Deadzone (example of a deadzone block with a lower value of –3.3503 and an upper value of 1.4864). Parameter { Name "LowerValue" Value [–3.3503] String "–3.3503" StringType "Expression" } Parameter { Name "UpperValue" Value [1.4864] String "1.4864" StringType "Expression" } Block Type: Demux Virtual.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: Derivative The Derivative block computes its derivative by using the approximation (input–prevInput)/deltaT Two “banks” of history are needed to keep track of the previous input. This is because the input history is updated prior to integrating states. To guarantee correctness when the output of the Derivative block is integrated directly or indirectly, two banks of the previous inputs are needed.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) } Block Type: DigitalClock No block specific records. Block Type: DiscreteFilter See Model.rtw File Contents — Linear Block Specific Records on page A-51. Block Type: DiscreteIntegrator (shown below is a limited integrator configured with an internal initial condition of 0, an upper limit of ".75", and a lower limit of "[–.25 0 –.75]").
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Value [–0.25, 0, –0.75] String "[–.25 0 –.75]" StringType "Expression" } NumRWorkDefines 0, 1, or 2. RworkDefine { Present if NumRWorkDefines is greater than 0. Name PrevT Width 1 } RWorkDefine { Present if NumRWorkDefines is 2. Name PrevU Width Equal to the width of the signal being integrated.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) BlockType: DiscretePulseGenerator (shown below is a discrete pulse generator with an amplitude of 1, a period of 2 samples, a pulse width of 1 sample, and a phase delay of 0 samples).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) NumIWorkDefines 1 (There is one integer work for each output signal.) IWorkDefine { Name "ClockTicksCounter" Width 1 } Block Type: DiscreteStateSpace See Model.rtw File Contents — Linear Block Specific Records on page A-51. Block Type: DiscreteTransferFcn See Model.rtw File Contents — Linear Block Specific Records on page A-51. Block Type: DiscreteZeroPole See Model.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Virtual. Not written to model.rtw file. Block Type: From Virtual. Not written to model.rtw file. Block Type: FromFile ParamSettings { NumPoints Number of data points. TUdata Data from the .mat file. } Block Type: FromWorkspace ParamSettings { NumPoints Number of data points. TUdata Data from the workspace variable(s). } Block Type: Fcn The Fcn block is written out as an abstract syntax tree (AST).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) LHS { Op "SIN" LHS { Op "U" LHS { Op "NUM" Value 1 } } } RHS { Op "NUM" Value 10 } } Block Type: Gain (example of a gain of 1:5).
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: Goto Virtual. Not written to model.rtw file. Block Type: Ground Virtual. Not written to model.rtw file. Block Type: HitCross (example of a hit crossing block with an offset of 0). Parameter { Name "HitCrossingOffset" Value [0] String "0" StringType "Expression" } Block Type: InitialCondition (example of an initial condition block with an initial value of 1:5).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: Inport Virtual. Not written to model.rtw file. Block Type: Integrator (shown below is a limited integrator configured with an internal initial condition of 0, an upper limit of ".75", and a lower limit of "[–.25 0 –.75]"). Parameter { Name "InitialCondition" Value [0] String "0" StringType "Expression" } Parameter { Name "UpperSaturationLimit" Value [0.75] String ".
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) ParamSettings { ExternalReset none, rising, falling, or either InitialConditionSource internal or external LimitOutput on or off ShowSaturationPort on or off ShowStatePort on or off ExternalX0 Only written when initial condition (IC) source is external. This is the initial value of the signal entering the IC port.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Parameter { The output values, y, of the function y = f(x). Name "OutputValues" Value [0, 1, 2, 3, 4, 5] String " [0:5]" StringType "Expression" } Parameter { This is (y(i+1)–y(i))/(x(i+1)–x(i)) Name "Slopes" Value [1, 1, 1, 1, 1, 0] String "" StringType "Computed" } Parameter { This is the output of the block when the input to the block is zero.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Name "RowIndex" Value [1, 2] String "1:2" StringType "Expression" } Parameter { The “column” input values, y, to the function z = f(x,y). Name "ColumnIndex" Value [1, 2, 3] String "1:3" StringType "Expression" } Parameter { The “table” output values, z, to the function z = f(x,y).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) StringType "Computed" } ParamSettings { ColZeroTechnique NormalInterp, AverageValue, or MiddleValue ColZeroIndex 0 } Block Type: Math ParamSettings { Operator exp, log, 10^u, log10, square, sqrt, pow, reciprocal, hypot, rem, or mod } Block Type: MATLABFcn There is no support for the MATLAB Fcn block in RTW. Block Type: Memory (example of a memory block with an initial condition of 0).
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Width 2 } Block Type: MinMax ParamSettings { Function min or max. } Block Type: MultiPortSwitch No block specific records. Block Type: Mux Virtual. Not written to model.rtw file. Block Type: Outport ParamSettings { PortNumber Port number as entered in the dialog box. OutputLocation Specified as Yi if root-level outport; otherwise specified as Bi.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) ProbeSampleTime on or off } Block Type: Product No block specific records. Block Type: Quantizer (example of a quantizer block with a quantization interval of .5). Parameter { Name "QuantizationInterval" Value [.5] String "0.5" } Block Type: RandomNumber (example of a random number block with a mean of 0, a variance of 1, and an initial seed of 0).
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) StringType "Computed" } NumIWorkDefines 1 IWorkDefine { Name "RandSeed" Width 1 } NumRWorkDefines 1 RWorkDefine { Name "NextOutput" Width 1 } Block Type: RateLimiter (example of a rate limiter block with a rising slew limit of 1, and a falling slew limit of –1).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) String "–1" StringType "Expression" } ParamSettings { Signal Limit the rate of change of the output or input signal. } NumRWorkDefines 1 RWorkDefine { Used to keep track of last time, output and input. Name "PrevTYU" Width 2*blockWidth+1 or 2*(2*blockWidth+1) where block width is the width of the input port after scalar expansion. } Block Type: Reference Will never appear in model.rtw.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Value [2.220446049250313e–16] String "eps" StringType "Variable" } Parameter { Name "OffSwitchValue" Value [2.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: ResetIntegrator No support for the obsoleted Reset Integrator block. Block Type: Rounding ParamSettings { Operator floor, ceil, round, or fix. } Block Type: Saturate The following is an example of a saturation block configured with an upper limit of 0.5 and a lower limit of –.5, Parameter { Name "UpperLimit" Value [0.5] String "–0.5" } Parameter { Name "UpperLimit" Value [0.5] String "–0.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) SaveToWorkspace If scope is configured to save its data, then yes, otherwise no. SaveName Name of variable used to save scope data. MaxRows Maximum number of rows to save or 0 for no limit. Decimation Data logging interval. } Block Type: Selector Virtual. Not written to model.rtw file. Block Type: S-Function.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) ParamSettings { FunctionName Name of S-function. FunctionType Type of S-function: "M-File", "C-MEX", or "FORTRAN-MEX". DirectFeedthrough yes or no UsingUPtrs Is the C MEX S-function using ssGetUPtrs(S) or ssGetU(S)? InputContiguous yes or no SampleTimesToSet M-by-2 matrix of sample time indices indicating any sample times specified by the S-function in mdlInitializeSampleTimes, which get updated.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: SignalGenerator (example of a signal generator with an amplitude of 1 and a frequency of 1). Parameter { Name "Amplitude" Value [1] String "1" StringType "Expression" } Parameter { Name "Frequency" Value [1] String "1" StringType "Expression" } ParamSettings { WaveForm sine, square, or sawtooth TwoPi 6.283185307179586 StringType "Expression" } Block Type: Signum No block specific records.
A model.rtw Table A-3: Model.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Value [0.009999833334166664] String "" StringType "Computed" } Parameter { This is a discrete sine coefficient and is only written when the Sine Wave block has a discrete sample time. Name "cos_h" Value [0.9999500004166653] String "" StringType "Computed" } Parameter { This is a discrete sine coefficient and is only written when the Sine Wave block has a discrete sample time. Name "sin_phi" Value [–0.
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) } Block Type: StateSpace See Model.rtw File Contents — Linear Block Specific Records on page A-51. Block Type: Sum ParamSettings { Inputs A vector of the form ["+", "+", "–"] corresponding to the configuration of the block. } Block Type: SubSystem ParamSettings { SystemIdx Index of this system in the model.rtw file. StatesWhenEnabling held or reset. Only written if enable port is present.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) StringType "Expression" } Block Type: ToFile The following is an example of a ToFile block configured with a filename of untitled.mat, and a matrix name of ans. The IWork contains two fields; one is for tracking the number of rows written (Count) and the other is for determining when to log the data at the input (Decimation).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) } Block Type: ToWorkspace ParamSettings { VariableName Name of variable used to save scope data. Buffer Maximum number of rows to save or 0 for no limit. Decimation Data logging interval. InputContiguous yes or no } Block Type: Terminator Virtual. Not written to model.rtw file. Block Type: TransferFcn See Model.rtw File Contents — Linear Block Specific Records on page A-51.
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) InitialInput [0] BufferSize [1024] } NumIWorkDefines 1 IWorkDefine { Name "BufferIndices" Width 4 } NumPWorkDefines 1 PWorkDefine { Name "TUbuffer" Width 2 } Block Type: TriggerPort ParamSettings { TriggerType Only written if the number of output ports is one. This will be one of "rising", "falling", "either", or "function-call".
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Block Type: UniformRandomNumber (example of a uniform random number block with minimum of –1, maximum of 1, initial seed of 0).
model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) } Block Type: UnitDelay (example of a unit delay with an initial condition of 0). Parameter { Name "X0" Value [0] String "0" StringType "Expression" } Block Type: VariableTransportDelay (example of a variable transport delay with a maximum delay of 10, an initial input of 0, and a buffer size of 1024).
A model.rtw Table A-3: Model.rtw File Contents — Block Specific Records (Continued) Name "BufferIndices" Width 4 } NumPWorkDefines 1 PWorkDefine { Name "TUbuffer" Width 2 } Block Type: Width No block specific records. Block Type: ZeroPole See Model.rtw File Contents — Linear Block Specific Records on page A-51. Block Type: ZeroOrderHold No block specific records.
model.rtw Model.rtw File Contents — Linear Block Specific Records The following table describes the block specific records written for the Simulink linear blocks. Table A-4: Model.rtw File Contents — Linear Block Specific Records Parameter { Vector of nonzero terms of the A matrix if realization is sparse, otherwise it is the first row of the A matrix. Name "Amatrix" Value Vector that could be of zero length.
A model.rtw Table A-4: Model.rtw File Contents — Linear Block Specific Records (Continued) Name "Dmatrix" Value Vector that could be of zero length. String "" StringType "Computed" } Parameter { Initial condition vector or []. Name "X0" Value Vector that could be of zero length. String "" StringType "Computed" } ParamSettings { A-52 NumNonZeroAInRow Vector of the number of nonzero elements in each row of the A matrix.
model.rtw Table A-4: Model.rtw File Contents — Linear Block Specific Records (Continued) ColIdxOfNonZeroD Column index of the nonzero elements in the D matrix.
A model.
B Target Language Compiler Error Messages
B Target Language Compiler Error Messages This appendix lists and describes error messages generated by the Target Language Compiler. Use this reference to: • Confirm that an error has been reported. • Determine possible causes for an error. • Determine possible ways to correct an error.
%closefile or %selectfile argument must be a valid open file When using %closefile or %selectfile, the argument must be a valid file variable opened with %openfile. %error directive: text Code containing the %error directive generates this message. It normally indicates some condition that the code was unable to handle and displays the text following the %error directive. %exit directive: text Code containing the %exit directive causes this message.
B Target Language Compiler Error Messages A language choice must be made using the %language directive prior to using GENERATE or GENERATE_TYPE To use the GENERATE or GENERATE_TYPE built-in functions, the Target Language Compiler requires that you first specify the language being generated. It does this to ensure that the block-level target file implements the same language and type as specified in the %language directive.
Argument to identifier must be a string The following built-in functions expect a string and report this error if the argument passed is not a string: CAST GENERATE_FILENAME EXISTS GENERATE_FUNCTION_EXISTS FILE_EXISTS GENERATE_TYPE FORMAT IDNUM GENERATE SYSNAME Arguments to TLC from the MATLAB command line must be strings An attempt was made to invoke the Target Language Compiler from MATLAB and some of the arguments that were passed were not strings.
B Target Language Compiler Error Messages Bad cast - unable to cast this expression to "type " The Target Language Compiler does not know how to cast this expression from its current type to the specified type. For example, the Target Language Compiler is not able to cast a string to a number as in: %assign x = "1234" %assign y = CAST("Number", x ); Cannot convert string string to a number Cannot convert the string to a number.
is illegal, whereas: % is correct.
B Target Language Compiler Error Messages Function reached the end and did not return a value Functions that are not declared as void or Output must return a value. If a return value is not desired, declare the function as void, otherwise ensure that it always returns a value. Identifier identifier used on a %foreach statement was already in scope (Warning) The argument to a %foreach statement cannot be defined prior to entering the %foreach.
It is illegal to return functions or macros from a function A function or macro value cannot be returned from a function call. Named value identifier already exists within this scope-identifier ; use %assign to change the value You cannot use the block addition operator + to add a value that is already a member of the indicated block. Use %assign to change the value of an existing value.
B Target Language Compiler Error Messages Output file identifier opened with %openfile was not closed Output files opened with %openfile must be closed with %closefile. identifier is the name of the variable specified in the %openfile directive. Syntax error The indicated line contains a syntax error, See Chapter 2, “Working with the Target Language,” for information on the syntax.
The %continue directive can only appear within a %foreach, %for, or %roll statement The %continue directive can only be used in a %foreach, %for, or %roll statement. The %foreach statement expects a constant numeric argument The argument of a %foreach must be a numeric type. For example: %foreach Index = [1 2 3 4] … %endforeach %foreach cannot accept a vector as input. The %if statement expects a constant numeric argument The argument of a %if must be a numeric type.
B Target Language Compiler Error Messages The %implements language does not match the language currently being generated (language ) The language or languages specified in the %implements directive must exactly match the %language directive. The %return statement can only appear within the body of a function A %return statement can only be in the body of a function.
identifier. When using array indexing on a scalar, the constant is automatically scalar expanded and the value of the scalar is returned. For example: %openfile x %assign y = x[0] This example would cause this error because x is a file and is not valid for indexing. The argument to %include must be a valid string The argument to the input file control directive must be a valid string. The begin directive must be in the same file as the corresponding end directive.
B Target Language Compiler Error Messages The error is reported on the line that opens the scope and has no matching end scope. Note: Nested scopes must be closed before their parent scopes. Failure to include an end for a nested scope often causes this error, as in: %if Block.Name == "Sin 3" %foreach idx = Block.
The final argument to %roll must be a valid block scope When using %roll, the final argument (prior to extra user-specified arguments) must be a valid block scope. See Chapter 2 for a complete discussion of the %roll construct. The first argument of a ? : operator must be a Boolean expression The ? : operator must have a Boolean expression as its first operand.
B Target Language Compiler Error Messages The language being implemented has changed from old-language to new-language (Warning) The language being implemented should not be changed in midstream because GENERATE function calls that appear prior to the %language directive may cause generate functions to load for the prior language. Only one language directive should appear in a given file. The left-hand side of a . operator must be a valid scope identifier When using the .
The number of rows specified (specified-rows ) did not match the actual number of rows seen in the matrix (actual-rows ) When specifying a Target Language Compiler matrix, the number of rows specified did not match the actual number of rows in the matrix. For example: %assign mat = Matrix(1,2) [ [1 2] [2 3] ] In this case, the number of rows in the declaration of the matrix (i.e., 1) did not match the number of rows seen in the matrix (i.e., 2).
B Target Language Compiler Error Messages The specified index ( index) was out of the range 0 to number-of-elements – 1 This error occurs when indexing into any nonscalar beyond the end of the variable. For example: %assign x = [1 2 3] %assign y = x[3] This example would cause this error. Remember, in the Target Language Compiler, array indices start at 0 and go to the number of elements minus 1.
There was no type associated with the given block for GENERATE The scope specified to GENERATE must include a Type parameter that indicates which template file should be used to generate code for the specified scope. For example: %assign scope = block { Name "foo" } % This example produces the error message because the scope does not include the parameter Type. See page 2-25 for more information and examples on using the GENERATE built-in function.
B Target Language Compiler Error Messages Unable to open output file filename Unable to open the specified output file; either an invalid filename was specified or the file was read only. Undefined identifier identifier The identifier specified in this expression was undefined. Unknown type "type " in CAST expression When calling the CAST built-in function, the type must be one of the valid Target Language Compiler types found in the Target Language Values table on pages 2-10 through 2-13.
Table B-1: Valid Directives (Continued) %endif %switch %endroll %trace %endswitch %undef %endwith %warning %error %with %exit Unrecognized type "output-type" for function The function type modifier was not Output or void. For functions that do not produce output, the default without a type modifier indicates that the function should produce no output. Unterminated string A string must be closed prior to the end of an expansion directive or the end of a line.
B Target Language Compiler Error Messages Usage: tlc [options] file Message Description –r Specify the Real-Time Workshop file to read. –v[N] Specify the verbose level to be N (1 by default). –I Specify a search path to look for %include and %generate files. –m[N|a] Specify the maximum number of errors (a is all) default is 5. –O Specify the path used to create output files. –d[g|n|o] Specify debug mode (generate, normal, or off).
When appending to a buffer stream, the variable must be a string You can specify the append option for a buffer stream only if the variable currently exists as a string. Do not use the append option if the variable does not exist or is not a string.
B Target Language Compiler Error Messages B-24
C Target Language Compiler Library Error Messages blkiolib.tlc Error Messages . . . . . . . . . . . . . C-3 blocklib.tlc Error Messages . . . . . . . . . . . . . C-4 hookslib.tlc Error Messages . . . . . . . . . . . . . C-5 paramlib.tlc Error Messages . . . . . . . . . . . . . C-7 rolllib.tlc Error Messages . . . . . . . . . . . . . . C-8 utillib.tlc Error Messages . . . . . . . . . . . . . .
C Target Language Compiler Library Error Messages This appendix lists and describes error messages that may be generated when working with the Target Language Compiler libraries. In this appendix, the error messages are grouped by the libraries because they are reported by library. For example, this error message is generated by the rolllib.tlc library. rolllib.
blkiolib.tlc Error Messages blkiolib.tlc Error Messages Invalid map source (mappingSource ) specified for Type block: Name (LibMapSignalSource) Real-Time Workshop does not generate a mapping matrix for the specified source. Valid map sources are: Map Source Description U External inputs map X States map B Block I/O map G Ground Invalid port number ( portNum) specified for Type block: Name (LibDataOutputPortWidth, LibDataInputPortWidth) The specified output port does not exist for this block.
C Target Language Compiler Library Error Messages blocklib.tlc Error Messages Don't know how to roll IWork for Type block: Name (LibBlockIWork) In order to roll a block’s IWork it must first be defined with LibDefineIWork. Don't know how to roll PWork for Type block: Name (LibBlockPWork) In order to roll a block’s PWork it must first be defined with LibDefinePWork.
hookslib.tlc Error Messages hookslib.tlc Error Messages Add root initialization code with LibMdlStartCustomCode (LibSystemInitializeCustomCode) The root system initialization function is MdlStart. Therefore, use LibMdlStartCustomCode for placement of root system initialization code.
C Target Language Compiler Library Error Messages System system.Name does not have Disable function (LibSystemDisableCustomCode) The subsystems types that have a disable function are: Purely enable subsystems Enable with trigger subsystems The system types that do not have a disable function are: Function-call Trigger Root System system.
paramlib.tlc Error Messages paramlib.tlc Error Messages Loop rolling not supported for param.Name in Type block Name (LibBlockMatrixParamter, LibBlockMatrixParameterAddr) Loop rolling of matrix parameters is not supported. The arguments are passed into this routine as protection for future support of this feature. Parameter param.Name must be of type Matrix (LibBlockMatrixParamter, LibBlockMatrixParameterAddr) This routine only works for matrix parameters.
C Target Language Compiler Library Error Messages rolllib.tlc Error Messages 1-- The inputs for Type block Name are not rollable, or do not exist (LibDeclareRollVariables) The variable rollVars contains U (declare all inputs), but the block does not have any inputs to declare. 2-- uuIdx for Type block Name is not rollable, or does not exist (LibDeclareRollVariables) The variable rollVars contains ui (declare input i), but input i does not exist.
rolllib.tlc Error Messages 8-- Unable to declare roll variable p_name for Type block Name (LibDeclareRollVariables) The variable rollVars contains /p (declare parameter p), but p is not a valid block parameter. 9-- Unable to roll RWork for Type block Name . RWork must be defined (LibDeclareRollVariables) The variable rollVars contains RWork (declare all real-work), but the block does not have any real-work to declare.
C Target Language Compiler Library Error Messages 16-- There are no previous zero-crossings to roll in Type block: Name (LibDeclareRollVariables) The variable rollVars contains PZC (declare block previous zero-crossing vector), but the block does not have a zero-crossing vector to declare.
utillib.tlc Error Messages utillib.tlc Error Messages Invalid matrix size (nRows x nCols ) for Type block: Name (LibOptionalMatrixWidth) Either nRows or nCols is less than 1. Invalid vector length ( length ) specified for Type block: Name (LibOptionalVectorWidth) The value of length is less than 1. Invalid zc direction ( direction) specified for Type block: Name (LibConvertZCDirection) RTW zero-crossings are either Rising, Falling, or Any. An unrecognized zero-crossing was specified.
C Target Language Compiler Library Error Messages C-12
Index Symbols ! 2-14 % 2-6, 2-13 ... character 2-9 .c file 1-3 .h file 1-3 .log 2-51 .prm file 1-3 .reg file 1-3 .rtw file 1-3, 2-29 structure 2-3 block-scoped variable 2-41 BlockTypeSetup 3-16 %body 2-20 Boolean 2-10 %break 2-19, 2-20 %continue 2-19 buffer close 2-27 writing 2-27 built-in functions 2-29 .
Index customizing code generation 1-10 Simulink block 2-24 expressions 2-13 operators in 2-13 precedence 2-13 D F debug message 2-29 mode 2-51 %default 2-19 %define 2-37 Derivatives 3-19 directive 1-10, 2-6 object-oriented 2-24 splitting 2-9 Disable 3-17 dynamic scoping 2-42 FEVAL 2-30 E %else 2-18 %elseif 2-18 Enable 3-17 %endbody 2-20 %endfor 2-20 %endforeach 2-19 %endfunction 2-44 %endif 2-18 %endswitch 2-19 %endwith 2-41 %error 2-29 error message 2-29 library C-2 Target Language Compiler B-2 EXI
Index formatting 2-17 Function 2-10 %function 2-44 function built-in TLC 3-30 C MEX S-function 1-3 call 2-14 GENERATE 2-25 GENERATE_TYPE 2-25 global 1-11 library 3-9, 3-13 local 1-11 output 2-45, 3-17 scope 2-44 target language 2-44 Target Language Compiler 2-29–2-35 function library reference 4-1–4-61 inclusion conditional 2-18 multiple 2-19 index 2-14 Initialize 3-18 InitializeConditions 3-18 InlineParameters 3-40 inlining S-function 3-31 input file control 2-28 Inputs 3-48 integer constant 2-13 interme
Index LibConvertZCDirection 4-24 LibSystemOutputCustomCode 4-60 LibDataInputPortWidth 3-22, 4-25 LibSystemUpdateCustomCode 4-61 LibDataOutputPortWidth 3-22, 4-26 local function 1-11 loop rolling 3-44 threshold 3-40 LibDataStoreMemory 3-26, 4-27 LibDeclareRollVariables 4-28 LibDefineIWork 3-21, 4-30 LibDefinePWork 3-21, 4-31 LibDefineRWork 3-21, 4-32 M LibDiscreteState 3-25, 4-33 LibOptionalVectorWidth 4-49 Macro 2-10 macro defining 2-37 expansion 2-14 makefile template 1-2 MatFileLogging 3-40 mat
Index MdlStart InitializeConditions 3-18 Start 3-18 MdlTerminate Terminate 3-19 mdlTerminate (S-function) 3-31 MdlUpdate Update 3-19 mdlUpdate (S-function) 3-31 mdlwide.tlc 1-11, 3-6, 3-10 variables 3-10 Mode 3-48 model description file. See model.rtw model.c 3-40 model.
Index OUTPUT_LINES 2-32 rt 3-10 Outputs 3-18, 3-48 rt_ 3-10 P RTW identifier 3-8 RWork 3-48 parameter defining 1-10 inlining 3-40 value pair 2-3 Parameters 3-48 path specifying absolute 2-28 specifying relative 2-28 port index input 3-22 output 3-22 precedence expressions 2-13 operations 2-14 Previous Zero-Crossing 3-48 program 1-10 PWork 3-48 R Range 2-11 Real 2-11 %realformat 2-17 Real-Time Workshop 1-2 generate code 3-6 record 2-3 resolving variables 2-42 %return 2-44, 2-49 %roll 2-22, 3-40, 3-4
Index Simulink and Real-Time Workshop 1-2 block parameters 3-41 generating code 1-3 SIZE 2-33, 3-30 Special 2-11 STAND_ALONE 2-33 Start 3-18 STDOUT 2-33 STRING 2-33 String 2-12 string constant 2-13 STRINGOF 2-34, 3-30 substitution textual 2-13 Subsystem 2-12 %switch 2-19 syntax 2-6 SYS_NAME 2-34 system target file 1-10, 1-11, 3-6 T target file 1-2, 1-10 and customizing code 1-10 block 1-11, 3-7 naming 2-51 necessary block functions 3-20 system 1-10, 1-11, 3-6 target language comment 2-8 directive 1-10, 2-
Index V values 2-10 variables block-scoped 2-41 global 3-9 local 3-9 RTW 3-40 Vector 2-12 void modifier 2-45 W %warning 2-29 warning message 2-29 WHITE_SPACE 2-35 WILL_ROLL 2-35 %with 2-41 Z zero-crossing reset code 3-18 I-8