Real-Time Workshop User's Guide    

System Target File Structure

This section is a guide to the structure and contents of a system target file. You may want to refer to the system target files provided with the Real-Time Workshop while reading this section. Most of these files are stored in the target-specific directories under matlabroot/rtw/c. Additional system target files are stored in matlabroot/toolbox/rtw/targets/rtwin/rtwin and matlabroot/toolbox/rtw/targets/xpc/xpc.

Before creating or modifying a system target file, you should acquire a working knowledge of the Target Language Compiler. The Target Language Compiler Reference Guide documents the features and syntax of the language.

Figure 17-2 shows the general structure of a system target file.

Figure 17-2: Structure of a System Target File

Browser Comments

This section is optional. You can place comment lines at the head of the file to identify your system target file to the System Target File Browser. These lines have significance to the browser only. During code generation, the Target Language Compiler treats them as comments.

Note that you must place the browser comments at the head of the file, before any other comments or TLC statements.

The comments contain the following directives:

The following browser information comments are from matlabroot/rtw/c/grt/grt.tlc.

See Adding a Custom Target to the System Target File Browser for further information.

Target Language Compiler Configuration Variables

This section assigns global TLC variables that affect the overall code generation process. The following variables must be assigned:

Target Language Compiler Program Entry Point

The code generation process normally begins with codegenentry.tlc. The system target file invokes codegenentry.tlc as follows.

codegenentry.tlc in turn invokes other TLC files:

To customize the code generation process, you can call the lower-level TLC files explicitly and include your own TLC functions at each stage of the process. See the Target Language Compiler Reference Guide for guidelines.

RTW_OPTIONS Section

The RTW_OPTIONS section (see Figure 17-2) is bounded by the directives:

The first part of the RTW_OPTIONS section defines an array of rtwoptions structures. The rtwoptions structure is discussed in this section.

The second part of the RTW_OPTIONS section defines rtwgensettings, a structure defining the build directory name and other settings for the code generation process. See Build Directory Name for information about rtwgensettings.

The rtwoptions Structure.   The fields of the rtwoptions structure define variables and associated user interface elements to be displayed in the Real-Time Workshop page. Using the rtwoptions structure array, you can customize the Category menu in the Real-Time Workshop page, define the options displayed in each category, and specify how these options are processed.

When the Real-Time Workshop page opens, the rtwoptions structure array is scanned and the listed options are displayed. Each option is represented by an assigned user interface element (check box, edit field, pop-up menu, or pushbutton), which displays the current option value.

The user interface elements can be in an enabled or disabled (grayed-out) state. If the option is enabled, the user can change the option value.

The elements of the rtwoptions structure array are organized into groups that correspond to items in the Category menu in the Real-Time Workshop page. Each group of items begins with a header element of type Category. The default field of a Category header must contain a count of the remaining elements in the category.

The header is followed by options to be displayed on the Real-Time Workshop page. The header in each category is followed by a maximum of seven elements.

Table 17-2 summarizes the fields of the rtwoptions structure.

The following example is excerpted from matlabroot/rtw/c/rtwsfcn/rtwsfcn.tlc, the system target file for the S-Function target. The code defines an rtwoptions structure array of three elements. The default field of the first (header) element is set to 2, indicating the number of elements that follow the header.

The first element adds the RTW S-function code generation options item to the Category menu of the Real-Time Workshop page. The options defined in rtwoptions(2) and rtwoptions(3) display as shown in Figure 17-3.

Figure 17-3: Code Generation Options for S-Function Target

If you want to define more than seven options, you can define multiple Category menu items within a single system target file. For an example, see the Tornado system target file, matlabroot/rtw/c/tornado/tornado.tlc.

For further examples of target-specific rtwoptions definitions, see the system target files in the other target directories under matlabroot/rtw/c.

Note that to verify the syntax of your rtwoptions definitions, you can execute the commands in MATLAB by copying and pasting them to the MATLAB command window.

The following table lists the fields of the rtwoptions structure.

Table 17-2: rtwoptions Structure Fields Summary
Field Name
Description
callback
Name of M-code function to call when value of option changes.
default

Default value of the option (empty if the type is Pushbutton).

enable
Must be on or off. If on, the option is displayed as an enabled item; otherwise, as a disabled item.
makevariable
Template makefile token (if any) associated with option. The makevariable will be expanded during processing of the template makefile. See Template Makefile Tokens.
opencallback
M-code to be executed when dialog opens. The purpose of the code is to synchronize the displayed value of the option with its previous setting. See matlabroot/rtw/c/ert/ert.tlc for an example.
popupstrings

If type is Popup, popupstrings defines the items in the pop-up menu. Items are delimited by the "|" (vertical bar) character. The following example defines the items of the Function management menu used by the GRT and other targets:

    ['None|Function splitting|File ', ...
     'splitting|Function and file splitting']
    
prompt
Label for the option.
tlcvariable
Name of TLC variable associated with the option.
tooltip
Help string displayed when mouse is over the item.
type
Type of element: Checkbox, Edit, Popup, Pushbutton, or Category.

Additional Code Generation Options

Target Language Compiler Variables and Options describes additional code generation variables. For readability, it is recommended that you assign these variables in the Configure RTW code generation settings section of the system target file.

Alternatively, you can append statements of the form

to the System target filename field on the Real-Time Workshop page.

Build Directory Name

The final part of the system target file defines the BuildDirSuffix field of the rtwgensettings structure. The build process appends the BuildDirSuffix string to the model name to form the name of the build directory. For example, if you define BuildDirSuffix as follows

the build directories are named model_mytarget_rtw.

See the Target Language Compiler Reference Manual for further information on the rtwgensettings structure.


 Customizing the Build Process Adding a Custom Target to the System Target File Browser