Real-Time Workshop    

Parameterizing Your Driver

You can add a custom icon, dialog box, and initialization commands to an S-Function block by masking it. This provides an easy-to-use graphical user interface for your device driver in the Simulink environment.

You can parameterize your driver by letting the user enter hardware-related variables. Figure 14-7 shows the dialog box of a masked device driver block for an input (ADC) device. The Simulink user can enter the device address, the number of channels, and other operational parameters.

Figure 14-7: Dialog Box for a Masked ADC Driver Block

A masked S-Function block obtains parameter data from its dialog box using macros and functions provided for the purpose.

To obtain a parameter value from the dialog:

  1. Access the parameter from the dialog box using the ssGetSFcnParam macro. The arguments to ssGetSFcnParam are a pointer to the block's Simstruct, and the index (0-based) to the desired parameter. For example, use the following call to access the Number of Channels parameter from the dialog above.
  2. Parameters are stored in arrays of type mxArray, even if there is only a single value. Get a particular value from the input mxArray using the mxGetPr function. The following code fragment extracts the first (and only) element in the Number of Channels parameter.

It is typical for a device driver block to read and validate input parameters in its mdlInitializeSizes function. See the listing adc.c for an example.

By default, S-function parameters are tunable. To make a parameter nontunable, use the ssSetSFcParamNotTunable macro in the mdlInitializeSizes routine. Nontunable S-function parameters become constants in the generated code, improving performance.

For further information on creation and use of masked blocks, see the Using Simulink and Writing S-Functions manuals.


  Device Driver Requirements and Limitations Writing a Noninlined S-Function Device Driver