S-functions can be used in Simulink Desktop Real-Time (SLDRT) External Mode only if they are self-contained, i.e. they do not call anything but a limited subset of the standard C library, like math and string functions, but not file or console I/O, or Windows API functions (manifested by the need to #include <windows.h>).
Note that being able to run an S-function with other targets (such as grt.tlc, ert.tlc or slrt.tlc) is not a proof that it will run with sldrt.tlc. For example, S-functions that are linked with dynamically linked libraries (DLLs) on Windows generally do not run with SLDRT because DLLs are not available to the real-time kernel.
In particular, the following functions are not supported in the C source code:
- File I/O (fopen etc.)
- Process management (spawn, exit, etc.)
- Signals and exceptions (signal, longjmp, __try etc.)
- Time functions (clock etc.)
- anything from the Windows API
The following C library functions are supported for use with Simulink Desktop Real-Time:
- Data conversion functions: abs atof atoi atol itoa labs ltoa strtod strtol strtoul ultoa
- Memory allocation functions: calloc free malloc
- Memory manipulation functions: _memccpy memcpy memchr memcmp _memicmp memmove memset
- String manipulation functions: strcat strchr strcmp strcpy strcspn _strdup _stricmp strlen _strlwr strncat strncmp strncpy _strnset strpbrk strrchr _strrev _strset strspn strstr strtok _strupr
- Mathematical functions: acos 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 conversion: isalnum isalpha _isascii iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit isxupper isxlower _toascii tolower toupper
- Searching and sorting: bsearch qsort
- Dummy functions - can be there but do nothing: exit
- Console I/O: fprintf printf
This information is currently not part of the Simulink Desktop Real-Time documentation. However, we submitted an internal request to add this list of functions to a future release of the documentation.
Note that the above limitation do not apply for Normal or Accelerator Mode real-time simulations. To learn more about the different SLDRT simulation modes, see the following MATLAB Answers article: