Real-Time Workshop |
 |
Creating Device Drivers
Device drivers that communicate with target hardware are essential to many real-time development projects. This section describes how to integrate device drivers into your target system. This includes incorporating drivers into your Simulink model and into the code generated from that model.
Device drivers are implemented as Simulink device driver blocks. A device driver block is an S-Function block that is bound to user-written driver code.
To implement device drivers, you should be familiar with the Simulink C MEX S-function format and API. The following documents contain more information about C MEX S-functions:
- Writing S-Functions describes S-functions, including how to write both inlined and noninlined S-functions and how to access parameters from a masked S-function. Writing S-Functions also describes how to use the special
mdlRTW
function to parameterize an inlined S-function.
- External Interfaces/API in the MATLAB online documentation explains how to write C and other programs that interact with MATLAB via the MEX API. The Simulink S-function API is built on top of this API. To pass parameters to your device driver block from MATLAB/Simulink you must use the MEX API. External Interfaces/API Reference in the MATLAB online documentation contains reference descriptions for the required MATLAB
mx*
routines.
- The Target Language Compiler documentation describes the Target Language Compiler. Knowledge of the Target Language Compiler is required in order to inline S-functions. The Target Language Compiler Reference Guide also describes the structure of the
model
.rtw
file.
- "Using Masks to Customize Blocks" in Using Simulink describes how to create a mask for an S-function.
Note
Device driver blocks must be implemented as C MEX S-functions, not as M-file S-functions. C MEX S-functions are limited to a subset of the features available in M-file S-functions. See Limitations of Device Driver Blocks for information.
|
This section covers the following topics:
- Inlined and noninlined device drivers
- General requirements and limitations for device drivers
- Obtaining S-function parameter values from a dialog box
- Writing noninlined device drivers
- Writing inlined device drivers
- Building the device driver MEX-file
| Template Makefiles | | Inlined and Noninlined Drivers |  |