3.2.1. Introduction

Simulink provides a mechanism to integrate existing or custom C code with a model, usually with little change to the C code itself. It may be beneficial to mix Simulink and C code for a number of reasons. For instance:

Existing or custom C code can be incorporated into a Simulink model using S-functions. S-functions can be written in MATLAB, C, C++, Ada, or Fortran and except for the MATLAB type function, the rest are compiled as a MEX-function using the MATLAB mex utility. An S-function can be used with Simulink Coder and the code generated by Simulink Coder for S-functions can be customized by writing a Target Language Compiler (TLC) file.

This section explains how to write and integrate a C type S-function into an OpenECU Simulink model (OpenECU does not support C++, Ada or Fortran S-functions, or non-inlined S-functions). S-functions with TLC files, are called inlined S-functions, while S-functions without TLC files are non-inlined. For OpenECU models, a TLC file is required, which improves the efficiency of code generation and helps reduce RAM usage.

Note

See “S-Functions and Code Generation” in MATLAB's help section for more information.