User`s guide
Creating a C ustom Driver
Creating a Custom Driver
The following is a generic procedure for how to create a custom device driver.
For additional note s on writing custom xPC Target drivers, see C hapter 6,
“Custom xPC Target Driver Notes”. For a description of a tool that helps you
create simple custom drivers, see Chapter 7, “Creating C ustom Drivers U sing
the xPC Target Driver Autho ring Tool”. A simple custom device driver is one
which performs no DMA or interrupt handling.
Note You m ight need administrative or write privileges to add a custom
device driver to the x PC Target system. Otherwise, see “Creating Custom
Blocks” in the Simulink User’s Guide.Thistopicdescribeshowtoaddcustom
blocks to a library.
1 Write your driver in C, using the a pproved I/O functions as appropriate
(see Chapter 9, “I/O Structures — A lphabetical List” and Ch apter 11, “I/O
Functions — Alph ab etical List”). An example device driver for the an a log
inputs of the Diamond MM-32 board is available at
matlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks\addiamondmm32.c
2 As y ou write your device driv er, you will w ant to com p ile and li nk the
driver, then test it. Compile and link the driver into a MEX-file. For
example:
mex driver.c
This step creates the MEX-file exe cutable, driver.mexw32.
Note A MEX-file is use d for simulatio n on the host and to set data
structure sizes during code generation. It is n ot used during targ et
execution.
3 CreateafileofMATLABcodetosupplementthemainCdriverandsupport
the block mask. For an example of this file, see
matlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks\diamondmm32.m
1-11