ss GetPort Based Sample Time BlockIs Triggered 10-106 ss GetPWork ....10-107 ssGetPWork value 10-108 ssGetRealDiscStates 10-109 ss Getrootss 10-110 ssGet Run TimeParamInfo 10-111 ss GetRWork .....10-112 ssGetRWorkvalue 10-11 ssGetSampleTimeOffset 10-114 ss GetSampleTime Period 10-115 ssGetSFcn Param 10-1 ss GetSFcn Params Count ....10-117 ssGetsim Mode 10-118 ssGetSolver Mode 10-119 ssGetSolverName 10-120 ssGetStateAbsTol 10-121 ss GetStop requested 1012 ss GettaskTime 10-124 ssGetTFinal 10-125 ss GetTExt 10-1 ss GetTstart .....10-127 ssGetUserData 10-128 ssIs Continuous task Is FirstInitcond 10-130 ssIsMajor Step 10-131 ssIsMinorTimeStep 10-132 sSampleHit 10-13 ssIs SpecialSampleHit .......,,,......,.10-134 is variable Step Solve 10-135 ssPrintf 10-136 ssRegDIgParamAsRunTimeParam 10137 ssRegAllTunableParamsAsRunTimeParams 10-138 ssRegisterDataType 10-139 ss SampleAndOffset Are Triggered 10-140 ssSetBlock Reduction 10-141 ss SetCallSystemOutput 10-142 ssSetData Type Size 10-143 ss SetDataTypeZere ...........10-144 sSetD Work ComplexSignal 10-146
x Contents ssGetPortBasedSampleTimeBlockIsTriggered . . . . . . . . . . 10-106 ssGetPWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-107 ssGetPWorkValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-108 ssGetRealDiscStates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-109 ssGetRootSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-110 ssGetRunTimeParamInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-111 ssGetRWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-112 ssGetRWorkValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-113 ssGetSampleTimeOffset . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-114 ssGetSampleTimePeriod . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-115 ssGetSFcnParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-116 ssGetSFcnParamsCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-117 ssGetSimMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-118 ssGetSolverMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-119 ssGetSolverName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-120 ssGetStateAbsTol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-121 ssGetStopRequested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-122 ssGetT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-123 ssGetTaskTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-124 ssGetTFinal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-125 ssGetTNext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-126 ssGetTStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-127 ssGetUserData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-128 ssIsContinuousTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-129 ssIsFirstInitCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-130 ssIsMajorTimeStep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-131 ssIsMinorTimeStep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-132 ssIsSampleHit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-133 ssIsSpecialSampleHit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-134 ssIsVariableStepSolver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-135 ssPrintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-136 ssRegDlgParamAsRunTimeParam . . . . . . . . . . . . . . . . . . . . 10-137 ssRegAllTunableParamsAsRunTimeParams . . . . . . . . . . . . 10-138 ssRegisterDataType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-139 ssSampleAndOffsetAreTriggered . . . . . . . . . . . . . . . . . . . . . 10-140 ssSetBlockReduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-141 ssSetCallSystemOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-142 ssSetDataTypeSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-143 ssSetDataTypeZero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-144 ssSetDWorkComplexSignal . . . . . . . . . . . . . . . . . . . . . . . . . . 10-146
s SetD WorkDataTy 10-147 ss SetD WorkName 10-148 ssSetDWorkrtWidentifier 10-149 ssSetDWorkRTWStorage Class 10-150 tDWorkRTWType Qualifie ssSetDWork UsedAs DState 10-152 ss SetDWork width 10-153 10-154 ssSetExternalModeFen 10-155 ssSetInputPortDataTy 10-157 ssSetInputPortDimensionInfo 10-158 ss SetInputPort FeedThrough 10-160 ssSetInputPortFrameData 10-161 ssSetInputPortMatrixDimensions 10-1 ssSetInputPortOffsetTime 10-1 ss SetInput PortOver Writable 10-164 ss SetInput Port Required Contiguous 10-165 ss SetInputPortReusable 10-166 ss SetInput Port SampleTime 10-168 ss SetInputPortSampleTimeIndex 10-169 ssSetInputPort VectorDimension 10-170 ssSetInputPortWidth 10-171 ssSetIwork value 10-1 ssSetMode vectorValue 10-173 ssSetNum Contstates 10-174 ss SetNumDiscstates 10-175 ss SetNumDWork 10-176 ss SetNumInputPorts 10=177 ss SetNumIWork 10-178 ss SetNumModes 10-179 ss SetNumNonsampledZCs 10-180 ssSetNumOutputPorts 10-181 ssSetNumPWork 10-182 ssSetNumRunTimeParams 10-183 10-184 ssSetNumSampleTimes 10-185 ssSetNumSFcnParams 10-186 ss SetoffsetTime 10-187 sSetOptions 10-188
xi ssSetDWorkDataType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-147 ssSetDWorkName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-148 ssSetDWorkRTWIdentifier . . . . . . . . . . . . . . . . . . . . . . . . . . 10-149 ssSetDWorkRTWStorageClass . . . . . . . . . . . . . . . . . . . . . . . 10-150 ssSetDWorkRTWTypeQualifier . . . . . . . . . . . . . . . . . . . . . . 10-151 ssSetDWorkUsedAsDState . . . . . . . . . . . . . . . . . . . . . . . . . . 10-152 ssSetDWorkWidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-153 ssSetErrorStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-154 ssSetExternalModeFcn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-155 ssSetInputPortComplexSignal . . . . . . . . . . . . . . . . . . . . . . . 10-156 ssSetInputPortDataType . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-157 ssSetInputPortDimensionInfo . . . . . . . . . . . . . . . . . . . . . . . . 10-158 ssSetInputPortDirectFeedThrough . . . . . . . . . . . . . . . . . . . . 10-160 ssSetInputPortFrameData . . . . . . . . . . . . . . . . . . . . . . . . . . 10-161 ssSetInputPortMatrixDimensions . . . . . . . . . . . . . . . . . . . . 10-162 ssSetInputPortOffsetTime . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-163 ssSetInputPortOverWritable . . . . . . . . . . . . . . . . . . . . . . . . . 10-164 ssSetInputPortRequiredContiguous . . . . . . . . . . . . . . . . . . . 10-165 ssSetInputPortReusable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-166 ssSetInputPortSampleTime . . . . . . . . . . . . . . . . . . . . . . . . . 10-168 ssSetInputPortSampleTimeIndex . . . . . . . . . . . . . . . . . . . . . 10-169 ssSetInputPortVectorDimension . . . . . . . . . . . . . . . . . . . . . . 10-170 ssSetInputPortWidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-171 ssSetIWorkValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-172 ssSetModeVectorValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-173 ssSetNumContStates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-174 ssSetNumDiscStates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-175 ssSetNumDWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-176 ssSetNumInputPorts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-177 ssSetNumIWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-178 ssSetNumModes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-179 ssSetNumNonsampledZCs . . . . . . . . . . . . . . . . . . . . . . . . . . 10-180 ssSetNumOutputPorts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-181 ssSetNumPWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-182 ssSetNumRunTimeParams . . . . . . . . . . . . . . . . . . . . . . . . . . 10-183 ssSetNumRWork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-184 ssSetNumSampleTimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-185 ssSetNumSFcnParams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-186 ssSetOffsetTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-187 ssSetOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-188
ss SetOutput Port Complex Signal 10-192 ssSetOutputPortDataType 10-193 ssSetOutput PortDimensionInfo 10-194 ssSetOutputPortFrame Data 10-195 ssSetOutput PortMatrixDimensions 10-196 ssSetOutputPortOffsetTime 10-197 ss SetOutput Port reusable 10-198 ss SetOutput Port SampleTime 10-200 ssSetOutputPort Vector Dimension 10-201 ssSetOutput width ssSetParameterName 10203 ss Set ParameterTunable 10204 ssSetPlacementGroup 10-205 ssSetPWork value 10-206 ss value 10207 ssSetRunTimeParamInfo 10208 ssSetSampleTime... 10-211 ss SetsFcn Param NotTunable 10-212 ss SetsFcnParamTunable 10213 ssSetSolver Needs Reset 10214 ssSetstop Requested 10216 ss SetTNext 10217 ss SetUserData 10218 ss Setvector Mode UpdateAllTunableParamsAsRunTimeParams 10-220 ssUpdateRunTime ParamData 10221 ssUpdateDIgParamAsRunTimeParam 10-222 ssUpdateRunTimeParamInfo sWa 10-224 ssWritertw2dMatParam 10-225 ss WritertWMx2dMatParan 10226 ssWriteRTWMxVect Param 10227 ssWritertWParameters ss WriteRTWParam Settings s WriterTwScalarParam 10-236 ss WritertwStr 10-237 ssWritertwStrParam 10238 ssWritertwStrVect Param 10-239 ssWritertWVectParam 10-240 WritertwWork vect 10241
xii Contents ssSetOutputPortComplexSignal . . . . . . . . . . . . . . . . . . . . . . 10-192 ssSetOutputPortDataType . . . . . . . . . . . . . . . . . . . . . . . . . . 10-193 ssSetOutputPortDimensionInfo . . . . . . . . . . . . . . . . . . . . . . 10-194 ssSetOutputPortFrameData . . . . . . . . . . . . . . . . . . . . . . . . . 10-195 ssSetOutputPortMatrixDimensions . . . . . . . . . . . . . . . . . . . 10-196 ssSetOutputPortOffsetTime . . . . . . . . . . . . . . . . . . . . . . . . . 10-197 ssSetOutputPortReusable . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-198 ssSetOutputPortSampleTime . . . . . . . . . . . . . . . . . . . . . . . . 10-200 ssSetOutputPortVectorDimension . . . . . . . . . . . . . . . . . . . . 10-201 ssSetOutputPortWidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-202 ssSetParameterName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-203 ssSetParameterTunable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-204 ssSetPlacementGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-205 ssSetPWorkValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-206 ssSetRWorkValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-207 ssSetRunTimeParamInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-208 ssSetSampleTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-211 ssSetSFcnParamNotTunable . . . . . . . . . . . . . . . . . . . . . . . . 10-212 ssSetSFcnParamTunable . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-213 ssSetSolverNeedsReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-214 ssSetStopRequested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-216 ssSetTNext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-217 ssSetUserData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-218 ssSetVectorMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-219 ssUpdateAllTunableParamsAsRunTimeParams . . . . . . . . . 10-220 ssUpdateRunTimeParamData . . . . . . . . . . . . . . . . . . . . . . . 10-221 ssUpdateDlgParamAsRunTimeParam . . . . . . . . . . . . . . . . . 10-222 ssUpdateRunTimeParamInfo . . . . . . . . . . . . . . . . . . . . . . . . 10-223 ssWarning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-224 ssWriteRTW2dMatParam . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-225 ssWriteRTWMx2dMatParam . . . . . . . . . . . . . . . . . . . . . . . . 10-226 ssWriteRTWMxVectParam . . . . . . . . . . . . . . . . . . . . . . . . . . 10-227 ssWriteRTWParameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-228 ssWriteRTWParamSettings . . . . . . . . . . . . . . . . . . . . . . . . . 10-232 ssWriteRTWScalarParam . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-236 ssWriteRTWStr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-237 ssWriteRTWStrParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-238 ssWriteRTWStrVectParam . . . . . . . . . . . . . . . . . . . . . . . . . . 10-239 ssWriteRTWVectParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-240 ssWriteRTWWorkVect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-241
Overview of s-Functions S-functions(system-functions) provide a powerful mechanism for extending the capabilities of Simulink The following sections explain what an S-function is and when and why you might use one and how to write your own S-functions What Is an S-Function?(p. 1-2) Brief overview of s-functions Using S-Functions in Models(p 1-3) How to insert S-functions as blocks in a model and pass parameters to them How S-Functions Work(p 1-6) How Simulink invokes S-functions when simulating a model that includes them Implementing S-Functions(p. 1-10) How to write S-functions S-Function Concepts(p. 1-13) Some key concepts needed to write certain types of S-functions S-Function Examples(p. 1-18) Examples that illustrate the creation of various types of S-functions and s-function features
1 Overview of S-Functions S-functions (system-functions) provide a powerful mechanism for extending the capabilities of Simulink®. The following sections explain what an S-function is and when and why you might use one and how to write your own S-functions. What Is an S-Function? (p. 1-2) Brief overview of S-functions. Using S-Functions in Models (p. 1-3) How to insert S-functions as blocks in a model and pass parameters to them. How S-Functions Work (p. 1-6) How Simulink invokes S-functions when simulating a model that includes them. Implementing S-Functions (p. 1-10) How to write S-functions. S-Function Concepts (p. 1-13) Some key concepts needed to write certain types of S-functions. S-Function Examples (p. 1-18) Examples that illustrate the creation of various types of S-functions and S-function features
1 Overview of s-functions What is an s-Function? An S-function is a computer language description of a Simulink block S-functions can be written in MATLAB. C. C++. Ada or Fortran. C. C++.Ada and Fortran S-functions are compiled as MEX-files using the mex utility(see Building MEX-Files"in the online matlaB documentation). As with other MEX-files, they are dynamically linked into MATLAB when needed S-functions use a special calling syntax that enables you to interact with Simulink's equation solvers. This interaction is very similar to the interaction that takes place between the solvers and built-in Simulink blocks. The form of an S-function is very general and can accommodate continuous, discrete and hybrid systems S-functions allow you to add your own blocks to Simulink models. You can create your blocks in MATLAB, C, C++, Fortran, or Ada. By following a set of simple rules, you can implement your algorithms in an S-function. After you write your S-function and place its name in an S-Function block(available in he Functions Tables block library), you can customize the user interface by using masking You can use S-functions with the Real-Time Workshop. You can also customize the code generated by the real Time Workshop for S-functions by writing a Target Language CompilerTM(tlC)file. See"Writing S-Functions for Real-Time Workshop"on page 8-1 and the Real-Time Workshop documentation for more information
1 Overview of S-Functions 1-2 What Is an S-Function? An S-function is a computer language description of a Simulink block. S-functions can be written in MATLAB, C, C++, Ada, or Fortran. C, C++, Ada, and Fortran S-functions are compiled as MEX-files using the mex utility (see “Building MEX-Files” in the online MATLAB documentation). As with other MEX-files, they are dynamically linked into MATLAB when needed. S-functions use a special calling syntax that enables you to interact with Simulink’s equation solvers. This interaction is very similar to the interaction that takes place between the solvers and built-in Simulink blocks. The form of an S-function is very general and can accommodate continuous, discrete, and hybrid systems. S-functions allow you to add your own blocks to Simulink models. You can create your blocks in MATLAB®, C, C++, Fortran, or Ada. By following a set of simple rules, you can implement your algorithms in an S-function. After you write your S-function and place its name in an S-Function block (available in the Functions & Tables block library), you can customize the user interface by using masking. You can use S-functions with the Real-Time Workshop®. You can also customize the code generated by the Real Time Workshop for S-functions by writing a Target Language CompilerTM (TLC) file. See “Writing S-Functions for Real-Time Workshop” on page 8-1 and the Real-Time Workshop documentation for more information