Troubleshoot S-Function Checks
To help you identify and troubleshoot issues with your S-function model and source code, S-function checks use S-function analyzer APIs to help you detect potential S-function issues.
Environment Checks
Environment checks inspect your environment for S-function analyzer APIs. This
check includes the MEX
compiler setup check.
MEX
Setup Check
This check indicated the presence of the MEX
compiler in
the current machine. A default C compiler is included in your MATLAB® installation. To see the supported list of compilers, see Change Default Compiler. You can change the default compiler
by typing mex -setup
at the command line.
Source Code Checks
These checks inspect the source code for S-functions. These checks include the
MEX
compile check and Polyspace®
Code Prover™ check.
MEX
Compile Check
The MEX
compile check uses MEX
compilers
to identify compiler warnings and errors in the S-function source code.
Polyspace Code Prover Check
If you have a Polyspace license, this check uses Polyspace Code Prover to conduct code analysis. See Source Code Verification with Polyspace Code Prover (Polyspace Code Prover) for more information.
S-Function MEX
File Checks
This set of checks inspects the semantics of S-function
MEX
-file.
MdlOutputsModifyContinuousStates
This check indicates that the continuous states of the S-function are modified
in the mdlOutputs
method. Continuous states can only be
modified at a major time step and requires the
ssSetSolverNeedsReset
macro to reset the S-function
solver. Changing the S-function states without resetting the solver can lead to
unexpected results.
MdlUpdateModifyContinuousStates
This check indicates whether the continuous states of the S-function are
modified in the mdlUpdate
method. Continuous states can only
be modified at a major time step and requires the
ssSetSolverNeedsReset
macro to reset the S-function
solver. Changing the S-function states without resetting the solver can lead to
unexpected results.
MinorStepModifyDiscreteStates
This check indicates whether the discrete states of the S-function are
modified in its mdlOutputs
method at a minor step. Discrete
states of an S-function can only be modified at a major step, guarded by
sslsMajorTimeStep
.
MinorStepModifyModes
This check investigates whether the mode vector of the S-function is modified
in the mdlOutputs
at a minor step. Mode step of the
S-function can only be modified at a major time step, guarded by
ssIsMajorTimeStep
function.
GlobalStaticAsInvisibleState
This check indicates whether the S-function is using static or global
variables to represent internal states. To avoid unexpected behavior that
results from having the S-function in multiple S-function blocks, declare the
S-function states explicitly using ssSetNumDiscreteStates
or
using data store memory function APIs.
ContinuousStateWithoutContinuousSampleTime
This check inspects whether the S-function continuous sample time is
explicitly declared when it has continuous states. You can use
ssSetSampleTime
to specify continuous sample time when
S-function has continuous states.
CombinedMdlOutputsMdlUpdateWithDiscreteState
This check inspects whether the S-function mdlUpdate
and
mdlOutputs
methods are combined when the S-function has
discrete states. When the S-function has discrete states, define
mdlUpdate
and mdlOutputs
methods
separately and modify discrete states only in the mdlUpdate
method.
DeclareCanBeConditionalExecWithState
This check inspects whether the S-function sets the
SS_OPTION_CAN_BE_CALLED_CONDITIONALLY
option when it has
state-like data or multiple sample times. This option could cause the
Simulink® engine to move the S-functions into a conditionally executed mode,
such as a conditionally executed subsystem. Remove this option when you have
state-like or multiple sample times.
TestHarnessCreationError
This error code indicates that the S-function analyzer encounters an error
when creating test harness for the input S-functions in a Simulink library. Possible reasons could be a missing
.mex
file or mask parameter definitions.
OperatingPointUnknownWithPWork
This error indicates that the S-function has registered PWork and sets the
operating point compliance as
OPERATING_POINT_COMPLIANCE_UNKNOWN
. This is not
supported. To support Simulink saving and restoring operating points for this
S-function, use USE_CUSTOM_OPERATING_POINT
and provide
mdlGetOperatingPoint
and
mdlSetOperatingPoint
methods.
ModelCompileError
The S-function analyzer encounters error when compiling the input model. You can try to recompile the model and check the diagnostic viewer for more information.
Input Parameter Robustness Check
This check inspects the robustness of S-functions by specifying incompatible number and type of parameters with certain random values. This check could cause MATLAB to crash. To fix this issue, follow the reproduction steps when you relaunch S-function checks and check the S-function parameter data types and values.
See Also
Simulink.sfunction.Analyzer
| Simulink.sfunction.analyzer.BuildInfo
| Simulink.sfunction.analyzer.Options
| findSfunctions