Target Language Compiler | ![]() ![]() |
Target Language Compiler Functions
This section lists the Target Language Compiler functions grouped by category, and provides a description of each function. To view the source code for a function, click on its name.
Common Function Arguments
Several functions take similar or identical arguments. To simplify the reference pages, some of these arguments are documented in detail here instead of in the reference pages.
Argument |
Description |
|
Refers to an input or output port index, starting at zero, for example the first input port of an S-function is 0. |
|
User control variable. This is an advanced feature that overrides the lcv and sigIdx parameters. When used within an inlined S-function, it should generally be specified as "" . |
|
Loop control variable. This is generally generated by the %roll directive via the second %roll argument (e.g., lcv=RollThreshold ) and should be passed directly to the library function. It will contain either "" , indicating that the current pass through the %roll is being inlined, otherwise it will be the name of a loop control variable such as "i" indicating that the current pass through the %roll is being placed in a loop. Outside of the %roll directive, this is usually specified as "" . |
or idx |
Signal index. Sometimes referred to as the signal element index. When accessing specific elements of an input or output signal directly, the call to the various library routines should have ucv="" , lcv="" , and sigIdx equal to the desired integer signal index starting at 0. Note, for complex signals, sigIdx can be an overloaded integer index specifying both wether the real or imaginary part is being accessed and which element. When accessing these items inside of a %roll , the sigIdx generated by the %roll directive should be used.
Most functions that accept a sigIdx argument, accept it in an overloaded form where sigIdx can be:
idx name is used when referring to a state or work vector.Functions that accept the three arguments ucv , lcv , sigIdx (or idx ) are called differently depending upon whether or not they are used with in a %roll directive. If they are used within a %roll directive, ucv is generally specified as "" , lcv and sigIdx are the same as those specified in the %roll directive. If they are not used with in a %roll directive, ucv and lcv are generally specified as "" and sigIdx specifies which index to access. |
paramIdx |
Parameter index. Sometimes referred to as the parameter element index. The handling of this parameter is very similar to sigIdx (i.e., it can be # , re# , or im# ). |
stateIdx |
State index. Sometimes referred to as the state vector element index (it must evaluate to an integer where the first element starts at 0 ). |
Overloading sigIdx
The signal index (sigIdx
some times written as idx
) can be overloaded when passed to most library functions. Suppose we interested in element 3 of a signal, ucv=""
, lcv=""
. The following table shows:
sigIdx
sigIdx
returnsNote that "container" in the following table refers to the object that encapsulates both the real and imaginary parts of the number, e.g., creal_T
defined in matlabroot
/extern/include/tmwtypes.h
.
The following table shows values of idx
, whether the signal is complex, and what the function that uses idx
returns.
Notes
ucv
is not an empty string (" "), then the ucv
is used instead of sigIdx
in the above examples and both lcv
and sigIdx
are ignored.ucv
is empty but lcv
is not empty, then this function returns "&y%<portIdx>[%<lcv>]"
and sigIdx
is ignored."rollVars"
as the argument to the %roll
directive.LibBlockInputSignal(portIdx, ucv, lcv, sigIdx)
Based on the input port number (portIdx
), the user control variable (ucv
), the loop control variable (lcv
), the signal index (sigIdx
), and where this input signal is coming from, LibBlockInputSignal
returns the appropriate reference to a block input signal.
The returned string value is a valid rvalue
(right value) for an expression. The block input signal may be coming from another block, a state vector, an external input, or it can be a literal constant (e.g, 5.0).
Since the returned value can be a literal constant, you should not use this function to access the address of an input signal. To access the address of an input signal, use LibBlockInputSignalAddr
. Accessing the address of the signal via LibBlockInputSignal
may result in a reference to a literal constant (e.g., 5.0).
For example, the following would not work.
%assign u = LibBlockInputSignal(0, "", lcv, sigIdx) x = &%<u>;
If %<u>
refers to a invariant signal with a value of 4.95
, the statement (after being processed by the pre-processor) would be generated as
x = &4.95;
or, if the input signal sources to ground, the statement could come out as
x = &0.0;
neither of these would compile.
Avoid any such situations by using LibBlockInputSignalAddr
.
%assign uAddr = LibBlockInputSignalAddr(0, "", lcv, sigIdx) x = %<uAddr>;
Real-Time Workshop tracks signals and parameters accessed by their address and declares them in addressable memory.
Input Arguments (ucv, lcv, and sigIdx) Handling
The value returned depends on what the input signal is connected to in the block diagram and how the function is being invoked (e.g., in a %roll
or directly). In the above example, case 1 occurs when an explicit call is made with the ucv
set to "i"
. Cases 2 and 3 receive the same arguments, lcv
and sigIdx
, however they produce different return values. Case 2 occurs when LibBlockInputSignal
is called within a %roll
directive and the current roll region is being rolled. Case 3 occurs when LibBlockInputSignal
is called within a %roll
directive and the current roll region is not being rolled.
When called within a %roll
directive, this function looks at ucv
, lcv
, and sigIdx
, the current roll region, and the current roll threshold 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 (thus, when called in a %roll
directive it is usually ""
). If ucv
is not specified and lcv
and sigIdx
are specified, the returned value depends on whether or not the current roll region is being placed in a for
loop or being expanded. If the roll region is being placed in a loop, then lcv
is used, otherwise, sigIdx
is used.
A direct call to this function (inside or outside of a %roll
directive) will use sigIdx
when ucv
and lcv
are specified as ""
.
For an example of this function, see matlabroot
/toolbox/simulink/blocks/tlc_c/sfun_multiport.tlc
.
Example 1
To assign the outputs of a block to be the square of the inputs, you could use
%assign rollVars = ["U", "Y"] %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) %assign y = LibBlockOutputSignal(0, "", lcv, sigIdx) %<y> = %<u> * %<u>; %endroll
This would be appropriate for a block with a single input port and a single output port.
Example 2
Suppose we have a block with multiple input ports where each port has width greater than or equal to 1 and at least one port has width 1. Setting the output signal to the sum of the squares of all the input signals gives
%assign y = LibBlockOutputSignal(0, "", "", 0) y = 0; %assign rollVars = ["U"] %foreach port = block.NumDataInputPorts - 1 %roll sigIdx=RollRegions, lcv = RollThreshold, block, "Roller", rollVars %assign u = LibBlockInputSignal(port, "", lcv, sigIdx) y += %<u> * %<u>; %endroll %endforeach
Since the first parameter of LibBlockInputSignal
is 0-indexed, you must index the foreach
loop to start from 0
and end at NumDataInputPorts-1
.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalAddr(portIdx, ucv, lcv, sigIdx)
Returns the appropriate string that provides the memory address of the specified block input port signal.
When you need an input signal address, you must use this function instead of appending an "&
" to the string returned by LibBlockInputSignal
. For example, LibBlockInputSignal
can return a literal constant, such as 5
(i.e., an invariant input signal). Real-Time Workshop tracks when LibBlockInputSignalAddr
is called on an invariant signal and declares the signal as "const" data (which is addressable), instead of being placed as a literal constant in the generated code (which is not addressable).
Note, unlike LibBlockInputSignal()
the last input argument, sigIdx
, is not overloaded. Hence, if the input signal is complex, the address of the complex container is returned.
In Ada, this function returns the identifier and the caller must append the 'Address
attribute.
Example
To get the address of a wide input signal and pass it to a user-function for processing, you could use
%assign uAddr = LibBlockInputSignalAddr(0, "", "", 0)
%assign y = LibBlockOutputSignal(0, "", "", 0)
y = myfcn
(%<uAddr>);
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalDataTypeId(portIdx)
Returns the numeric identifier (id
) corresponding to the data type of the specified block input port.
If the input port signal is complex, this function returns the data type of the real part (or the imaginary part) of the signal.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalDataTypeName(portIdx, reim)
Returns the name of the data type (e.g., int_T
, ... creal_T
) corresponding to the specified block input port.
Specify the reim
argument as ""
if you want the complete signal type name. For example, if reim==""
and the first output port is real and complex, the data type name placed in dtname
will be creal_T
.
%assign dtname = LibBlockInputSignalDataTypeName(0,"")
Specify the reim
argument as tRealPart
if you want the raw element type name. For example, if reim==tRealPart
and the first output port is real and complex, the data type name returned will be real_T
.
%assign dtname = LibBlockInputSignalDataTypeName(0,tRealPart)
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalDimensions(portIdx)
Returns the dimensions vector of specified block input port, e.g., [2,3]
.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalIsComplex(portIdx)
Returns 1 if the specified block input port is complex, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalIsFrameData(portIdx)
Returns 1 if the specified block input port is frame based, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalNumDimensions(portIdx)
Returns the number of dimensions of the specified block input port.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalWidth(portIdx)
Returns the width of the specified block input port index.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignal(portIdx, ucv, lcv, sigIdx)
Based on the output port number (portIdx
), the user control variable (ucv
), the loop control variable (lcv
), the signal index (sigIdx
), and where the output signal destination, LibBlockOutputSignal
returns the appropriate reference to a block output signal.
The returned value is a valid lvalue
(left value) for an expression. The block output destination can be a location in the block I/O vector (another block's input), the state vector, or an external output.
The Real-Time Workshop tracks when a variable (e.g., signals and parameters) is accessed by its address. To access the address of an output signal, use LibBlockOutputSignalAddr
as in the following example.
%assign yAddr = LibBlockOutputSignalAddr(0, "", lcv, sigIdx) x = %<yAddr>;
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalAddr(portIdx, ucv, lcv, sigIdx)
Returns the appropriate string that provides the memory address of the specified block output port signal.
When an output signal address is needed, you must use this function instead of taking the address that is returned by LibBlockOutputSignal
. For example, LibBlockOutputSignal
can return a literal constant, such as 5 (i.e., an invariant output signal). When LibBlockOutputSignalAddr
is called on an invariant signal, the signal is declared as a "const" instead of being placed as a literal constant in the generated code.
Note, unlike LibBlockOutputSignal()
, the last argument, sigIdx
, is not overloaded. Hence, if the output signal is complex, the address of the complex container is returned.
In Ada, this function returns the identifier and the caller must append the 'Address
attribute.
Example
To get the address of a wide output signal and pass it to a user-function for processing, you could use
%assign u = LibBlockOutputSignalAddr(0, "", "", 0)
%assign y = LibBlockOutputSignal(0, "", "", 0)
y = myfcn
(%<u>);
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalDataTypeId(portIdx)
Returns the numeric ID corresponding to the data type of the specified block output port.
If the output port signal is complex, this function returns the data type of the real (or the imaginary) part of the signal.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalDataTypeName(portIdx, reim)
Returns the type name string (e.g., int_T
, ... creal_T
) of the data type corresponding to the specified block output port.
Specify the reim
argument as ""
if you want the complete signal type name. For example, if reim==""
and the first output port is real and complex, the data type name placed in dtname
will be creal_T
.
%assign dtname = LibBlockOutputSignalDataTypeName(0x,"")
Specify the reim
argument as tRealPart
if you want the raw element type name. For example, if reim==tRealPart
and the first output port is real and complex, the data type name returned will be real_T
.
%assign dtname = LibBlockOutputSignalDataTypeName(0,tRealPart)
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalDimensions(portIdx)
Returns the dimensions of specified block output port.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalIsComplex(portIdx)
Returns 1 if the specified block output port is complex, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalIsFrameData(portIdx)
Returns 1 if the specified block output port is frame based, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalNumDimensions(portIdx)
Returns the number of dimensions of the specified block output port.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalWidth(portIdx)
Returns the width of specified block output port.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockMatrixParameter(param,rucv,rlcv,ridx,cucv,clcv,cidx)
Returns the appropriate matrix parameter for a block given the row and column user control variables (rucv
, cucv
), loop control variables (rlcv
, clcv
), and indices (ridx
, cidx
). Generally, blocks should use LibBlockParameter
. If you have a matrix parameter, you should write it as a column major vector and access it via LibBlockParameter
.
Note
Loop rolling is currently not supported, and will generate an error if requested (i.e., if either rlcv or clcv is not equal to "" ).
|
The row and column index arguments are similar to the arguments for LibBlockParameter
. The column index (cidx
) is overloaded to handle complex numbers.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockMatrixParameterAddr(param,rucv,rlcv,ridx,cucv,clcv,cidx)
Returns the address of a matrix parameter.
Note
LibBlockMatrixParameterAddr returns the address of a matrix parameter. Loop rolling is not supported (i.e., rlcv and clcv should both be the empty string).
|
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameter(param, ucv, lcv, sigIdx)
Based on the parameter reference (param
), the user control variable (ucv
), the loop control variable (lcv
), the signal index (sigIdx
), and the state of parameter inlining, this function returns the appropriate reference to a block parameter.
The returned value is always a valid rvalue
(right-hand side expression value). For example,
To illustrate the basic workings of this function, assume a noncomplex vector signal where Gain[0]=4.55
.
LibBlockParameter(Gain, "", "i", 0)
Note case 4. Even though inline parameter is true, the parameter must be placed in memory (RAM) since it's accessed inside a for
-loop.
Note This function also supports expressions when used with inlined parameters and parameter tuning. |
For example, if the parameter field had the M expression '2*a'
, this function will return the C expression '(2 * a)'
. The list of functions supported by this function is determined by the functions FcnConvertNodeToExpr
and FcnConvertIdToFcn
. To enhance functionality, augment/update either of these functions.
Note that certain types of expressions are not supported such as x * y
where both x
and y
are nonscalars.
See the Real-Time Workshop documentation about tunable parameters for more details on the exact functions and syntax that is supported.
Warning
Do not use this function to access the address of a parameter, or you may end up referencing a number (i.e., &4.55
) when the parameter is inlined. You can avoid this situation entirely by using LibBlockParameterAddr()
.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameterAddr(param, ucv, lcv, idx)
Returns the address of a block parameter.
Using LibBlockParameterAddr
to access a parameter when the global InlineParameters
variable is equal to 1 will cause the variable to be declared "const" in RAM instead of being inlined.
Also, trying to access the address of an expression when inline parameters is on and the expression has multiple tunable/rolled variables in it, will result in an error.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameterDataTypeId(param)
Returns the numeric ID corresponding to the data type of the specified block parameter.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameterDataTypeName(param, reim)
Returns the name of the data type corresponding to the specified block parameter.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameterIsComplex(param)
Returns 1 if the specified block parameter is complex, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
LibBlockParameterSize(param)
Returns a vector of size 2 in the format [nRows, nCols]
where nRows
is the number of rows and nCols
is the number of columns.
See function in matlabroot
/rtw/c/tlc/paramlib.tlc
or matlabroot
/rtw/ada/tlc/paramlib.tlc
.
Block State and Work Vector Functions
LibBlockContinuousState(ucv, lcv, idx)
Returns a string corresponding to the specified block discrete state (CSTATE
) element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWork(dwork, ucv, lcv, sigIdx)
Returns a string corresponding to the specified block DWORK
element.
Note, the last input argument is overloaded to handle complex DWorks
.
sigIdx = "re3"
=> returns the real part of element 3 if the dwork
is complex, otherwise returns element 3.
sigIdx = "im3"
=> returns the imaginary part of element 3 if the dwork
is complex, otherwise returns ""
.
sigIdx = "3"
=> returns the complex container of element 3, if the dwork
is complex, otherwise returns element 3.
If either ucv
or lcv
is specified (i.e., it is not equal to ""
) then the index part of the last input argument (sigIdx
) is ignored.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkAddr(dwork, ucv, lcv, idx)
Returns a string corresponding to the address of the specified block DWORK
element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkDataTypeId(dwork)
Returns the data type ID of specified block DWORK
.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkDataTypeName(dwork, reim)
Returns the data type name of specified block DWORK
.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkIsComplex(dwork)
Returns 1 if the specified block DWORK is complex
, returns 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkName(dwork)
Returns the name of the specified block DWORK
.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkUsedAsDiscreteState(dwork)
Returns 1 if the specifed block DWORK
is used as a discrete state, returns 0 otherwise.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDWorkWidth(dwork)
Returns the width of the specified block DWORK
.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockDiscreteState(ucv, lcv, idx)
Returns a string corresponding to the specified block discrete state (DSTATE
) element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockIWork(iwork, ucv, lcv, idx)
Returns a string corresponding to the specified block IWORK
element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockMode(ucv, lcv, idx)
Returns a string corresponding to the specified block MODE
element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockPWork(pwork, ucv, lcv, idx)
Returns a string corresponding to the specified block PWORK
element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
LibBlockRWork(rwork, ucv, lcv, idx)
Returns a string corresponding to the specified block RWORK
element.
See function in matlabroot
/rtw/c/tlc/blocklib.tlc
or matlabroot
/rtw/ada/tlc/blocklib.tlc
.
Block Path and Error Reporting Functions
LibBlockReportError(block,errorstring)
This should be used when reporting errors for a block. This function is designed to be used from block target files (e.g., the TLC file for an inlined S-function).
This function can be called with or without the block record scoped. To call this function without a block record scoped, pass the block record. To call this function when the block is scoped, pass block = []
. Specifically
LibBlockReportError([],"error string")--If block is scoped LibBlockReportError(blockrecord,"error string")--If block record is available
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibBlockReportFatalError(block,errorstring)
This should be used when reporting fatal (assert) errors for a block. Use this function for defensive programming. Refer to Appendix B, TLC Error Handling.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibBlockReportWarning(block,warnstring)
This should be used when reporting warnings for a block. This function is designed to be used from block target files (e.g., the TLC file for an inlined S-function).
This function can be called with or without the block record scoped. To call this function without a block record scoped, pass the block record. To call this function when the block is scoped, pass block = []
.
LibBlockReportWarning([],"warn string")--If block is scoped LibBlockReportWarning(blockrecord,"warn string")--If block record is available
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibGetBlockPath(block)
LibGetBlockPath
returns the full block path name string for a block record including carriage returns and other special characters that may be present in the name. Currently, the only other special string sequences defined are '/*'
and '*/'
.
The full block path name string is useful when accessing blocks from MATLAB. For example, you can use the full block name with hilite_system()
via FEVAL
to match the Simulink path name exactly.
Use LibGetFormattedBlockPath
to get a block path suitable for placing in a comment or error message.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibGetFormattedBlockPath(block)
LibGetFormattedBlockPath
returns the full path name string of a block without any special characters. The string returned from this function is suitable for placing the block name, in comments or generated code, on a single line.
Currently, the special characters are carriage returns, '/*'
, and '*/'
. A carriage return is converted to a space, '/*'
is converted to '/+'
, and '*/'
is converted to '+/'
. Note that a '/'
in the name is automatically converted to a '//'
to distinguish it from a path separator.
Use LibGetBlockPath
to get the block path needed by MATLAB functions used in reference blocks in your model.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibAddToModelSources(newFile)
For blocks, this function is generally called from BlockTypeSetup
. This function adds a filename to the list of sources needed to build this model. This function returns 1 if the filename passed in was a duplicate (i.e., it was already in the sources list) and 0 if it was not a duplicate.
See function in matlabroot
/rtw/c/tlc/commonhdrlib.tlc
or matlabroot
/rtw/ada/tlc/commonhdrlib.tlc
.
LibCacheDefine(buffer)
Each call to this function appends your buffer to the existing cache buffer. For blocks, this function is generally called from BlockTypeSetup
.
C
This function caches #define
statements for inclusion in model
.h
.
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
.
%openfile buffer #define INTERP(x,x1,x2,y1,y2) ( y1+((y2-y1)/(x2-x1))*(x-x1) ) #define this that %closefile buffer %<LibCacheDefine(buffer)>
Ada
This function caches definitions for inclusion in model
.adb
The Ada utility functions and procedures are placed in the generated model
.adb
package body immediately preceding Mdl_Start
.
See function in matlabroot
/rtw/c/tlc/cachelib.tlc
or matlabroot
/rtw/ada/tlc/cachelib.tlc
.
LibCacheExtern(buffer)
LibCacheExtern
should be called from inside BlockTypeSetup
to cache an extern
statement. Each call to this function appends your buffer to the existing cache buffer. The extern
statements are placed in model
.h
or model
.ads
.
C Example
%openfile buffer extern real_T mydata; %closefile buffer %<LibCacheExtern(buffer)>
See function in matlabroot
/rtw/c/tlc/cachelib.tlc
or matlabroot
/rtw/ada/tlc/cachelib.tlc
.
LibCacheFunctionPrototype(buffer)
LibCacheFunctionPrototype
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
.
Example
%openfile buffer extern int_T fun1(real_T x); extern real_T fun2(real_T y, int_T i); %closefile buffer %<LibCacheFunctionPrototype(buffer)>
See function in matlabroot
/rtw/c/tlc/cachelib.tlc
.
LibCacheIncludes(buffer)
LibCacheIncludes
should be called from inside BlockTypeSetup
to cache #include
statements. Each call to this function appends your buffer to the existing cache buffer. The #include
statements are placed inside model
.h
.
Example
%openfile buffer #include "myfile.h" %closefile buffer %<LibCacheInclude(buffer)>
For Ada, the equivalent statements are placed in the Ada package specification.
See function in matlabroot
/rtw/c/tlc/cachelib.tlc
or matlabroot
/rtw/ada/tlc/cachelib.tlc
.
LibCacheTypedefs(buffer)
LibCacheTypedefs
should be called from inside BlockTypeSetup
to cache typedef
declarations. Each call to this function appends your buffer to the existing cache buffer. The typedef
statements are placed inside model
.h
or the Ada package specification if the language is Ada.
Example
%openfile buffer typedef foo bar; %closefile buffer %<LibCacheTypedefs(buffer)>
See function in matlabroot
/rtw/c/tlc/cachelib.tlc
or matlabroot
/rtw/ada/tlc/cachelib.tlc
.
LibGetGlobalTIDFromLocalSFcnTID(sfcnTID)
Returns the model task identifier (sample time index) corresponding to the specified local S-function task identifier or port sample time. This function allows you to use one function to determine a global TID, independent of port- or block-based sample times.
Calling this function with an integer argument is equivalent to the statement SampleTimesToSet[sfcnTID][1]
. SampleTimesToSet
is a matrix that maps local S-function TIDs to global TIDs.
The input argument to this function should be either
For block-based sample times (e.g., in S-function mdlInitializeSizes
, ssSetNumSampleTimes(S,N)
with N > 1
was specified), sfcnTID
is an integer starting at 0 of the corresponding local S-function sample time.
sfcnTID
: string of the form "InputPortIdxI", "OutputPortIdxI"
where I
is a number ranging from 0 to the number of ports (e.g., "InputPortIdx0", "OutputPortIdx7"
). For port-based sample times (e.g., in S-function mdlInitializeSizes
, ssSetNumSampleTimes(S,PORT_BASED_SAMPLE_TIMES)
was specified), sfcnTID
is a string giving the input (or output) port index.
Examples
%assign globalTID = LibGetGlobalTIDFromLocalSFcnTID(2)
%assign globalTID = LibGetGlobalTIDFromLocalSFcnTID("InputPortIdx4") %assign period = CompiledModel.SampleTime[globalTID].PeriodAndOffset[0] %assign offset = CompiledModel.SampleTime[globalTID].PeriodAndOffset[1]
%switch (LibGetSFcnTIDType(0)) %case "discrete" %case "continuous" %assign globalTID = LibGetGlobalTIDFromLocalSFcnTID(2) %assign period = ... CompiledModel.SampleTime[globalTID].PeriodAndOffset[0] %assign offset = ... CompiledModel.SampleTime[globalTID].PeriodAndOffset[1] %breaksw %case "triggered" %assign period = -1 %assign offset = -1 %breaksw %case "constant" %assign period = rtInf %assign offset = 0 %breaksw %default %<LibBlockReportFatalError([],"Unknown tid type")> %endswitch
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibGetNumSFcnSampleTimes(block)
Returns the number of S-function sample times for a block.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibGetSFcnTIDType(sfcnTID)
Returns the type of the specified S-function's task identifier (sfcnTID
).
"continuous"
if the specified sfcnTID
is continuous.
"discrete"
if the specified sfcnTID
is discrete.
The format of sfcnTID
must be the same as for LibIsSFcnSampleHit
.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibGetTaskTimeFromTID(block)
Returns the string "ssGetT(S)"
if the block is constant or the system is single rate and "ssGetTaskTime(S, tid)"
otherwise. In both cases, S is the name of the SimStruct.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsContinuous(TID)
Returns 1 if the specifed task identifier (TID
) is continuous, 0 otherwise. Note, TID
s equal to "triggered"
or "constant"
are not continuous.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsDiscrete(TID)
Returns 1 if the specifed task identifier (TID
) is discrete, 0 otherwise. Note, task identifiers equal to "triggered"
or "constant"
are not discrete.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsSFcnSampleHit(sfcnTID)
Returns 1 if a sample hit occurs for the specified local S-function task identifier (TID
), 0 otherwise.
The input argument to this function should be either
For block-based sample times (e.g., in S-function mdlInitializeSizes
, ssSetNumSampleTimes(S,N)
with N > 1 was specified), sfcnTID
is an integer starting at 0 of the corresponding local S-function sample time.
sfcnTID
: "InputPortIdx
I
", "OutputPortIdx
I
"
(e.g., "InputPortIdx
0
", "OutputPortIdx7"
)
For port based sample times (e.g., in S-function mdlInitializeSizes
, ssSetNumSampleTimes(S,PORT_BASED_SAMPLE_TIMES)
was specified), sfcnTID
is a string giving the input (or output) port index.
Examples
LibIsSFcnSampleHit(2)
will return the code to check for a sample hit on the 3rd S-function block sample time.LibIsSFcnSampleHit("InputPortIdx0")
returns the code to check for a sample hit on the first input port. The call LibIsSFcnSampleHit("OutputPortIdx7")
returns the code to check for a sample hit on the eight output port.See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsSFcnSingleRate(block)
LibIsSFcnSingleRate
returns a boolean value (1 or 0) indicating whether the S-function is single rate (one sample time) or multirate (multiple sample times).
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsSFcnSpecialSampleHit(sfcnSTI, sfcnTID)
Returns the Simulink macro to promote a slow task (sfcnSTI
) into a faster task (sfcnTID
).
This advanced function is specifically intended for use in rate transition blocks. This function determines the global TID
from the S-function TID and
calls LibIsSpecialSampleHit
using the global TID
s for both the sample time index (sti
) and the task ID (tid
).
The input arguments to this function are:
sfcnSTI
: local S-function sample time index (sti
) of the slow task that is to be promoted
sfcnTID
: local S-function task ID (tid
) of the fast task where the slow task will be run.
SS_OPTION_RATE_TRANSITION
, sfcnSTI
and sfcnTID
are ignored and should be specified as ""
.The format of sfcnSTI
and sfcnTID
must follow that of the argument to LibIsSFcnSampleHit
.
Examples
if (%<LibIsSFcnSpecialSampleHit("","")>) {
if (%<LibIsSFcnSpecialSampleHit("OutputPortIdx0","InputPortIdx0")>) {
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibCallFCSS(system, simObject, portEl, tidVal)
For use by inlined S-functions with function call outputs. Returns a string to either call function-call subsystem with the appropriate number of arguments or generates the subsystem's code right there (inlined).
See the SFcnSystemOutputCall
record in the model
.rtw
file.
The return string is determined by the current code format.
Example
%foreach fcnCallIdx = NumSFcnSysOutputCalls %% call the downstream system %with SFcnSystemOutputCall[fcnCallIdx] %% skip unconnected function call outputs %if LibIsEqual(BlockToCall, "unconnected") %continue %endif %assign sysIdx = BlockToCall[0] %assign blkIdx = BlockToCall[1] %assign ssBlock = System[sysIdx].Block[blkIdx] %assign sysToCall = System[ssBlock.ParamSettings.SystemIdx] %<LibCallFCSS(sysToCall, tSimStruct, FcnPortElement, ... ParamSettings.SampleTimesToSet[0][1])>\ %endwith %endforeach
BlockToCall
and FcnPortElement
are elements of the SFcnSystemOutputCall
record. System is a record within the global CompiledModel
record.
This example is from the file matlabroot
/toolbox/simulink/blocks/tlc_c/fcncallgen.tlc
.
See function in matlabroot
/rtw/c/tlc/syslib.tlc
or matlabroot
/rtw/ada/tlc/syslib.tlc
.
LibGetDataTypeComplexNameFromId(id)
Returns the name of the complex data type corresponding to a data type ID. For example, if id == tSS_DOUBLE
then this function returns "creal_T"
.
See function in matlabroot
/rtw/c/tlc/dtypelib.tlc
or matlabroot
/rtw/ada/tlc/dtypelib.tlc
.
LibGetDataTypeEnumFromId(id)
Returns the data type enum
corresponding to a data type ID. For example id == tSS_DOUBLE
=> enum = "SS_DOUBLE"
. If id
does not correspond to a built-in data type, this function returns ""
.
See function in matlabroot
/rtw/c/tlc/dtypelib.tlc
or matlabroot
/rtw/ada/tlc/dtypelib.tlc
.
LibGetDataTypeNameFromId(id)
Returns the data type name corresponding to a data type ID
.
See function in matlabroot
/rtw/c/tlc/dtypelib.tlc
or matlabroot
/rtw/ada/tlc/dtypelib.tlc
.
LibGetT()
Returns a string to access the absolute time. You should only use this function to access time.
Calling this function causes the global flag CompiledModel.NeedAbsoluteTime
to be set to 1. If this flag isn't set and you manually accessed time, the generated code will not compile.
This function is the TLC version of the SimStruct macro, ssGetT
.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsComplex(arg)
Returns 1 if the argument passed in is complex, 0 otherwise.
See function in matlabroot
/rtw/c/tlc/utillib.tlc
or matlabroot
/rtw/ada/tlc/utillib.tlc
.
LibIsFirstInitCond(s)
LibIsFirstInitCond
returns generated code intended for placement in the initialization function. This code determines, during run-time, whether the initialization function is being called for the first time.
This function also sets a flag that tells the Real-Time Workshop if it needs to declare and maintain the first-initialize-condition
flag.
This function is the TLC version of the SimStruct macro, ssIsFirstInitCond
.
See function in matlabroot
/rtw/c/tlc/syslib.tlc
or matlabroot
/rtw/ada/tlc/syslib.tlc
.
LibMaxIntValue(dtype)
For a built-in integer data type, this function returns the formatted maximum value of that data type.
See function in matlabroot
/rtw/c/tlc/dtypelib.tlc
or matlabroot
/rtw/ada/tlc/dtypelib.tlc
.
LibMinIntValue(dtype)
For a built-in integer data type, this function returns the formatted minimum value of that data type.
See function in matlabroot
/rtw/c/tlc/dtypelib.tlc
or matlabroot
/rtw/ada/tlc/dtypelib.tlc
.
LibBlockInputSignalBufferDstPort(portIdx)
Returns the output port corresponding to input port (portIdx
) that share the same memory, otherwise (-1) is returned. You will need to use this function when you specify ssSetInputPortOverWritable(S,portIdx,TRUE)
in your S-function.
If an input port and some output port of a block are:
then the output port might reuse the same buffer as the input port. In this case, LibBlockInputSignalBufferDstPort
returns the index of the output port that reuses the specified input port's buffer. If none of the block's output ports reuse the specified input port buffer, then this function returns -1.
This function is the TLC implementation of the Simulink macro ssGetInputPortBufferDstPort
.
Example
Assume you have a block that has two input ports, both of which receive a complex number in 2-wide vectors. The block outputs the product of the two complex numbers.
%assign u1r = LibBlockInputSignal (0, "", "", 0) %assign u1i = LibBlockInputSignal (0, "", "", 1) %assign u2r = LibBlockInputSignal (1, "", "", 0) %assign u2i = LibBlockInputSignal (1, "", "", 1) %assign yr = LibBlockOutputSignal (0, "", "", 0) %assign yi = LibBlockOutputSignal (0, "", "", 1) %if (LibBlockInputSignalBufferDstPort(0) != -1) %% The first input is going to get overwritten by yr so %% we need to save the real part in a temporary variable. { real_T tmpRe = %<u1r>; %assign u1r = "tmpRe"; %endif %<yr> = %<u1r> * %<u2r> - %<u1i> * %<u2i>; %<yi> = %<u1r> * %<u2i> + %<u1i> * %<u2r>; %if (LibBlockInputSignalBufferDstPort(0) != -1) } %endif
Note that this example could have equivalently used (LibBlockInputSignalBufferDstPort(0) == 0)
as the boolean condition for the %if
statements since there is only one output port.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalStorageClass(portIdx, idx)
Returns the storage class of the specified block input port signal. The storage class can be "Auto"
, "ExportedSignal"
, "ImportedExtern"
, or "ImportedExternPointer"
.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockInputSignalStorageTypeQualifier(portIdx, idx)
Returns the storage type qualifier of the specified block input port signal. The type qualifier can be anything entered by the user such as "const"
. The default type qualifier is "Auto"
, which means do the default action.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalIsGlobal(portIdx)
Returns 1 if the specified block output port signal is declared in the global scope, otherwise returns 0.
If this function returns 1, then the variable holding this signal is accessible from any where in generated code. For example, this function returns 1 for signals that are test points, external or invariant.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalIsInBlockIO(portIdx)
Returns 1 if the specified block output port exists in the global Block I/O data structure. You may need to use this if you specify ssSetOutputPortReusable(S,portIdx,TRUE)
in your S-function.
See matlabroot
/toolbox/simulink/blocks/tlc_c/sfun_multiport.tlc
.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalIsValidLValue(portIdx)
Returns 1 if the specified block output port signal can be used as a valid left hand side argument (lvalue
) in an assignment expression, otherwise returns 0. For example, this function returns 1 if the block output port signal is in read/write memory.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalStorageClass(portIdx)
Returns the storage class of the block's specified output signal. The storage class can be "Auto"
, "ExportedSignal"
, "ImportedExtern"
, or "ImportedExternPointer"
.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockOutputSignalStorageTypeQualifier(portIdx)
Returns the storage type qualifier of the block's specified output signal. The type qualifier can be anything entered by the user such as "const"
. The default type qualifier is "Auto"
, which means do the default action.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockSrcSignalBlock(portIdx, idx)
Returns a reference to the block that is source of the specified block input port element. The return argument is one of the following.
Example
If you want to find the block that drives the second input on the first port of the current block, then, assign the input signal of this source block to the variable y
. The following code fragment does exactly this.
%assign srcBlock = LibBlockSrcSignalBlock(0, 1) %% Make sure that the source is a block %if TYPE(srcBlock) == "Vector" %assign sys = srcBlock[0] %assign blk = srcBlock[1] %assign block = CompiledModel.System[sys].Block[blk] %with block %assign u = LibBlockInputSignal(0, "", "", 0) y = %<u>; %endwith %endif
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockSrcSignalIsDiscrete(portIdx, idx)
Returns 1 if the source signal corresponding to the specified block input port element is discrete, otherwise returns 0.
Note that this function also returns 0 if the driving block cannot be uniquely determined if it is a merged or reused signal (i.e., the source is a Merge block or the signal has been reused due to optimization).
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockSrcSignalIsGlobalAndModifiable(portIdx, idx)
This function returns 1 if the source signal corresponding to the specified block input port element satisfies the following three conditions:
Otherwise, this function returns 0.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
LibBlockSrcSignalIsInvariant(portIdx, idx)
Returns 1 if the source signal corresponding to the specified block input port element is invariant (i.e., the signal does not change).
For example, a source block with a constant TID
(or equivalently, an infinite sample time) would output an invariant signal.
See function in matlabroot
/rtw/c/tlc/blkiolib.tlc
or matlabroot
/rtw/ada/tlc/blkiolib.tlc
.
![]() | Obsolete Functions | model.rtw | ![]() |