User`s guide

3 Writing S-Functions As C-MEX files
3-42
Multirate S-Function Blocks
Ina multirate S-Function block, you canencapsulate the code that defines each
behavior in the
mdlOutput and mdlUpdate functions with a statement that
determines whether a sample hit has occurred. The
ssIsSampleHit macro
determines whether the current time is a sample hit for a specified sample
time. The macro has this syntax:
ssIsSampleHit(S, st_index, tid)
where S is the SimStruct, st_index identifiesaspecificsampletime index,and
tid is the task ID (tid is an argument to the mdlOutput and mdlUpdate).
For example, these statements specify three sample times: one for continuous
behavior, and two for discrete behavior.
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetSampleTime(S, 1, 0.75);
ssSetSampleTime(S, 2, 1.0);
In the mdlUpdate function,the followingstatement would encapsulate thecode
that defines the behavior for the sample time of 0.75 seconds:
if (ssIsSampleHit(S, 1, tid)) {
}
The second argument, 1, corresponds to the second sample time, 0.75 seconds.
Example - Defining a Sample Time for a Continuous Block. This example defines a
sample time for a block that is continuous in nature.
/* Initialize the sample time and offset. */
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
You must add this statement to the mdlInitializeSizes function:
ssSetNumSampleTimes(S, 1);