Real-Time Workshop | ![]() ![]() |
Inlined and Noninlined Drivers
In your target system, a device driver has a dual function. First, it functions as a code module that you compile and link with other code generated from your model by Real-Time Workshop. In addition, the driver must interact with Simulink during simulation. To meet both these requirements, you must incorporate your driver code into a Simulink device driver block.
You can build your driver S-function in several ways:
Real-Time Workshop provides standard compilation conditionals and include files to let you build the drivers for both cases. (See Conditional Compilation for Simulink and Real-Time.)
Inlining an S-function can improve its performance significantly. However, there is a tradeoff in increased development and maintenance effort. To inline a device driver block, you must implement the block twice: first, as a C MEX-file, and second, as a TLC program.
The C MEX-file version is for use in simulation. Since a simulation normally does not have access to I/O boards or other target hardware, the C MEX-file version often acts as a "dummy" block within a model. For example, a digital-to-analog converter (DAC) device driver block is often implemented as a stub for simulation.
Alternatively, the C MEX-file version can simulate the behavior of the hardware. For example, an analog-to-digital converter (ADC) device driver block might read sample values from a data file or from the MATLAB workspace.
The TLC version generates actual working code that accesses the target hardware in a production system.
Inlined device drivers are an appropriate design choice when:
Simstruct
. Each Simstruct
uses over 1K of memory. Inlined S-functions do not allocate any Simstruct
. For optimal memory usage, consider using inlined S-functions with the Real-Time Workshop Embedded Coder target.
![]() | Creating Device Drivers | Device Driver Requirements and Limitations | ![]() |