Real-Time Workshop Embedded Coder    

Code Modules

This section summarizes the code modules and header files that make up a Real-Time Workshop Embedded Coder program, and describes where to find them.

Note that in most cases, the easiest way to locate and examine the generated code files is to use the Real-Time Workshop Embedded Coder code generation report. The code generation report provides a table of hyperlinks that let you view the generated code in the MATLAB Help browser. See Generating a Code Generation Report for further information.

Generated Code Modules

The Real-Time Workshop Embedded Coder creates a build directory in your working directory to store generated source code. The build directory also contains object files, a makefile, and other files created during the code generation process. The default name of the build directory is model_ert_rtw.

Table 2-2 summarizes the structure of source code generated by the Real-Time Workshop Embedded Coder.

Table 2-2: Real-Time Workshop Embedded Coder File Packaging  
File
Description
model.c
Contains entry points for all code implementing the model algorithm (model_step, model_initialize, model_terminate, model_SetEventsForThisBaseStep).
model_private.h
Contains local macros and local data that are required by the model and subsystems. This file is included by the generated source files in the model. You do not need to include model_private.h when interfacing hand-written code to a model.
model.h
Declares model data structures and a public interface to the model entry points and data structures. Also provides an interface to the real-time model data structure (model_rtM) via accessor macros. model.h is included by subsystem .c files in the model.
If you are interfacing your hand-written code to generated code for one or more models, you should include model.h for each model to which you want to interface.
model_data.c
(conditional)

model_data.c is conditionally generated. It contains the declarations for the parameters data structure and the constant block I/O data structure. If these data structures are not used in the model, model_data.c is not generated. Note that these structures are declared extern in model.h.
model_types.h
Provides forward declarations for the real-time model data structure and the parameters data structure. These may be needed by function declarations of reusable functions. model_types.h is included by all the generated header files in the model.
ert_main.c
(optional)
This file is generated only if the Generate an example main program option is on. (This option is on by default). See Generating the Main Program.
autobuild.h
(optional)
This file is generated only if the Generate code only and Generate an example main program options are off. (See Generating the Main Program.)
autobuild.h contains #include directives required by the static version of the ert_main.c main program module. Since the static ert_main.c is not created at code generation time, it includes autobuild.h to access model-specific data structures and entry points.
See The Static Main Program Module for further information.
model_pt.c
(optional)
Provides data structures that enable a running program to access model parameters without use of external mode. To learn how to generate and use the model_pt.c file, see "C API for Parameter Tuning" in the Real-Time Workshop documentation.
model_bio.c
(optional)
Provides data structures that enable your code to access block outputs. To learn how to generate and use the model_bio.c file, see "Signal Monitoring via Block Outputs" in the Real-Time Workshop documentation.

User-Written Code Modules

Code that you write to interface with generated model code usually includes a customized main module (based on a main program provided by the Real-Time Workshop Embedded Coder), and may also include interrupt handlers, device driver blocks and other S-functions, and other supervisory or supporting code.

We recommend that you establish a working directory for your own code modules. Your working directory should be on the MATLAB path. You must also modify the Real-Time Workshop Embedded Coder template makefile and system target file so that the build process can find your source and object files. See Targeting Real-Time Systems in the Real-Time Workshop documentation for information.


  Data Structures and Code Modules Generating the Main Program