Target Language Compiler | ![]() ![]() |
Sample Time Functions
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 (a real number greater than 0. ) |
Continuous |
0.0 |
Triggered |
-1.0 |
Constant |
-2.0 |
See function in matlabroot
/rtw/c/tlc/lib/blocklib.tlc
.
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
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
: string of the form "InputPortIdxI", "OutputPortIdxI"
where I
is a number ranging from 0 to the number of ports (e.g., "InputPortIdx0", "OutputPortIdx7"
). 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
%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] %breaksw %case "triggered" %assign period = -1 %assign offset = -1 %breaksw %case "constant" %assign period = rtInf %assign offset = 0 %breaksw %default %<LibBlockReportFatalError([],"Unknown tid type")> %endswitch
See function in matlabroot
/rtw/c/tlc/lib/utillib.tlc
.
LibGetNumSFcnSampleTimes(block)
Returns the number of S-function sample times for a block.
See function in matlabroot
/rtw/c/tlc/lib/utillib.tlc
.
LibGetSFcnTIDType(sfcnTID)
Returns the type of the specified S-function's task identifier (sfcnTID
).
"continuous"
if the specified sfcnTID
is continuous.
"discrete"
if the specified sfcnTID
is discrete.
The format of sfcnTID
must be the same as for LibIsSFcnSampleHit
.
See function in matlabroot
/rtw/c/tlc/lib/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/lib/utillib.tlc
.
LibIsContinuous(TID)
Returns 1 if the specified task identifier (TID
) is continuous, 0 otherwise. Note, TID
s equal to "triggered"
or "constant"
are not continuous.
See function in matlabroot
/rtw/c/tlc/lib/utillib.tlc
.
LibIsDiscrete(TID)
Returns 1 if the specified 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/lib/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
mdlInitializeSizes
, ssSetNumSampleTimes(S,N)
with N > 1 was specified), sfcnTID
is an integer starting at 0 of the corresponding local S-function sample time.
mdlInitializeSizes
, ssSetNumSampleTimes(S,PORT_BASED_SAMPLE_TIMES)
was specified), sfcnTID
is a string giving the input (or output) port index.
Examples
LibIsSFcnSampleHit(2)
will return the code to check for a sample hit on the third S-function block sample time.
LibIsSFcnSampleHit("InputPortIdx0")
returns the code to check for a sample hit on the first input port. The call LibIsSFcnSampleHit("OutputPortIdx7")
returns the code to check for a sample hit on the eighth output port.
See function in matlabroot
/rtw/c/tlc/lib/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/lib/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 TID
s for both the sample time index (sti
) and the task ID (tid
).
The input arguments to this function are
sfcnSTI
: local S-function sample time index (sti
) of the slow task that is to be promoted
sfcnTID
: local S-function task ID (tid
) of the fast task where the slow task will be run.
SS_OPTION_RATE_TRANSITION
, sfcnSTI
and sfcnTID
are ignored and should be specified as ""
.
The format of sfcnSTI
and sfcnTID
must follow that of the argument to LibIsSFcnSampleHit
.
Examples
SS_OPTION_RATE_TRANSITION
)
See function in matlabroot
/rtw/c/tlc/lib/utillib.tlc
.
LibPortBasedSampleTimeBlockIsTriggered(block)
Determines if the port-based S-function block is triggered.
See function in matlabroot
/rtw/c/tlc/lib/blocklib.tlc
.
LibSetVarNextHitTime(block,tNext)
Generates code to set the next variable hit time. Blocks with variable sample time must call this function in their output functions.
See function in matlabroot
/rtw/c/tlc/lib/blocklib.tlc
.
![]() | Code Configuration Functions | Other Useful Functions | ![]() |