Main Content

Miscellaneous Functions

LibAddtoSystemCustomIncludes(system, incFileName)

For use by inlined S-functions within a subsystem. Adds #include file to the system header file.

Call this function from the BlockInstanceSetup(block, system) method of the block so that different S-functions can include different header files. Specify your header file without any braces (for example, "myInclude.h") and include the system header file in braces (for example, "<sysinclude.h>").

Each call to this function adds the file to the list of included headers files only if it is not already included.

Example

%function BlockInstanceSetup(block, system) Output
  %assign incFileName = "sfun_custincl.h"
  %<LibAddToSystemCustomIncludes(system, incFileName)>
%endfunction

%function Outputs(block, system) Output
%endfunction

See LibAddToSystemCustomIncludes in commonhdrlib.tlc.

LibBlockExecuteFcnCall(block, callIdx)

For use by inlined S-functions with function-call outputs. Returns a string to call the function-call subsystem with required arguments or generates the subsystem's code in place (inlined).

Example

%foreach callIdx = NumSFcnSysOutputCalls
  %if LibIsEqual(SFcnSystemOutputCall[callIdx].BlockToCall,...
   "unconnected")
    %continue
  %endif
%% call the downstream system
  %<LibBlockExecuteFcnCall(block, callIdx)>\
%endforeach

See LibBlockExecuteFcnCall in syslib.tlc.

LibBlockExecuteFcnDisable(block, callIdx)

For use by inlined S-Functions to call the function-call system disable function. Returns a string to either call the function-call subsystem disable function with required arguments or to call the generated subsystem disable code (inlined).

Example

%foreach callIdx = NumSFcnSysOutputCallDsts
  %if LibIsEqual(SFcnSystemOutputCall[callIdx].BlockToCall, "unconnected")
   %continue
  %endif
%% call the downstream system
  %<LibBlockExecuteFcnDisable(block, callIdx)>\
%endforeach

See LibBlockExecuteFcnDisable in syslib.tlc.

LibBlockExecuteFcnEnable(block, callIdx)

For use by inlined S-Functions to call the function-call system enable function. Returns a string to call the function-call subsystem enable function with required arguments or the generated subsystem enable code (inlined).

Example

%foreach callIdx = NumSFcnSysOutputCallDsts
  %if LibIsEqual(SFcnSystemOutputCall[callIdx].BlockToCall, "unconnected")
   %continue
  %endif
%% call the downstream system
  %<LibBlockExecuteFcnEnable(block, callIdx)>\
%endforeach

See LibBlockExecuteFcnEnable in syslib.tlc.

LibBlockInputSignalAliasedThruDataTypeId(idx)

Returns the data type ID the input signal is aliased thru to.

See LibBlockInputSignalAliasedThruDataTypeId in dtypelib.tlc.

LibBlockOutputSignalAliasedThruDataTypeId(idx)

Returns the data type ID the output signal is aliased thru to.

See LibBlockOutputSignalAliasedThruDataTypeId in dtypelib.tlc.

LibDataTypeElementDataTypeId(id, idx)

Returns an integer representing the data type ID of the specified element at index idx within a data type identified by the parent data type ID id.

See LibDataTypeElementDataTypeId in dtypelib.tlc.

LibDataTypeElementName(id, idx)

Returns a string representing the name of the specified element at index idx within a data type identified by the parent data type ID id.

See LibDataTypeElementName in dtypelib.tlc.

LibDataTypeElementNumDimensions(id, idx)

Returns an integer representing the number of dimensions of the specified element at index idx within a data type identified by the parent data type ID id.

See LibDataTypeElementNumDimensions in dtypelib.tlc.

LibDataTypeElementWidth(id, idx)

Returns an integer representing the width of the specified element at index idx within a data type identified by the parent data type ID id.

See LibDataTypeElementWidth in dtypelib.tlc.

LibDataTypeNumElements(id)

Returns an integer representing the count of elements within the data type specified by the ID id.

See LibDataTypeNumElements in dtypelib.tlc.

LibEmitPlatformTypeIncludes()

Emit code to include headers for platform types. For example, if the DataTypeReplacement configuration parameter is set to 'CDataTypesFixedWidth' and no custom data type names are specified, the emitted code is:

#include <stdint.h>
#include <stdbool.h>

If DataTypeReplacement is set to 'CoderTypedefs', the emitted code is:

 #include "rtwtypes.h"

See LibEmitPlatformTypeIncludes in commonhdrlib.tlc.

LibEndSharedUtilityFcn(functionName)

Indicates the end of the utility function code block in the generated code.

See LibEndSharedUtilityFcn in cache_sharedutils_api.tlc.

LibGenConstVectWithInit(data, typeId, varId)

Returns an initialized static constant variable string of form:

static const typeName varId[] = { data };

The typeName is generated from typeId, which can be one of

tSS_DOUBLE, tSS_SINGLE, tSS_BOOLEAN, tSS_INT8, tSS_UINT8, 
tSS_INT16, tSS_UINT16, tSS_INT32, tSS_UINT32

The data input argument must be a numeric scalar or vector and must be finite (no Inf, -Inf, or NaN values).

See LibGenConstVectWithInit in utillib.tlc.

LibGetBlockAttribute(block, attr)

Get a field value inside a block record.

Syntax

%if LibIsEqual(LibGetBlockAttribute(ssBlock,"MaskType"), ... 
  "Task Block")
  %assign isTaskBlock = 1
%endif

Returns

Returns the value of the attribute (field) or an empty string if it does not exist.

See LibGetBlockAttribute in asynclib.tlc.

LibGetCallerClockTickCounter(sfcnBlock)

For use by asynchronous S-functions with function call outputs. Asynchronous tasks can manage their own time. LibGetCallerClockTickCounter is used to access an upstream asynchronous task's time counter. This is preferred when being driven by another asynchronous rate (e.g., an Interrupt block driving a Task block) because the time the interrupt occurred is used, rather than the time the task is allowed to run.

Returns

Returns a string for the counter variable for the upstream asynchronous task.

See LibGetCallerClockTickCounter in asynclib.tlc.

LibGetCallerClockTickCounterHigh(sfcnBlock)

For use by asynchronous S-functions with function-call outputs. Asynchronous tasks can manage their own time. LibGetCallerClockTickCounterHigh is used to access the high word of an upstream asynchronous task's time counter. This is preferred when being driven by another asynchronous rate (for example, an Interrupt block driving a Task block) because the time the interrupt occurred is used rather than the time the Task is allowed to run.

Returns

Returns a string for the high word of the counter variable for the upstream asynchronous task.

See LibGetCallerClockTickCounterHigh in asynclib.tlc.

LibGetDataTypeComplexNameFromId(id)

Returns the name of the complex data type corresponding to a data type ID. For example, if id==tSS_DOUBLE then LibGetDataTypeComplexNameFromId returns "creal_T".

See LibGetDataTypeComplexNameFromId in dtypelib.tlc.

LibGetDataTypeEnumFromId(id)

Returns the data type enum corresponding to a data type ID. For example, if id==tSS_DOUBLE, then enum is "SS_DOUBLE". If id does not correspond to a built-in data type, LibGetDataTypeEnumFromId returns "".

See LibGetDataTypeEnumFromId in dtypelib.tlc.

LibGetDataTypeIdAliasedThruToFromId(id)

Returns the data type IdAliasedThruTo that corresponds to a data type ID. For example, if yourfloat is an alias to myfloat, and myfloat is an alias to double, then the IdAliasedThruTo for both yourfloat and myfloat is 0 (because the ID for double is 0).

See LibGetDataTypeIdAliasedThruToFromId in dtypelib.tlc.

LibGetDataTypeIdAliasedToFromId(id)

Returns the data type IdAliasedTo that corresponds to a data type ID. For example, if yourfloat is an alias to myfloat, and myfloat is an alias to double, then the IdAliasedTo for yourfloat is the ID for myfloat, and the IdAliasedTo for myfloat is 0 (because the ID for double is 0).

See LibGetDataTypeIdAliasedToFromId in dtypelib.tlc.

LibGetDataTypeIdResolvesToFromId(id)

Returns the data type IdResolvesTo that corresponds to a data type ID.

See LibGetDataTypeIdResolvesToFromId in dtypelib.tlc.

LibGetDataTypeNameFromId(id)

Returns the data type name that corresponds to a data type ID.

See LibGetDataTypeNameFromId in dtypelib.tlc.

LibGetDataTypeSLSizeFromId(id)

Return the size (as Simulink® knows it) corresponding to a data type ID.

See LibGetDataTypeSLSizeFromId in dtypelib.tlc.

LibGetDataTypeStorageIdFromId(id)

Returns the data type StorageId corresponding to a data type ID. For example, if the input ID is the ID for a 16-bit signed fixed-point data type, then the StorageId corresponds to int16.

See LibGetDataTypeStorageIdFromId in dtypelib.tlc.

LibGetFcnCallBlock(sfcnblock,callIdx)

Given an S-function block and call index, return the block record for the downstream function-call subsystem block.

Syntax

 %assign ssBlock = LibGetFcnCallBlock(block,0)

Returns

The block record of the downstream function-call subsystem connected to that element (call index).

See LibGetFcnCallBlock in asynclib.tlc.

LibGetRecordDataTypeId(rec)

Returns the data type identifier of the specified record as an integer.

See LibGetRecordDataTypeId in dtypelib.tlc.

LibGetRecordDimensions(rec)

Returns the dimensions of the specified record as a vector of integers.

See LibGetRecordDimensions in dtypelib.tlc.

LibGetRecordIsComplex(rec)

Returns the value 1 if the specified record is complex, and zero otherwise.

See LibGetRecordIsComplex in dtypelib.tlc.

LibGetRecordWidth(rec)

Returns the width of the specified record as an integer.

See LibGetRecordWidth in dtypelib.tlc.

LibGetT()

Returns a string to access the absolute time, which is a floating-point number. However, if you have configured the model for integer-only code generation (by deselecting Support floating-point numbers), the string represents an integer equal to the number of base rate ticks (the absolute time divided by the base sample time) rather than the absolute time.

You should use LibGetT to access time only.

LibGetT is the TLC version of the SimStruct macro ssGetT.

See LibGetT in utillib.tlc.

LibIsComplex(arg)

Returns 1 if the argument passed in is complex, 0 otherwise.

See LibIsComplex in utillib.tlc.

LibIsFirstInitCond()

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.

LibIsFirstInitCond also sets a flag that tells the code generator if it needs to declare and maintain the first-initialize-condition flag.

LibIsFirstInitCond is the TLC version of the SimStruct macro ssIsFirstInitCond.

See LibIsFirstInitCond in syslib.tlc.

LibIsMajorTimeStep()

Returns a string to access whether the current simulation step is a major time step.

LibIsMajorTimeStep is the TLC version of the SimStruct macro ssIsMajorTimeStep.

See LibIsMajorTimeStep in utillib.tlc.

LibIsMinorTimeStep()

Returns a string to access whether the current simulation step is a minor time step.

LibIsMinorTimeStep is the TLC version of the SimStruct macro ssIsMinorTimeStep.

See LibIsMinorTimeStep in utillib.tlc.

LibManageAsyncCounter(sfcnBlock, callIdx)

For use by asynchronous S-Functions with function-call outputs. Asynchronous tasks can manage their own time, and use LibManageAsyncCounter to determine whether a need exists for an asynchronous counter to manage its own timer.

Example

%if LibManageAsyncCounter(block,callIdx)
  %%	  %<LibSetAsyncCounter(block,callIdx), CodeGetCounter)>

where CodeGetCounter is target specific code reading hardware timer.

Returns

Returns TLC_TRUE if an asynchronous counter is required to manage its own counter, otherwise TLC_FALSE.

See LibManageAsyncCounter in asynclib.tlc.

LibMaxIntValue(dtype)

For a built-in integer data type, LibMaxIntValue returns the formatted maximum value of that data type.

See LibMaxIntValue in dtypelib.tlc.

LibMinIntValue(dtype)

For a built-in integer data type, LibMinIntValue returns the formatted minimum value of that data type.

See LibMinIntValue in dtypelib.tlc.

LibNeedAsyncCounter(sfcnBlock, callIdx)

For use by asynchronous S-functions with function-call outputs. Asynchronous tasks use LibNeedAsyncCounter to determine whether a need exists for an asynchronous counter.

Example

%if LibNeedAsyncCounter(block,0)
  %<LibSetAsyncCounter(block,0), "tickGet()")>

Returns

Returns TLC_TRUE if an asynchronous counter is required, otherwise TLC_FALSE.

See LibNeedAsyncCounter in asynclib.tlc.

LibSetAsyncClockTicks(sfcnBlock, callIdx, buf1, buf2)

For use by asynchronous S-functions with function-call outputs. Asynchronous tasks can manage their own time. Use LibSetAsyncClockTicks to return code that sets clockTick counters that are to be maintained by the asynchronous task. If the data type of a clockTick counter maintained by the asynchronous task is tSS_TIMER_UINT32_PAIR, the low and high word of the clockTick counter are set.

Arguments

buf1 — Code that reads the low word of the hardware counter

buf2 — Code that reads the high word of the hardware counter. Leave buf2 empty if hardware counter length is less than 32 bits.

Returns

Returns code that sets clockTick counters that are to be maintained by the asynchronous task.

Example

%if LibNeedAsyncCounter(block, callIdx)
%<LibSetAsyncCounter(block, 0, buf1, buf2)>
%endif

See LibSetAsyncClockTicks in asynclib.tlc.

LibSetAsyncCounter(sfcnBlock, callIdx, buf)

For use by asynchronous S-functions with function-call outputs. Asynchronous tasks can manage their own time. Use LibSetAsyncCounter to return code that sets a counter variable that is to be maintained by the asynchronous task.

Returns

Returns code that sets the counter variable that is to be maintained by the asynchronous task.

Example

%if LibNeedAsyncCounter(block,0)
  %<LibSetAsyncCounter(block,0, "tickGet()")> 
%endif

See LibSetAsyncCounter in asynclib.tlc.

LibSetAsyncCounterHigh(sfcnBlock, callIdx, buf)

For use by asynchronous S-functions with function-call outputs. Asynchronous tasks can manage their own time. Use LibSetAsyncCounterHigh to return code that sets the higher word of the counter variable that is to be maintained by the asynchronous task.

Returns

Returns code that sets the higher word of the counter variable that is to be maintained by the asynchronous task.

Example

%if LibNeedAsyncCounter(block,0)
%<LibSetAsyncCounterHigh(block,0, "hightTickGet()")>
%endif

See LibSetAsyncCounterHigh in asynclib.tlc.

LibStartSharedUtilityFcn(functionName)

Indicates the start of the utility function code block in the generated code. To include the required dependencies and to correctly associate tracked symbols and headers with their utility function, use LibStartSharedUtilityFcn and its corresponding function LibEndSharedUtilityFcn.

See LibStartSharedUtilityFcn in cache_sharedutils_api.tlc.

LibTIDInSystem(system, fcnType)

Purpose

Returns a task identifier (TID) if it is in the scope of a subsystem function and can be called before or during TLC generating code.

Syntax

LibTIDInSystem(system, fcnType)

Arguments

system

A record within the global CompiledModel record.

fcnType

One of the following: 'Output', 'Update', 'Outputupdate'.

Description

This function returns a TID if it is in the scope of a subsystem function and can be called before or during TLC generating code. It returns the TID argument name, if a TID is passed as argument in the system function scope. If TID is not passed as argument in the scope, this function returns:

  • '0' if model is single tasking.

  • The TID value of the subsystem if the subsystem is single rate.

  • A local TID variable name, if the subsystem is multirate. A local TID variable is added to the subsystem code.

Note

This function issue an error message if it is called for a reusable subsystem whose instances run at different rates.

See LibTIDInSystem in syslib.tlc.

LibIsRowMajor

Returns true when the current model uses the row-major array layout.

See LibIsRowMajor in dtypelib.tlc.

Obsolete Functions

The following table shows obsolete functions and the functions that have replaced them.

Obsolete FunctionEquivalent Replacement Function

LibBlockOutportLocation

LibBlockDstSignalLocation

LibCacheGlobalPrmData

Use the block function Start

LibCacheIncludes

LibAddToCommonIncludes

LibContinuousState

LibBlockContinuousState

LibControlPortInputSignal

LibBlockSrcSignalLocation

LibConvertZCDirection

Function is not used in code generation.

LibDataInputPortWidth

LibBlockInputSignalWidth

LibDataOutputPortWidth

LibBlockOutputSignalWidth

LibDefineIWork
LibDefinePWork
LibDefineRWork

IWork , PWork, and RWork names are now specified via the mdlRTW function in your C MEX S-function.

LibDiscreteState

LibBlockDiscreteState

LibExportFileCustomCode

LibSetSourceFileSection

LibExternalResetSignal

LibBlockInputSignal

LibHeaderFileCustomCode

LibSetSourceFileSection

LibIsEqual

Use built-in function ISEQUAL

LibMapSignalSource

FcnMapDataTypedSignalSource

LibMaxBlockIOWidth

Function is not used in Simulink Coder™ code generation.

LibMaxDataInputPortWidth

Function is not used in Simulink Coder code generation.

LibMaxDataOutputPortWidth

Function is not used in Simulink Coder code generation.

LibPathName

LibGetBlockPath, LibGetFormattedBlockPath

LibPrevZCState

LibBlockPrevZCState

LibPrmFileCustomCode

LibSetSourceFileSection

LibRegFileCustomCode

LibSetSourceFileSection

LibRegisterGNUMathFcnPrototypes

Function is not used in Simulink Coder code generation.

LibRegisterISOCMathFcnPrototypes

Function is not used in Simulink Coder code generation.

LibRegisterMathFcnPrototype

Function is not used in Simulink Coder code generation.

LibRenameParameter

Specifying parameter names is now supported via the mdlRTW function in your C MEX S-function.

Related Topics