User`s guide
Overview of the C MEX S-Function Routines
3-33
either 1 or N.YoucanusessGetInputPortWidth in the routines called during
the simulation loop to determine the actual port width being used.
You canalso specifythat input and/or output signals aredynamicallysized(via
the
DYNAMICALLY_SIZED define). Simulink determines the corresponding
widths when it propagates vector widths throughout your model. You can
influence the vector width propagation via the
mdlSetInputPortWidth and
mdlSetOutputPort width routines. If your S-function doesn’t specify these
routines, then the default scalar expansion rules apply.
The best way to understand the default scalar expansion rules is to consider a
an S-function implementing a sum block with three input ports. The block has
an overall width, called the block width, equal to the width of the output port.
Eachinputport can have a width of 1 or the blockwidthproviding thatat least
one input port has a width equal to the b lock width. Each dynamically sized
work vector will be set to the block width. See
matlabrooot/simulink/src/
sfun_multiport.c
for an example.
If this handling of dynamically sized input and output signals doesn’t meet
your needs, then you need to use the optional routines
mdlSetInputPortWidth
and mdlSetOutputPortWidth.
Note You must correctly specify the number of ports before setting a ny
properties. If you attempt to s et a property of a port that doe sn't exist, you wi ll
be accessing invalid memory and S imulink will crash.
mdlSetInputPortSampleTime
This routine is c al le d wi th the candidate sample time for a n inherited sample
time input p ort . If the propose d s amp le time is acceptable , t he ro utine should
go ahead and set the actual port sample time using
ssSetInputPortSampleTime. I f the s ample time is una ccep ta ble an error
should gene rated via ss Se tErrorStatus. No te th at any o th er inh e rited in p u t or
output ports whose sample times are implicit ly defined by the sample time of
the given port can also have t heir widths set v ia calls t o
ssSetInputPortSampleTime or ssSetOutputPortSampleTime.