S-Functions That Specify Sample Time Inheritance Rules - MATLAB & Simulink (original) (raw)

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 frommdlInitializeSizes 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, usessSetModelReferenceSampleTimeInheritanceRule as indicated in this table.
    If... Use... Example
    None of the macros or functions are present, the S-function does not preclude the model from inheriting a sample time. ssSetModelReferenceSampleTimeInheritanceRule (S, USE_DEFAULT_FOR_DISCRETE_INHERITANCE)
    Any of the macros or functions are used for:Throwing errors if sample time is inherited, continuous, or constantChecking ssIsSampleHitChecking whether sample time is inherited in eithermdlSetInputPortSampleTime ormdlSetOutputPortSampleTime before setting ssSetModelReferenceSampleTimeInheritanceRule... (S,USE_DEFAULT_FOR_DISCRETE_INHERITANCE) Consider this mdlOutputs code:static void mdlOutputs(SimStruct *S, int_T tid) { const real_T *u = (const real_T*)     ssGetInputPortSignal(S,0); 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. ssSetModelReferenceSampleTimeInheritanceRule (S, DISALLOW_SAMPLE_TIME_INHERITANCE) Consider the mdlOutputs code from the S-function examplesfun_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

Note

If an S-function does not set thessSetModelReferenceSampleTimeInheritanceRule 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 > pane to control how the Simulink engine responds when it encounters S-functions that have unspecified sample time inheritance rules. Toggle the diagnostic tonone,warning, or error. The default is warning.

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

See Also

Topics