Target Language Compiler    

Model.rtw and TLC Overview

The TLC Process

To write TLC code for your S-function, you need to understand the TLC process for code generation. As previously described, Simulink generates a model.rtw file that contains a high level representation of the execution semantics of the block diagram. The model.rtw file is an ASCII file that contains a data structure in the form of a nested set of TLC records. The records are comprised of name/value pairs. The TLC compiler reads the model.rtw file and converts it into an internal representation.

Next, the TLC compiler runs (interprets) the TLC files, starting first with the system target file, i.e., grt.tlc. This is the entry point to all the system TLC files as well as the block files, i.e., other TLC files get included into or generated from the one TLC file passed to TLC on its command line (grt.tlc). As the TLC code in the system and block target files is run, it uses, appends to and modifies the existing name/values and records initially loaded from the model.rtw file.

model.rtw Structure

The structure of the model.rtw file mirrors the block diagram's structure:

The basic structure of model.rtw is

Operating Sequence

For each occurrence of a given block in the model, a corresponding block record exists in the model.rtw file. The system target file TLC code loops through all block records and calls the functions in the corresponding block target file for that block type. For inlined S-functions, it calls the inlining TLC file.

There is a method for getting block specific information (internal block information as apposed to inputs/outputs/parameters/etc.) into the block record in the model.rtw file for a block by using the mdlRTW function in the C-MEX function of the block.

Among other things, the mdlRTW function allows you to write out parameter settings (paramsettings), i.e., unique information pertaining to this block. For parameter settings in the block TLC file, direct accesses to these fields are made from the block TLC code and can be used to affect the generated code as desired.


 Getting Started Inlining S-Function Concepts