| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
| On this page… |
|---|
When to Write Your Own Drivers Restrictions on Customizing xPC Target Drivers |
The xPC Target™ software provides device drivers for a variety of third-party boards. xPC Target users access these drivers as Simulink® blocks from the xPC Target library (xpclib). If you have a board for which the xPC Target software does not supply a driver, you can write your own. This guide provides guidelines for writing custom xPC Target device drivers.
The xPC Target driver library contains drivers that support third-party boards with many I/O capabilities and applications. This includes drivers for different types of I/O boards, including
| Analog-to-digital |
| Digital-to-analog |
| Audio |
| Counters |
| Shared memory |
There are also drivers that support particular protocols, including
| RS-232, RS-422, RS-485 |
| GPIB |
| CAN |
| UDP |
| ARINC 429 |
| MIL-1553 |
Consider writing your own device drivers for the xPC Target block library if:
No xPC Target driver exists for your I/O needs.
You are unable to use a board that the xPC Target software supports.
You need to extend the functionality of an existing xPC Target driver.
The MathWorks xPC Target team will not write a device driver for your board.
The xPC Target software has its own kernel, and you will be writing device drivers aimed at that kernel. An xPC Target driver is therefore different from a driver for another environment, such as Microsoft Windows. The xPC Target kernel is optimized and small, and does not have the operating system layers that traditional kernels do.
The xPC Target software installs its own kernel on the target PC. This kernel runs to the exclusion of any other operating system. When writing your own driver:
You cannot use a driver DLL that accompanies the I/O board from the manufacturer. A manufacturer-supplied DLL will have external dependencies that the xPC Target kernel cannot resolve. The xPC Target executable will not be able to load the DLL.
Do not create your own driver DLL.
If you do not have access to the register programming information, neither you nor The MathWorks can write a device driver for the board. If you have access to the source code of an existing driver for the board, you might be able to port it to the xPC Target kernel.
This guide assumes that you are already knowledgeable about writing device drivers. It describes the steps specific to writing device drivers for the xPC Target environment. To write your own device drivers for the xPC Target system, you need the following background:
Good C programming skills
Knowledge of how Simulink simulation works, for example, the type and order of calls
Knowledge of writing S-functions and compiling those functions as C-MEX functions. This includes a comprehensive knowledge of Simulink callback methods and the Simulink SimStruct functions.
Basic knowledge of Real-Time Workshop
Understanding of I/O hardware. Because of the real-time nature of the xPC Target software, you must develop drivers with minimal latency. Most drivers access the I/O hardware at the lowest possible level (register programming). Therefore, you must understand how to control the board with register information.
Knowledge of port and memory I/O access over various buses. You need this information to access I/O hardware at the register level.
Knowledge of PC hardware fundamentals and internals
This section lists the resources that are available to you from The MathWorks.
The following MathWorks documentation provides information that you can refer to when customizing xPC Target drivers:
| See... | For... |
|---|---|
| Simulink User's Guide | Overall description of the Simulink environment and how the Simulink software performs simulations. |
| MATLAB External Interfaces | How to write MATLAB® MEX-files. |
| Writing S-Functions | How to write MATLAB C-MEX S-functions (noninlined S-functions).
Note the following references in this guide:
|
| Real-Time Workshop Target Language Compiler | How to write target language compiler (TLC) files to inline S-function drivers. This is an optional reference and depends on whether or not you choose to inline your driver. |
| Real-Time Workshop User's Guide | Overall description of Real-Time Workshop fundamentals, and guidelines on understanding I/O boards and low-level programming for drivers for those boards. |
You can alternatively contact the MathWorks Consulting Services Group about the fee-based creation of a driver for your board.
You can examine the source code for existing xPC Target device drivers as a reference for your custom drivers. Refer to the following directory:
matlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks
Note In this directory, you might notice that some drivers use outdated xPC Target driver functions. For the current functions to use, see xPC Target Exported Functions. |
The xPC Target software provides kernel functions that you can use when writing your device drivers. These functions enable you to input and output data, configure PCI devices, and specify time-out intervals. Use only the functions documented in this guide. The guidelines in this document are not applicable if you are using an xPC Target software version prior to xPC Target software version 3.2 (R2007a). See I/O Functions — Alphabetical List, for a description of these functions.
The xPC Target software provides the following directory to help you integrate your custom driver.
matlabroot\toolbox\rtw\targets\xpc\target\build\xpcblocks\thirdpartydrivers
This directory provides template files that you copy and customize for your drivers. Place all files that support your drivers in this directory.
An xPC Target device driver is an S-function with functions that access an I/O board.
Like any device driver, an xPC Target driver interfaces between the user and an I/O device. Unlike typical device drivers, xPC Target device drivers:
Can have the following parts
Driver code, that is C code written as an S-function using exported xPC Target kernel functions (see xPC Target Exported Functions)
Optional Simulink block interface (Simulink mask) that users use to configure the device and access output
Optional M-file code that you can write to perform operations such as cross-block checking or parameter value range checking. You reference this file through the Simulink mask.
Can be included in a Simulink library
Are configured like any other Simulink block
Anatomy of an xPC Target Driver

![]() | Customizing xPC Target Drivers | Before You Start | ![]() |

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 |