Main Content

Advanced Functions

LibAppendToModelReferenceUserData(data)

Appends the given data object to the user data in the binfo file for the model currently being built. This function is only called during builds for model reference targets.

Note

The data argument cannot be a vector or matrix. To work around this limitation, create a record with a field containing the vector or matrix data and pass this record into the function.

See LibAppendToModelReferenceUserData in modelrefutil.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 LibBlockInputSignalBufferDstPort when you specify ssSetInputPortOverWritable(S,portIdx,TRUE) in your S-function.

If an input port and some output port of a block are

  • Not test points, and

  • The input port is overwritable

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 LibBlockInputSignalBufferDstPort returns -1.

LibBlockInputSignalBufferDstPort is the TLC version 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 be 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, because only one output port exists, this example could have used (LibBlockInputSignalBufferDstPort(0) == 0) as the Boolean condition for the %if statements.

See LibBlockInputSignalBufferDstPort in blkiolib.tlc.

LibBlockInputSignalStorageClass(portIdx, sigIdx)

Returns the storage class of the specified block input port signal. The storage class can be "Auto", "ExportedSignal", "ImportedExtern", or "ImportedExternPointer".

See LibBlockInputSignalStorageClass in blkiolib.tlc.

LibBlockInputSignalStorageTypeQualifier
(portIdx, sigIdx)

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 LibBlockInputSignalStorageTypeQualifier in blkiolib.tlc.

LibBlockOutputSignalIsGlobal(portIdx)

Returns 1 if the specified block output port signal is declared in the global scope, otherwise returns 0.

If LibBlockOutputSignalIsGlobal returns 1, then the variable holding this signal is accessible from anywhere in generated code. For example, LibBlockOutputSignalIsGlobal returns 1 for signals that are test points, external, or invariant.

See LibBlockOutputSignalIsGlobal in blkiolib.tlc.

LibBlockOutputSignalIsInBlockIO(portIdx)

Returns 1 if the specified block output port exists in the global block I/O data structure. You might need to use this if you specify ssSetOutputPortReusable(S,portIdx,TRUE) in your S-function.

See sfun_multiport.tlc.

See LibBlockOutputSignalIsInBlockIO in blkiolib.tlc.

LibBlockOutputSignalIsValidLValue(portIdx)

Returns 1 if the specified block output port signal can be used as a valid left-side argument (lvalue) in an assignment expression, otherwise returns 0. For example, LibBlockOutputSignalIsValidLValue returns 1 if the block output port signal is in read/write memory.

See LibBlockOutputSignalIsValidLValue in 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 LibBlockOutputSignalStorageClass in 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 LibBlockOutputSignalStorageType in blkiolib.tlc.

LibBlockSrcSignalBlock(portIdx, sigIdx)

Returns a reference to the block that is the source of the specified block input port element. The return argument is one of the following:

[systemIdx, blockIdx]

If the block output or state is unique

"ExternalInput"

If external input (root inport)

"Ground"

If unconnected or connected to ground

"FcnCall"

If function-call output

0

If not unique (i.e., source for a Merge block or a signal reused because of block I/O optimization)

Example

The following code fragment finds the block that drives the second input on the first port of the current block, then assigns the input signal of this source block to the variable y:

%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 LibBlockSrcSignalBlock in blkiolib.tlc.

LibBlockSrcSignalIsDiscrete(portIdx, sigIdx)

Returns 1 if the source signal corresponding to the specified block input port element is discrete, otherwise returns 0.

Note that LibBlockSrcSignalIsDiscrete also returns 0 if the driving block cannot be uniquely determined to be a merged or reused signal (i.e., the source is a Merge block or the signal has been reused because of optimization).

See LibBlockSrcSignalIsDiscrete in blkiolib.tlc.

LibBlockSrcSignalIsGlobalAndModifiable
(portIdx, sigIdx)

LibBlockSrcSignalIsGlobalAndModifiable returns 1 if the source signal corresponding to the specified block input port element satisfies the following three conditions:

  • It is readable everywhere in the generated code.

  • It can be referenced by its address.

  • Its value can change (i.e., it is not declared as a const).

Otherwise, LibBlockSrcSignalIsGlobalAndModifiable returns 0.

See LibBlockSrcSignalIsGlobalAndModifiable in blkiolib.tlc.

LibBlockSrcSignalIsInvariant(portIdx, sigIdx)

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 LibBlockSrcSignalIsInvariant in blkiolib.tlc.

LibGetModelReferenceUserData(modelName)

Gets the user data for the given model. This returns a vector with one element for each time LibAppendToUserData is called in the given model. This function cannot be called during builds where the target type is SIM.

See LibGetModelReferenceUserData in modelrefutil.tlc.

LibGetReferencedModelNames()

Gets the names of the models referenced by the model that is currently being built. Returns the data as a structure with two fields:

  • NumReferencedModels: an integer with the number of model names

  • ReferencedModel: an array of structures, where each structure has a field –Name– containing the name of a referenced model

See LibGetReferencedModelNames in modelrefutil.tlc.

LibIsModelReferenceRTWTarget()

Returns true if the build process is generating code for model reference target.

See LibIsModelReferenceRTWTarget in utillib.tlc.

LibIsModelReferenceSimTarget()

Return true if we are generating code for model reference Simulation target.

See LibIsModelReferenceSimTarget in utillib.tlc.

LibIsModelReferenceTarget()

Return true if we are generating code for model reference target.

See LibIsModelReferenceTarget in utillib.tlc.

Related Topics