Main Content

S-Functions That Specify Sample Time Inheritance Rules

For the Simulink® engine to determine whether a model can inherit a sample time from a parent model, the S-functions in the model need to specify how they use sample times. You can specify this information by calling the macro ssSetModelReferenceSampleTimeInheritanceRule from mdlInitializeSizes or mdlSetWorkWidths. To use this macro:

  1. Check whether the S-function calls any of these macros:

  2. Check for these in your S-function TLC code:

    • LibBlockSampleTime

    • CompiledModel.SampleTime

    • LibBlockInputSignalSampleTime

    • LibBlockInputSignalOffsetTime

    • LibBlockOutputSignalSampleTime

    • LibBlockOutputSignalOffsetTime

  3. Depending on your search results, use ssSetModelReferenceSampleTimeInheritanceRule as indicated in this table.

    None of the macros or functions are present, the S-function does not preclude the model from inheriting a sample time.

    Any of the macros or functions are used for:

    • Throwing errors if sample time is inherited, continuous, or constant

    • Checking ssIsSampleHit

    • Checking whether sample time is inherited in either mdlSetInputPortSampleTime or mdlSetOutputPortSampleTime before setting


    Consider this mdlOutputs code:

    static void mdlOutputs(SimStruct *S, int_T tid)
        const real_T *u = (const real_T*) 
        real_T       *y = ssGetOutputPortSignal(S,0);
        y[0] = ssGetSampleTime(S,tid) * u[0];
    The S-function uses its sample time for computing parameters, outputs, and so on.

    Consider the mdlOutputs code from the S-function example sfun_multirate.c:

    static void mdlOutputs(SimStruct *S, int_T tid)
        InputRealPtrsType enablePtrs;
        int               *enabled = ssGetIWork(S);
        int enableTid = ssGetInputPortSampleTimeIndex(S,ENABLE_IPORT);
        int signalTid = ssGetInputPortSampleTimeIndex(S,SIGNAL_IPORT);
        real_T enableTs       = ssGetInputPortSampleTime(S,ENABLE_IPORT);
        real_T enableTsOffset = ssGetInputPortOffsetTime(S,ENABLE_IPORT);
        if (enableTs == CONTINUOUS_SAMPLE_TIME && enableTsOffset == 0.0) {
            if (ssIsMajorTimeStep(S) && ssIsContinuousTask(S,tid)) {
                if (signalTid == enableTid ||
                    ssIsSpecialSampleHit(S, signalTid, enableTid, tid)) {
                    enablePtrs = ssGetInputPortRealSignalPtrs(S,ENABLE_IPORT);
                    *enabled = (*enablePtrs[0] > 0.0);
        } else {
            int enableTid = ssGetInputPortSampleTimeIndex(S,ENABLE_IPORT);
            if (ssIsSampleHit(S, enableTid, tid)) {
                if (enableTid == signalTid || 
                    ssIsSpecialSampleHit(S, signalTid, enableTid, tid)) {
                    enablePtrs = ssGetInputPortRealSignalPtrs(S,ENABLE_IPORT);
                    *enabled = (*enablePtrs[0] > 0.0);
        if (ssIsSampleHit(S, signalTid, tid) && (*enabled)) {
            InputRealPtrsType uPtrs  = ssGetInputPortRealSignalPtrs(S,SIGNAL_IPORT);
            real_T            signal = *uPtrs[0];
            int               i;
            for (i = 0; i < NOUTPUTS; i++) {
                int outTid = ssGetOutputPortSampleTimeIndex(S,i);
                if (outTid==signalTid || 
                    ssIsSpecialSampleHit(S, outTid, signalTid, tid)) {
                    real_T *y = ssGetOutputPortRealSignal(S,i);
                    *y = signal;
    } /* end mdlOutputs */


If an S-function does not set the ssSetModelReferenceSampleTimeInheritanceRule macro, by default the Simulink engine assumes that the S-function does not preclude the model containing that S-function from inheriting a sample time. However, the engine issues a warning indicating that the model includes S-functions for which this macro is not set.

You can use settings in the Configuration Parameters on the Diagnostics > Sample Time pane to control how the Simulink engine responds when it encounters S-functions that have unspecified sample time inheritance rules. Toggle the Unspecified inheritability of sample time diagnostic to none, warning, or error. The default is warning.

For information about Model block sample time inheritance, see Referenced Model Sample Times.

Related Topics