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)
.
See LibGetClockTick
in utillib.tlc
.
LibGetClockTickDataTypeId(tid)
Returns clock tick data type ID.
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.
See LibGetClockTickStepSize
in utillib.tlc
.
LibGetElapseTime(system)
Returns time elapsed since the last time the subsystem started to execute.
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. To get real-world elapsed time, this integer elapsed time must be multiplied by the applicable resolution.
You can obtain the resolution by calling
LibGetElapseTimeResolution(system)
. You can obtain the data type ID of
the integer elapsed time counter by calling
LibGetElapseTimeCounterDTypeId(system)
.
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
.
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 > 1
was specified),sfcnTID
is 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),sfcnTID
is a string of the form"InputPortIdx
orI
""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")> %endswitch
See 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
.
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 specifiedsfcnTID
is continuous."discrete"
— The specifiedsfcnTID
is discrete."triggered"
— The specifiedsfcnTID
is triggered."constant"
— The specifiedsfcnTID
is 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.
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.
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),sfcnTID
is an integer starting at 0 of the corresponding local S-function sample time.sfcnTID
:"InputPortIdx
orI
""OutputPortIdx
(e.g.,I
""InputPortIdx0"
).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
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
,sfcnSTI
andsfcnTID
are 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
.
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
.