Download Writing S-Functions

Transcript
3
Writing S-Functions in C
An S-function’s mdlInitializeSizes routine sets the sizes of the various
signals and vectors. S-function methods called during the simulation loop can
determine the sizes and values of the signals.
An S-function method can access input signals in two ways:
• Via pointers
• Using contiguous inputs
Accessing Signals Using Pointers
During the simulation loop, accessing the input signals is performed using
InputRealPtrs uPtrs = ssGetInputPortRealSignalPtrs(S,portIndex)
This is an array of pointers, where portIndex starts at 0. There is one for each
input port. To access an element of this signal you must use
*uPtrs[element]
as described by this figure.
Input 1
Input 2
S-function
Block
To Access Input 1:
InputRealPtrs uPtrs0 = ssGetInputPortRealSignalPtrs(S,0)
...
uPtrs0
To Access Input 2:
InputRealPtrs uPtrs1 = ssGetInputPortRealSignalPtrs(S,1)
...
...
uPtrs1
Block I/O
Vector
3-18