|Real-Time Workshop User's Guide|
This section summarizes the code modules and header files of the Real-Time Workshop Embedded Coder, and describes where to find them.
Generated Code Modules
The Real-Time Workshop creates a build directory in your working directory to store generated source code. The build directory also contains object (
.obj) files, a makefile, and other files created during the code generation process.
The default name of the build directory is
_ert_rtw. The build directory contains the following generated source code modules:
.c defines all entry points to the generated code. These are:
_stepimplements all computations required for one time step of your model.
_initializeinitializes the real-time object. If logging is enabled, it also initializes the logging object.
_terminateperforms any cleanup operations required after your program's main loop has stopped executing. Real-Time Workshop generates
_terminateif you select the Terminate function required code generation option (by default, this option is selected).
A standard way to call these entry points is via the macros
MODEL_TERMINATE. These macros are defined in
/rtw/c/ert/ertformat.h. The following code fragment illustrates their use.
#include "ertformat.h" MODEL_INITIALIZE(1);
export.h defines the real-time object and provides a public interface to the entry points of the model code. See How to Call the Entry Points Directly for an example of how to use this interface.
Note that the Real-Time Workshop Embedded Coder code generation report contains further information about code modules generated during a build. (See Generating a Code Generation Report).
Main Program Module
Real-Time Workshop provides the module
rtw/c/ert/ert_main.c as a template example for developing embedded applications.
ert_main.c is not part of the generated code; it is provided as a basis for your custom modifications, and for use in simulation.
We recommend that you copy
ert_main.c to your working directory and rename it to
_ert_main.c before making modifications. The Build process will create
_ert_main.obj in the build directory.
rt_OneStep, a timer interrupt service routine (ISR).
MODEL_STEPto execute processing for one clock period of the model.
mainfunction. As provided,
mainis useful in simulation only. You must modify
mainfor real-time interrupt-driven execution.
Program Execution contains a detailed discussion of the main module, as well as guidelines for modifying it to meet your requirements.
Utility Header Files
The following support header files are provided in the directory
You can include these header files generically for all models. Inclusion of the header files adds no overhead to the generated code.
Table 9-1 summarizes the Real-Time Workshop Embedded Coder header files.
(Used only if MAT-file logging is enabled)
User-Written Code Modules
Code that you write to interface with generated model code will include a customized main module, 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 Chapter 17, Targeting Real-Time Systems for information.
|Real-Time Object||Program Execution|