Sample Time Functions
LibAsynchronousTriggeredTID(tid)
Returns whether this TID corresponds to a asynchronous triggered rate.
See LibAsynchronousTriggeredTID in utillib.tlc.
LibAsyncTaskAccessTimeInFcn(tid, fcnType)
Returns 1 if the specified asynchronous task identifier (TID) is given function type.
See LibAsyncTaskAccessTimeInFcn in utillib.tlc.
LibBlockSampleTime(block)
Returns the block's sample time. The returned value depends on the sample time classification of the block, as shown in the following table.
| Block Classification | Returned Value |
|---|---|
Discrete | The actual sample time of a block (real >
|
Continuous |
|
Triggered |
|
Constant |
|
See LibBlockSampleTime in blocklib.tlc.
LibGetClockTick(tid)
Returns integer task time (current clock tick of the task timer). The resolution of the
timer can be obtained from LibGetClockTickStepSize(tid). The data type ID
of the timer can be obtained from LibGetClockTickDataTypeId(tid).
If you use this function in a target file for an S-Function block intended for use in
models that are configured for timer service interface code generation, specify a global
task identifier (tid). TLC library functions that use a
tid require the tid to be global. If you specify the
local tid, the code generator might produce incorrect code for the
S-Function block. Compute the global tid by specifying LibGetGlobalTIDFromLocalSFcnTID(sfcnTID).
See LibGetClockTick in utillib.tlc.
LibGetClockTickDataTypeId(tid)
Returns clock tick data type ID.
If you use this function in a target file for an S-Function block intended for use in
models that are configured for timer service interface code generation, specify a global
task identifier (tid). TLC library functions that use a
tid require the tid to be global. If you specify the
local tid, the code generator might produce incorrect code for the
S-Function block. Compute the global tid by specifying LibGetGlobalTIDFromLocalSFcnTID(sfcnTID).
See LibGetClockTickDataTypeId in utillib.tlc.
LibGetClockTickHigh(tid)
Returns high-order word of the integer task time. LibGetClockTickHigh
is used when uint32 pairs are used to store absolute time. The resolution
of a clock tick can be obtained from LibGetClockTickStepSize(tid).
See LibGetClockTickHigh in utillib.tlc.
LibGetClockTickStepSize(tid)
Returns clock tick step size, which is the resolution of the integer task time.
LibGetClockTickStepSize cannot be used if the task does not have a
timer.
If you use this function in a target file for an S-Function block intended for use in
models that are configured for timer service interface code generation, specify a global
task identifier (tid). TLC library functions that use a
tid require the tid to be global. If you specify the
local tid, the code generator might produce incorrect code for the
S-Function block. Compute the global tid by specifying LibGetGlobalTIDFromLocalSFcnTID(sfcnTID).
See LibGetClockTickStepSize in utillib.tlc.
LibGetElapseTime(system)
Returns time elapsed since the last time the subsystem started to execute.
If you use this function in a target file for an S-Function block intended for use in models that are configured for timer service interface code generation:
Configure the S-Function block to use elapsed time by calling the
SimStructfunctionssSetNeedElapseTimewith the elapsed time Boolean flag set to1.Configure models that use the block to support floating-point numbers (select model configuration parameter Support: floating-point numbers).
See LibGetElapseTime in utillib.tlc.
LibGetElapseTimeCounter(system)
Returns an integer elapsed time. This is the number of clock ticks elapsed since the last time the system started. For an aperiodic rate (triggered or asynchronous sample time), the function returns the elapsed time counter state (DWork vector) that is maintained by the conditionally executed parent subsystem of the component that maintains the elapsed time. For a periodic rate, the function returns an integer that equals the sample time divided by the elapsed time resolution.
To get real-world elapsed time, multiply the elapsed time by the applicable resolution.
Use LibGetElapseTimeCounter, in conjunction with functions
LibGetElapseTimeCounterDtypeId and
LibGetElapseTimeResolution. Use
LibGetElapseTimeCounterDTypeId(system) to get the data type ID of the
integer elapsed time counter. Use LibGetElapseTimeResolution to get the
resolution.
If you use this function in a target file for an S-Function block intended for use in
models that are configured for timer service interface code generation, configure the
S-Function block to use elapsed time by calling the
SimStruct function ssSetNeedElapseTime with the elapsed time Boolean flag set to
1.
See LibGetElapseTimeCounter in utillib.tlc.
LibGetElapseTimeCounterDTypeId(system)
Returns the date type ID of the integer elapsed time returned by
LibGetElapseTimeCounter.
See LibGetElapseTimeCounterDTypeId in utillib.tlc.
LibGetElapseTimeResolution(system)
Returns the resolution of the elapsed time returned by
LibGetElapseTimeCounter. When model configuration parameter Clock resolution (seconds, -1 for inherited) is set to a value
other than -1, the function returns the specified clock resolution. When
Clock resolution (seconds, -1 for inherited) is set to -1
(default), the value that the function returns depends on whether the rate of the S-function
is aperiodic (triggered or asynchronous sample time) or periodic. If the rate is aperiodic,
LibGetElapseTimeResolution returns the fixed-step size (fundamental
sample time) of the model. If the rate is periodic,
LibGetElapseTimeResolution returns the sample time.
See LibGetElapseTimeResolution in utillib.tlc.
LibGetGlobalTIDFromLocalSFcnTID(sfcnTID)
Returns the model task identifier (sample time index) corresponding to the specified
local S-function task identifier or port sample time.
LibGetGlobalTIDFromLocalSFcnTID allows you to use one function to
determine a global TID, independent of port- or block-based sample times.
The input argument to LibGetGlobalTIDFromLocalSFcnTID should be one
of the following:
For block-based sample times (e.g., in S-function
mdlInitializeSizes,ssSetNumSampleTimes(S, N)withN > 1was specified),sfcnTIDis a nonnegative integer giving the corresponding local S-function sample time.For port-based sample times (e.g., in S-function
mdlInitializeSizes,ssSetNumSampleTimes(S, PORT_BASED_SAMPLE_TIMES)was specified),sfcnTIDis a string of the form"InputPortIdxorI""OutputPortIdx, whereI"is an integer ranging from 0 to the number of ports (e.g.,I"InputPortIdx0".
Examples
Multirate block
%assign globalTID = LibGetGlobalTIDFromLocalSFcnTID(2)
or
%assign globalTID =
LibGetGlobalTIDFromLocalSFcnTID("InputPortIdx4")
%assign period =
CompiledModel.SampleTime[globalTID].PeriodAndOffset[0]
%assign offset =
CompiledModel.SampleTime[globalTID].PeriodAndOffset[1]Inherited sample time block
%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]
%break
%case "triggered"
%assign period = -1
%assign offset = -1
%break
%case "constant"
%assign period = rtInf
%assign offset = 0
%break
%default
%<LibBlockReportFatalError([],"Unknown tid type")>
%endswitchSee LibGetGlobalTIDFromLocalSFcnTID in utillib.tlc.
LibGetNumAsyncTasks()
Return the number of asynchronous tasks in generated code.
See LibGetNumAsyncTasks in utillib.tlc.
LibGetNumSFcnSampleTimes(block)
Returns the number of S-function sample times for a block.
See LibGetNumSFcnSampleTimes in utillib.tlc.
LibGetNumSyncPeriodicTasks()
Return the number of periodic tasks in generated code.
See LibGetNumSyncPeriodicTasks in utillib.tlc.
LibGetNumTasks()
Return the number of tasks in generated code.
See LibGetNumTasks in utillib.tlc.
LibGetSampleTimeNeedsAbsoluteTime(sampleTimeIdx)
Checks if the sample time specified by sampleTimeIdx requires
absolute time and returns a Boolean value.
Argument
sampleTimeIdx — Specify an integer indicating the index of the
sample time (zero-based).
Example
% Check if absolute time is needed for the fourth sample time needsAbsoluteTime = LibGetSampleTimeNeedsAbsoluteTime(3);
See LibGetSampleTimeNeedsAbsoluteTime in utils_api.tlc.
LibGetSampleTimeNeedsFloatTime(sampleTimeIdx)
Checks if the sample time specified by sampleTimeIdx requires
floating time and returns a Boolean value.
Argument
sampleTimeIdx — Specify an integer indicating the index of the
sample time (zero-based).
Example
% Check if floating time is needed for the fourth sample time needsFloatTime = LibGetSampleTimeNeedsFloatTime(3);
See LibGetSampleTimeNeedsFloatTime in utils_api.tlc.
LibGetSampleTimePeriodAndOffset(tid, idx)
Returns the sample time period value or offset value for a specified task.
Arguments
tid — Specify the identifier of the task for which to return
information.
idx — Specify 0 to return the sample time period value or 1
to return the sample time offset value.
Examples
%% Get sample time period and offset for task 0 %assign sampleTime = LibGetSampleTimePeriodAndOffset(0,0) %assign offsetTime = LibGetSampleTimePeriodAndOffset(0,1) %% Get sample time periods for tasks 0 and 1 %assign periodTID0 = LibGetSampleTimePeriodAndOffset(0,0) %assign periodTID1 = LibGetSampleTimePeriodAndOffset(1,0)
See LibGetSampleTimePeriodAndOffset in codetemplatelib.tlc.
LibGetSFcnTIDType(sfcnTID)
Returns the type of the specified S-function task identifier
(sfcnTID). Possible values are:
"continuous"— The specifiedsfcnTIDis continuous."discrete"— The specifiedsfcnTIDis discrete."triggered"— The specifiedsfcnTIDis triggered."constant"— The specifiedsfcnTIDis constant.
The format of sfcnTID must be the same as for
LibIsSFcnSampleHit.
Note
This is useful primarily in the context of S-functions that specify an inherited sample time.
See LibGetSFcnTIDType in utillib.tlc.
LibGetTaskTime(tid)
Returns a string to access the absolute time of the task, 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. In integer-only code, the task time is an integer time value whose resolution is the model fundamental step size.
If you use this function in a target file for an S-Function block intended for use in models that are configured for timer service interface code generation:
Specify a global task identifier (
tid). TLC library functions that use atidrequire thetidto be global. If you specify the localtid, the code generator might produce incorrect code for the S-Function block. Compute the globaltidby specifyingLibGetGlobalTIDFromLocalSFcnTID(sfcnTID).Configure the S-Function block to use absolute time by calling the
SimStructfunctionssSetNeedAbsoluteTimewith the absolute time Boolean flag set to1.Configure models that use the block to support floating-point numbers (select model configuration parameter Support: floating-point numbers).
LibGetTaskTime is the TLC version of the SimStruct macro:
"ssGetTaskTime(S,tid)".
See LibGetTaskTime in utillib.tlc.
LibGetTaskTimeFromTID(block)
Returns a string to access the absolute time of the task associated with the block.
If the value of the CodeFormat TLC variable is not
Embedded-C, LibGetTaskTimeFromTID returns the string
"RTMGet("T")" if the block is constant or the system is single rate,
and "RTMGetTaskTimeForTID(tid)" otherwise.
If the value for the CodeFormat TLC variable is
Embedded-C, LibGetTaskTimeFromTID returns
"RTMGetTaskTimeForTID(tid)".
If the block is constant or the system is single rate, this is the TLC version of the
SimStruct macro: "ssGetT(S)" and "ssGetTaskTime(S,
tid)" otherwise.
In both cases, S is the name of the SimStruct.
If you use this function in a target file for an S-Function block intended for use in models that are configured for timer service interface code generation:
Configure the S-Function block to use absolute time by calling the
SimStructfunctionssSetNeedAbsoluteTimewith the absolute time Boolean flag set to1.Configure models that use the block to support floating-point numbers (select model configuration parameter Support: floating-point numbers).
Note
Do not use LibGetT as an alternative to
LibGetTaskTimeFromTID. LibGetT reads the base
rate (tid 0) timer. If LibGetT is called for a
block executing at a subrate, the wrong timer is read.
See LibGetTaskTimeFromTID in utillib.tlc.
LibGetTID01EQ()
Returns the value of the TID01EQ flag — true (1) if sampling rates of the continuous task and the first discrete task are equal and false (0) otherwise.
When a model has continuous time and the flag TID01EQ is true, both continuous time and the fastest discrete time are treated as one rate in generated code. The code associated with the fastest discrete rate is guarded by a major time step check. When the model has only two rates, and TID01EQ is true, the generated code has a single-rate call interface.
Use LibGetTID01EQ to detect and account for the case where continuous
time and the fastest discrete time are treated as one rate.
See LibGetTID01EQ in codetemplatelib.tlc, bareboard_mrmain.tlc, and ertmainlib.tlc.
LibIsContinuous(TID)
Returns 1 if the specified task identifier (TID) is continuous and 0
otherwise. Note that task identifiers equal to "triggered" or
"constant" are not continuous.
See LibIsContinuous in utillib.tlc.
LibIsDiscrete(TID)
Returns 1 if the specified task identifier (TID) is discrete and 0
otherwise. Note that task identifiers equal to "triggered" or
"constant" are not discrete.
See LibIsDiscrete in utillib.tlc.
LibIsSFcnSampleHit(sfcnTID)
Returns 1 if a sample hit occurs for the specified local S-function task identifier
(TID) and 0 otherwise.
The input argument to LibIsSFcnSampleHit should be one of the
following:
sfcnTID: integer (e.g., 2)For block-based sample times (e.g., in S-function
mdlInitializeSizes,ssSetNumSampleTimes(S,N)with N > 1 was specified),sfcnTIDis an integer starting at 0 of the corresponding local S-function sample time.sfcnTID:"InputPortIdxorI""OutputPortIdx(e.g.,I""InputPortIdx0").For port-based sample times (e.g., in S-function
mdlInitializeSizes,ssSetNumSampleTimes(S,PORT_BASED_SAMPLE_TIMES)was specified),sfcnTIDis a string giving the input (or output) port index.
Examples
Consider a multirate S-function block with four block sample times. The call
LibIsSFcnSampleHit(2)returns the code to check for a sample hit on the third S-function block sample time.Consider a multirate S-function block with three input and eight output sample times. The call
LibIsSFcnSampleHit("InputPortIdx0")returns the code to check for a sample hit on the first input port. The callLibIsSFcnSampleHit("OutputPortIdx7")returns the code to check for a sample hit on the eighth output port.
See LibIsSFcnSampleHit in utillib.tlc.
LibIsSFcnSingleRate(block)
Returns a Boolean value (1 or 0) indicating whether the S-function is single rate (one sample time) or multirate (multiple sample times).
See LibIsSFcnSingleRate in 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.
LibIsSFcnSpecialSampleHit determines the global TID from the S-function
TID
The input arguments to LibIsSFcnSpecialSampleHit are
For multirate S-function blocks:
sfcnSTI: local S-function sample time index (sti) of the slow task that is to be promotedsfcnTID: local S-function task ID (tid) of the fast task where the slow task is to runFor single-rate S-function blocks using
SS_OPTION_RATE_TRANSITION,sfcnSTIandsfcnTIDare ignored and should be specified as"".
The format of sfcnSTI and sfcnTID must follow that
of the argument to LibIsSFcnSampleHit.
Examples
A rate transition S-function (one sample time with
SS_OPTION_RATE_TRANSITION)if (%<LibIsSFcnSpecialSampleHit("","")>) {A multirate S-function with port-based sample times where the output rate is slower than the input rate (e.g., a zero-order hold operation)
if (%<LibIsSFcnSpecialSampleHit("OutputPortIdx0","InputPortIdx0")>) {
See LibIsSFcnSpecialSampleHit in utillib.tlc.
LibIsSingleRateModel()
Returns true if model is single rate and false
otherwise.
See LibIsSingleRateModel in codetemplatelib.tlc.
LibIsSingleTasking()
Returns true if the model is configured for single-tasking execution
and false if the model is configured for multitasking execution.
See LibIsSingleTasking in codetemplatelib.tlc.
LibIsZOHContinuous(TID)
Returns 1 if the specified task identifier (TID) is zero order hold (ZOH) continuous and
0 otherwise. A TID equal to triggered or constant is
not ZOH continuous.
See LibIsZOHContinuous in utillib.tlc.
LibNumAsynchronousSampleTimes()
Returns the number of asynchronous sample times in the model.
See LibNumAsynchronousSampleTimes in codetemplatelib.tlc.
LibNumDiscreteSampleTimes()
Returns the number of discrete sample times in the model.
See LibNumDiscreteSampleTimes in codetemplatelib.tlc.
LibNumSynchronousSampleTimes()
Returns the number of synchronous sample times in the model.
See LibNumSynchronousSampleTimes in codetemplatelib.tlc.
LibPortBasedSampleTimeBlockIsTriggered(block)
Determines whether the port-based S-function block is triggered.
See LibPortBasedSampleTimeBlockIsTriggered in blocklib.tlc.
LibSetSampleTimeNeedsAbsoluteTime(sampleTimeIdx, value)
Sets whether the sample time at index sampleTimeIdx needs to use
absolute time, based on the argument value.
Arguments
sampleTimeIdx — Specify an integer indicating the index of the
sample time (zero-based).
value — Specify a Boolean value indicating the necessity of
absolute time. Use TLC_TRUE if absolute time is required and
TLC_FALSE if it is not.
Example
% Set the fourth sample time to use absolute time LibSetSampleTimeNeedsAbsoluteTime(3, TLC_TRUE)
See LibSetSampleTimeNeedsAbsoluteTime in utils_api.tlc.
LibSetSampleTimeNeedsFloatTime(sampleTimeIdx, value)
Sets whether the sample time at index sampleTimeIdx needs to use
floating time, based on the argument value.
Arguments
sampleTimeIdx — Specify an integer indicating the index of the
sample time (zero-based).
value — Specify a Boolean value indicating the necessity of floating
time. Use TLC_TRUE if floating time is required and
TLC_FALSE if it is not.
Example
% Set the fourth sample time to use floating time LibSetSampleTimeNeedsFloatTime(3, TLC_TRUE);
See LibSetSampleTimeNeedsFloatTime in utils_api.tlc.
LibSetVarNextHitTime(block, tNext)
Generates code to set the next variable hit time. Blocks with variable sample time must
call LibSetVarNextHitTime in their output functions.
See LibSetVarNextHitTime in blocklib.tlc.
LibTriggeredTID(tid)
Returns whether this TID corresponds to a triggered rate.
See LibTriggeredTID in utillib.tlc.