Custom I/O Driver Basics

You can write custom I/O device drivers to work with Real-Time Windows Target™ applications.

    Note:   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 Windows® operating system in your custom blocks or I/O drivers. The following includes a partial list of supported functions:

  • Console I/Oprintf

    The printf function sends output to the MATLAB® Command Window when it is called from the real-time application.

  • Data conversionabs, atof, atoi, atol, itoa, labs, ltoa, strtod, strtol, strtoul, ultoa

  • Memory allocationcalloc, free, malloc

    Memory allocation is not an operation that can be done in real time. To work with a Real-Time Windows Target application, memory management must occur before real-time simulation begins. Simulation switches into real-time after mdlStart, so you can allocate memory in mdlInitializeSizes or mdlStart. You cannot allocate memory in any function after mdlStart, such as mdlOutputs or mdlUpdate.

  • Memory manipulation_memccpy, memcpy, memchr, memcmp, _memicmp, memmove, memset

  • String manipulationstrcat, strchr, strcmp, strcpy, strcspn, _strdup, _stricmp, strlen, _strlwr, strncat, strncmp, strncpy, _strnset, strpbrk, strrchr, _strrev, _strset, strspn, strstr, strtok, strupr

  • Mathematicalacos, asin, atan, atan2, ceil, cos, cosh, div, exp, fabs, floor, fmod, frexp, ldexp, ldiv, log, log10, max, min, modf, pow, rand, sin, sinh, sqrt, srand, tan, tanh, uldiv

  • Character class tests and conversionisalnum, isalpha, _isascii, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit, isxupper, isxlower, _toascii, tolower, toupper

  • Searching and sortingbsearch, qsort

  • Dummy functionsexit, fprintf

Unsupported C Functions

If you create your own custom I/O driver blocks, you should use only C functions supported by Real-Time Windows Target software. Functions that use the Windows operating system are not supported by Real-Time Windows Target. This includes functions from vendor-supplied driver libraries for Windows, which are also not supported.

The following list includes many, but not all, of the unsupported functions:

  • File I/Ofopen, freopen, fclose, fread, fwrite, fputs, fputc, fgets, fgetc, gets, getc, getchar, puts, putc, putchar, fflush, setbuf, setvbuf

  • Console I/Ofprintf, sprintf, vfprintf, vprintf, vsprintf, fscanf, scanf, sscanf

  • Process managementspawn, exit, abort, atexit

  • Signals and exceptionssignal, longimp, raise

  • Time functionsclock, time, difftime, asctime, ctime, difftime, gmtime, localtime, mktime, strftime

  • Win32 API functionsNo Windows API functions are supported.

Incompatibility with Win32 API Calls

The Real-Time Windows Target 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 Windows operating system to allow Windows based applications or any software using the Win32 API to run.

As a result, software that uses the Win32 API 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 Win32 API.

I/O Register Access from S-Functions Limitation

Windows 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 RTWin kernel, do board I/O */
#else
/* we are in Simulink, don't do board I/O */
#endif
Was this topic helpful?