Update zero-crossing vector
#define MDL_ZERO_CROSSINGS void mdlZeroCrossings(SimStruct *S)
An S-function needs to provide this optional method only if it does zero-crossing detection. Implementing zero-crossing detection typically requires using the zero-crossing and mode work vectors to determine when a zero crossing occurs and how the S-function's outputs should respond to this event. The mdlZeroCrossings method should update the S-function's zero-crossing vector, using ssGetNonsampledZCs.
You can use the optional mdlZeroCrossings routine when your S-function has registered the CONTINUOUS_SAMPLE_TIME and has nonsampled zero crossings (ssGetNumNonsampledZCs(S) > 0). The mdlZeroCrossings routine is used to provide the Simulink® engine with signals that are to be tracked for zero crossings. These are typically
Continuous signals entering the S-function
Internally generated signals that cross zero when a discontinuity would normally occur in mdlOutputs
Thus, the zero-crossing signals are used to locate the discontinuities and end the current time step at the point of the zero crossing. To provide the engine with zero-crossing signals, mdlZeroCrossings updates the ssGetNonsampleZCs(S) vector.