Target Language Compiler | ![]() ![]() |
Inlining Process
The strategy for achieving compact, high performance code from Simulink blocks in Real-Time Workshop centers on determining what part of a block's operations are active and necessary in the generated code and what parts can be predetermined or left out.
In practice, this means the TLC code in the block target file will select an algorithm that is a subset of the algorithms contained in the S-function itself and then selectively hard-code numerical parameters that are not to be changed at run time. This reduces code memory size and results in code that is often much faster than its S-function counterpart when mode selection is a significant part of S-function processing. Additionally, all function call overhead is eliminated for inlined S-functions as the code is generated directly in the body of the code unless there is an explicit call to a library function in the generated code.
The algorithm selections and parameter set for each block is output in the initial phase of the code generation process from the S-function's registered parameter set or the mdlRTW()
function (if present), which results in entries in the model's .rtw
file for that block at code generation time. A file written in the target language for the block is then called to read the entries in the model
.rtw
file and compute the generated code for this instance of the block. This TLC code is contained in the block target file.
One special case for inlined S-functions is for the case of I/O blocks and drivers such as A/D converters or communications ports. For simulation, the I/O driver is typically coded in the S-function as a pure source, a pass-through, or a pure sink. In the generated code however, an actual interface to the I/O device must be made, typically through direct coding with the common _in()
, _out()
functions, inlined assembly code, or a specific set of I/O library calls unique to the device and target environment.
![]() | Advantages of Inlining S-Functions | Search Algorithm for Locating Target Files | ![]() |