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
portIdx
Refers to an input or output port index, starting at zero, for example the first input port of an S-function is 0.
ucv
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 "".
lcv
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 "".
sigIdx
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:
  • An integer, e.g. 3. If the referenced signal is complex, then this refers to the identifier for the complex container. If the referenced signal is not complex, then this refers to the identifier.
  • An id-num usually of the form (see Overloading sigIdx):
    1. "%<tRealPart>%<idx>" (e.g., "re3"). The real part of the signal element. Usually "%<tRealPart>%<sigIdx>" when sigIdx is generated by the %roll directive.
    2. "%<tImagPart>%<idx>" (e.g., "im3"). The imaginary part of the signal element or "" if the signal is not complex. Usually "%<tImagPart>%<sigIdx>" when sigIdx is generated by the %roll directive.
The 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:

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

sigIdx
Complex
Function Returns
Example
Data
Type

"re3"
yes
Real part of element 3
u0[2].re
real_T
"im3"
yes
Imaginary part of element 3
u0[2].im
real_T
"3"
yes
Complex container of element 3
u0[2]
creal_T
3
yes
Complex container of element 3
u0[2]
creal_T
"re3"
no
Element 3
u0[2]
real_T
"im3"
no
" "
N/A
N/A
"3"
no
Element 3
u0[2]
real_T
3
no
Element 3
u0[2]
real_T

Now suppose:

  1. We are interested in element 3 of a signal
  2. (ucv = "i" AND lcv == "") OR (ucv = "" AND lcv = "i")

The following table shows values of idx, whether the signal is complex, and what the function that uses idx returns.

sigIdx
Complex
Function Returns
"re3"
yes
Real part of element i
"im3"
yes
Imaginary part of element i
"3"
yes
Complex container of element i
3
yes
Complex container of element i
"re3"
no
Element i
"im3"
no
" "
"3"
no
Element i
3
no
Element i

Notes

Input Signal Functions

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.

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

or, if the input signal sources to ground, the statement could come out as

neither of these would compile.

Avoid any such situations by using LibBlockInputSignalAddr.

Real-Time Workshop tracks signals and parameters accessed by their address and declares them in addressable memory.

Input Arguments (ucv, lcv, and sigIdx) Handling

Consider:

Function (case 1, 2, 3)
Example Return Value
LibBlockInputSignal(0, "i", "", sigIdx)
rtB.blockname[i]
LibBlockInputSignal(0, "", lcv, sigIdx)
u0[i1]
LibBlockInputSignal(0, "", lcv, sigIdx)
rtB.blockname[0]

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

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

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

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.

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.

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.

Output Signal Functions

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.

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

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.

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.

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.

Parameter Functions

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.

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.

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,

Case
Function Call
May Produce
1
LibBlockParameter(Gain, "i", lcv, sigIdx)
rtP.blockname[i]
2
LibBlockParameter(Gain, "i", lcv, sigIdx)
rtP.blockname
3
LibBlockParameter(Gain, "", lcv, sigIdx)
p_Gain[i]
4
LibBlockParameter(Gain, "", lcv, sigIdx)
p_Gain
5
LibBlockParameter(Gain, "", lcv, sigIdx)
4.55
6
LibBlockParameter(Gain, "", lcv, sigIdx)
rtP.blockname.re
7
LibBlockParameter(Gain, "", lcv, sigIdx)
rtP.blockname.im

To illustrate the basic workings of this function, assume a noncomplex vector signal where Gain[0]=4.55.

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.

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.

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

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 = [].

Specifically

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.

Code Configuration Functions

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.

Example.   

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

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

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

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

See function in matlabroot/rtw/c/tlc/cachelib.tlc or matlabroot/rtw/ada/tlc/cachelib.tlc.

Sample Time Functions

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

Examples

Multirate block.   

Inherited sample time block.   

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

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, TIDs 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

Examples

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 TIDs for both the sample time index (sti) and the task ID (tid).

The input arguments to this function are:

The format of sfcnSTI and sfcnTID must follow that of the argument to LibIsSFcnSampleHit.

Examples

See function in matlabroot/rtw/c/tlc/utillib.tlc or matlabroot/rtw/ada/tlc/utillib.tlc.

Other Useful Functions

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

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.

Advanced Functions

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.

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.

[systemIdx, blockIdx]
If unique block output or block state.
"ExternalInput"
If external input (root inport).
"Ground"
If unconnected or connected to ground.
"FcnCall"
If function-call output.
0
If not unique (i.e., sources to a Merge block or is a reused signal due to block I/O optimization).

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.

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