Main Content

Custom File Processing (CFP) Templates

The files provided to support custom file processing are:

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.

Custom File Processing (CFP) Template Structure

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)

where

  • 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.

    Determine the section argument as follows:

  • 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.

Generate Additional Files Required to Interface with an Application

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 fileprocess.tlc creates an additional entry-point function, CustomFileProcess, which calls the step function and initializes the model, if necessary. The initialization function is transparent to the caller.

1. Open the example model CustomFileProcess.

open_system('CustomFileProcess');

2. Verify the model configuration parameter File customization template is set to fileprocess.tlc by double-clicking the yellow button labeled View Templates Configuration.

3. Generate code.

4. Inspect the generated code. An additional function, CustomFileProcess, appears at the end of the generated file CustomFileProcess.c. The entry point is declared extern in CustomFileProcess.h as the fileprocess.tlc script specifies.