Target Language Compiler | ![]() ![]() |
Why Wrap?
Many Simulink users want to build models incorporating algorithms that they have already coded in a high level language, implemented, and tested. Typically, such code is brought into Simulink as S-functions. To generate an external application with Real-Time Workshop that integrates user code, you can take several approaches:
The figure below illustrates how S-function wrappers operate.
Wrapping a function eliminates the need to recode it, requiring only a bit of extra TLC code to glue it in place. Wrappers also enable object modules or libraries to be used in S-functions. This may be the only way to deploy functions for which source code is unavailable, and also allows users to distribute models to others without divulging implementation details that may be proprietary.
For example, you might have an existing object file compiled for a TI DSP or for some other processor on which Simulink does not run. You can write a dummy C S-function and use a TLC wrapper that calls the external function, despite not having its source code. You could similarly access functions in a library of algorithms optimized for the target processor. Accomplishing this requires making appropriate changes to a template makefile, or otherwise providing a means to link against the library.
The only restriction on S-function wrappers is that they must use the correct number of block inputs and outputs. Wrapper code may include computations, but usually these are limited to transforming (e.g., scaling or reformatting) values passed to and from the wrapped external functions.
![]() | Wrapping User Code with TLC | Getting Started | ![]() |