Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

S-Function Guidelines

You implement xPC Target device driver blocks using Simulink S-functions. An S-function is a set of subroutines that implements a function. On the host, you can write an S-function in M-code, C, or Fortran. For xPC Target device drivers, you must write an S-function in C.

Simulink S-functions have a number of callback methods. For xPC Target drivers, you typically need to write C code for the following callback methods:

MethodDescription
mdlInitializeSizesInitializes the S-function with the number of inputs, outputs, states, parameters, and other characteristics.
mdlInitializeSampleTimesInitializes the sample rates of the S-function.
mdlStartInitializes the state vectors of this S-function. It also initializes hardware as necessary.
mdlOutputsComputes the signals that this block emits.
mdlTerminatePerforms any actions required at termination of the simulation.

After you create the S-function, create a mask for it. See Masking Drivers. Also, refer to the Simulink documentation (in particular, Writing S-Functions).

Of particular note when writing S-functions:

See mdlStart and mdlTerminate Considerations for notes on specific applications of the callback methods.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS