Target Language Compiler | ![]() ![]() |
Why Use TLC to Implement S-functions?
When Real-Time Workshop generates code for a model, built-in Simulink blocks are handled differently than user-written blocks (S-functions). Each Simulink block has a corresponding block
.tlc
file that directs TLC how to encode it in a given target language. Such directives do not exist for user-written S-functions.
RTW provides a generic way to invoke user-written algorithms and drivers. Its generic API includes a variety of callback functions -- for initialization, output, derivatives, termination, etc. -- as well as data structures. Once coded, these are instantiated in memory and invoked during execution via indirect function calls. Each invocation involves stack frames and other overhead that adds to execution time.
In a real-time environment, especially when many solution steps are involved, generic API calls can be unacceptably slow. Real-Time Workshop can speed up S-functions in stand-alone applications it generates by embedding user-written algorithms within auto-generated functions rather than indirectly calling S-functions via the generic API. This form of optimization is called inlining.
You should understand that TLC is not a substitute for writing C code S-functions. To invoke custom blocks within Simulink, it is still necessary to code S-functions in C (or as M-files), since Simulink does not make use of TLC files. You can, however, prepare TLC files that inline specified S-functions to make your Real-Time Workshop target code much more efficient.
In the next step, you inline your S-function by removing the SimStruct associated with your S-function (achieving memory savings) and the generic API (speeding up execution).
![]() | Noninlined Code Generation | Creating an Inlined S-Function | ![]() |