What is .TLC (Target Language Compiler) and MEX file in Matlab Simulink

TLC (Target Language Compiler) files are used to customize the code building process. They generally come in two varieties
  1. System/model tlc files that help in the overall model conversion process
  2. Block level tlc files which describe how individual blocks (typically S-Functions) get converted to C code.

Target Language Compiler (TLC) is an integral part of the code generator. Use TLC to customize generated code. Through customization, you can produce platform-specific code and incorporate your own algorithmic changes for performance, code size, or compatibility with existing methods.
With the Target Language Compiler, you can :
  • 1. Customize the set of options specified by your system target file.
  • 2. Inline the code for S-Function blocks.
  • 3. Generate additional or different types of files.




The Target Language Compiler™ is a tool that is included with Real-Time Workshop® (RTW) and enables you to customize the C code generated from any Simulink® model.
Through customization, you can produce platform-specific code or incorporate algorithmic changes for performance, code size, or compatibility with existing methods that you prefer to maintain.

The Target Language Compiler is used to transform an intermediate form of a Simulink block diagram, called model.rtw, into C code. The Compiler generates its code based on “target files,” which specify particular code for each block, and “model-wide files,” which specify the overall code style. The Compiler works like a text processor, using the target files and the model.rtw file to generate ANSI C code





When generating code from a Simulink model using Real-Time Workshop, the first step in the automated process is to generate a model.rtw file. The model.rtw file includes all of the model-specific information required for generating code from the Simulink model. model.rtw is passed to the Target Language Compiler, which uses the model.rtw file in combination with a set of included target files to generate the body source C code (model.c), a header file (model.h), a model registration include file (model.reg) that registers the model’s SimStruct, and a parameter include file (model.prm) that contains information about all the parameters contained in the model.



http://users.isr.ist.utl.pt/~alex/micd0405/rtw_getting_started.pdf

The TLC scripts specify how to generate code from the model, using the model.rtw file as input. The TLC
1. Reads the model.rtw file.
2. Compiles and executes commands in a system target file. The system target file is the entry point or main file. You select it from those available on the MATLAB path with the System target file browser or you can type the name of any such file on your system prior to building.
3. Compiles and executes commands in block target files. For each block in a Simulink model, there is a block target file that specifies how to translate that block into target-specific code.
4. Writes a source code version of the Simulink block diagram




========================================
MEX file is a type of computer file that provides an interface between MATLAB or Octave and functions written in CC++ or Fortran. It stands for "MATLAB executable"

You can call your own C or C++ programs from the MATLAB command line as if they were built-in functions. These programs are called MEX functions and the function name is the MEX file name. MEX functions are not appropriate for all applications. MATLAB is a high-productivity environment whose specialty is eliminating time-consuming, low-level programming in compiled languages. In general, do your programming in MATLAB. Do not use MEX functions unless your application requires it.

http://cs.smith.edu/~nhowe/370/Assign/mexfiles.html

Matlab provides library functions for a number of important operations, and many additional tasks may be accomplished by writing m-files from scratch. But there are certain tasks that cannot be accomplished efficiently using the resources available within Matlab itself. To address such cases, Matlab provides an interface to allow code written in other languages (Fortran, C, & Java) to be called from the Matlab environment. Programs written for this interface must accept internal Matlab data structures as input, and produce similar structures as output. They may then be compiled and called from the Matlab environment just like any other function.

A MEX file is a function, created in MATLAB, that calls a C/C++ program or a Fortran subroutine. A MEX function behaves just like a MATLAB script or function.
To call a MEX function, use the name of the MEX file, without the file extension. The MEX file contains only one function or subroutine. The calling syntax depends on the input and output arguments defined by the MEX function. The MEX file must be on your MATLAB path.
While MATLAB scripts and functions have platform-independent extensions .m and .mlx, MEX functions have these platform-specific extensions.
MEX File Platform-Dependent Extension
PlatformBinary MEX File Extension
Linux® (64-bit)
mexa64
Apple Mac (64-bit)
mexmaci64
Windows® (64-bit)
mexw64
https://pages.cs.wisc.edu/~ferris/cs733/Seminarium_CBA_ht07_MATLAB_MEX_handouts.pdf




Comments

Popular posts from this blog

Simulink & Matlab Interview Question and Answers For Automotive , Aerospace etc.

Real World Value Vs Stored Integer In Simulink ( Fixed Point Number Debunked )