Writing S-Functions    

Writing Callback Methods in Ada

Simulink interacts with an Ada S-function by invoking callback methods that the S-function implements. This section specifies the callback methods that an Ada S-function can implement and provides guidelines for implementing them.

Callbacks Invoked by Simulink

The following diagram shows the callback methods that Simulink invokes when interacting with an Ada S-function during a simulation and the order in which Simulink invokes them.

Implementing Callbacks

Simulink defines in a general way the task of each callback. The S-function is free to perform the task according to the functionality it implements. For example, Simulink specifies that the S-function's mdlOutputs method must compute that block's outputs at the current simulation time. It does not specify what those outputs must be. This callback-based API allows you to create S-functions, and hence custom blocks, that meet your requirements.

S-Function Callback Methods, explains the purpose of each callback and provides guidelines for implementing them. Writing S-Functions in C, provides information on using these callbacks to implement specific S-function features, such as the ability to handle multiple signal data types.

Omitting Optional Callback Methods

The method mdlInitializeSizes is the only callback that an Ada S-function must implement. The source for your Ada S-function needs to include implementations only for callbacks that it must handle. If the source for your S-function does not include an implementation for a particular callback, the mex tool that builds the S-function (see Building an Ada S-Function) provides a stub implementation.

SimStruct Functions

Simulink provides a set of functions that enable an Ada S-function to access the internal data structure (SimStruct) that Simulink maintains for the S-function. These functions consist of Ada wrappers around the SimStruct macros used to access the SimStruct from a C S-function (see SimStruct Functions). Simulink provides Ada wrappers for a substantial subset of the SimStruct macros. The "Languages Supported" section of the reference page for a macro specifies whether it has an Ada wrapper.


  Ada S-Function Body Building an Ada S-Function