The files provided to support custom file processing are:
A TLC function library that implements the code template API.
codetemplatelib.tlc also provides the comprehensive documentation of
the API in the comments headers preceding each function.
An example custom file processing (CFP) template, which you should use as the starting
point for creating your own CFP templates. Guidelines and examples for creating a CFP
template are provided in Generate Source and Header Files with a Custom File Processing (CFP) Template.
TLC files supporting generation of single-rate and multirate main program modules (see Customizing Main Program Module Generation).
Once you have created a CFP template, you must integrate it into the code generation process, using the File customization template edit field. See Specify Templates For Code Generation.
A custom file processing (CFP) template imposes a simple structure on the code generation process. The template, a code generation template (CGT) file, partitions the code generated for each file into a number of sections. These sections are summarized in Built-In CGT Tokens and Corresponding Code Sections and Subsections Defined for Built-In Sections.
Code for each section is assembled in buffers and then emitted, in the order listed, to the file being generated.
To generate a file section, your CFP template must first assemble the code to be generated into a buffer. Then, to emit the section, your template calls the TLC function
LibSetSourceFileSection(fileH, section, tmpBuf)
fileH is a file reference to a file being generated.
section is the code section or subsection to which code is to be
emitted. section must be one of the section or subsection names listed in Subsections Defined for Built-In Sections.
section argument as follows:
If Subsections Defined for Built-In Sections does not define subsections for
a given section, use the section name as the
If Subsections Defined for Built-In Sections defines one or more subsections
for a given section, you can use either the section name or a subsection name as the
If you have defined a custom token denoting a custom section, do not call
LibSetSourceFileSection. Special API calls are provided for
custom sections (see Generate a Custom Section).
tmpBuf is the buffer containing the code to be emitted.
There is no requirement to generate all of the available sections. Your template need only generate the sections you require in a particular file.
Note that legality or syntax checking is not performed on the custom code within each section.
See Generate Source and Header Files with a Custom File Processing (CFP) Template, for typical usage examples.
Embedded Coder® provides an extensible API to augment generated code and to generate additional files. The model configuration parameter File customization template specifies a custom Target Language Compiler (TLC) script that executes at the end of the code generation process. Using this script, you can generate additional code to interface with application code.
In this example, the TLC script file
rtwdemofileprocess.tlc creates an additional entry-point function,
rtwdemo_fileprocess, which calls the step function and initializes the model, if necessary. The initialization function is transparent to the caller.
1. Open the example model
2. Verify the model configuration parameter File customization template is set to
rtwdemofileprocess.tlc by double-clicking the yellow button labeled View Templates Configuration.
3. Generate code.
4. Inspect the generated code. An additional function,
rtwdemo_fileprocess, appears at the end of the generated file
rtwdemo_fileprocess.c. The entry point is declared
rtwdemo_fileprocess.h as the
rtwdemofileprocess.tlc script specifies.