Real-Time Workshop User's Guide | ![]() ![]() |
Code Modules
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 model
_ert_rtw
. The build directory contains the following generated source code modules:
model
.c
defines all entry points to the generated code. These are:
model
_step
implements all computations required for one time step of your model. model
_initialize
initializes the real-time object. If logging is enabled, it also initializes the logging object.model
_terminate
performs any cleanup operations required after your program's main loop has stopped executing. Real-Time Workshop generates model
_terminate
if 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_STEP
, MODEL_INITIALIZE
, and MODEL_TERMINATE
. These macros are defined in matlabroot
/rtw/c/ert/
ertformat.h. The following code fragment illustrates their use.
#include "ertformat.h" MODEL_INITIALIZE(1);
model_
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.
This header defines parameters and data structures private to model
.c
.
#include "autobuild.h"
#include "
model_
export.h"
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 matlabroot/
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 model
_ert_main.c
before making modifications. The Build process will create model
_ert_main.obj
in the build directory.
rt_OneStep
, a timer interrupt service routine (ISR). rt_OneStep
calls MODEL_STEP
to execute processing for one clock period of the model. main
function. As provided, main
is useful in simulation only. You must modify main
for 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 matlabroot
/rtw/c/ert:
ertformat.h
. 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.
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 | ![]() |