Custom I/O Driver Basics
You can write custom I/O device drivers to work with Simulink® Desktop Real-Time™ applications.
Do not use Analog Input, Analog Output, Digital Input, or Digital Output drivers as starting points for creating custom device drivers.
Supported C Functions
You can use ANSI® C functions that do not use the operating system in your custom blocks or I/O drivers. The following includes a partial list of supported functions:
Console I/O —
printffunction sends output to the MATLAB® Command Window when it is called from the real-time application.
Data conversion —
Memory allocation —
Memory allocation is not an operation that can be done in real time. To work with a Simulink Desktop Real-Time application, memory management must occur before real-time simulation begins. Simulation switches into real time after
mdlStart, so you can allocate memory in
mdlStart. You cannot allocate memory in any function after
mdlStart, such as
Memory manipulation —
Character string manipulation —
Character class tests and conversion —
Searching and sorting —
Dummy functions —
Unsupported C Functions
If you create your own custom I/O driver blocks, use only C functions that Simulink Desktop Real-Time supports. Simulink Desktop Real-Time does not support functions that use the operating system. This category includes functions from vendor-supplied driver libraries for the operating system, which are also not supported.
The following list includes many, but not all, of the unsupported functions:
File I/O —
Console I/O —
Process management —
Signals and exceptions —
Time functions —
Operating system API functions — No operating system API functions, such as Win64 functions, are supported .
Incompatibility with Operating System API Calls
The Simulink Desktop Real-Time kernel intercepts the interrupt from the system clock. It then reprograms the system clock to operate at a higher frequency for running your real-time application. At the original clock frequency, it sends an interrupt to the operating system to allow software that uses the operating system API to run.
As a result, software that uses the operating system API, such as Win64 functions, cannot be executed as a component of your real-time application. Software you use to write I/O drivers must not make calls to the operating system API.
I/O Register Access from S-Functions Limitation
Operating system drivers can access I/O registers only from the real-time kernel and not from the Simulink software. To prevent drivers from attempting to access I/O registers from Simulink S-functions, enter code fragments like the following:
#ifndef MATLAB_MEX_FILE /* we are in real-time kernel, do board I/O */ #else /* we are in Simulink, don't do board I/O */ #endif