| Real-Time Workshop Embedded Coder | ![]() |
The Static Main Program Module
In most cases, the easiest strategy for deploying your generated code is to use the Generate an example main program option to generate the ert_main.c module (see Generating the Main Program).
However, if you turn the Generate an example main program option off, you can use the module matlabroot/rtw/c/ert/ert_main.c as a template example for developing your 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. If your existing applications, developed prior to this release, depend upon ert_main.c, you may need to continue using this module.
When developing applications using ert_main.c, we recommend that you copy ert_main.c to your working directory and rename it to model_ert_main.c before making modifications. Also, you must modify the template makefile such that the build process will create model_ert_main.obj (on Unix, model_ert_main.o) 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.
In the static version of ert_main.c, the operation of rt_OneStep and the main function are essentially the same as described in Stand-Alone Program Execution.
Modifying the Static Main Program
As in a generated program, a few modifications to the main loop and rt_OneStep are necessary. See Guidelines for Modifying the Main Program and Guidelines for Modifying rt_OneStep.
Also, you should replace the rt_OneStep call in the main loop with a background task call or null statement.
Other modifications you may need to make are
REMOVE in comments (see also the Version 3.0 comments in ert_main.c).
MODEL_SETEVENTS macro (defined in ert_main.c) to set the event flags instead of accessing the flags directly. The relevant code is tagged with the keyword REPLACE in comments.
#include ertformat.h directives. ertformat.h will be obsoleted in a future release. The following macros, formerly defined in ertformat.h, are now defined within ert_main.c:
autobuild.h to provide an interface between the main module and generated model code. If you create your own static main program module, you would normally include autobuild.h.
autobuild.h, and include model.h directly in your main module. To suppress generation of autobuild.h, use the following statement in your system target file:
ert_main.c:
ert_main.c:
MODEL_STEP with calls to MODEL_OUTPUT and MODEL_UPDATE.
#if ONESTEPFCN... error check.
ert_main.c module does not support the Generate Reusable Code option. Use this option only if you are generating a main program. The following error check will raise a compile-time error if Generate Reusable Code is used illegally.
ert_main.c module does not support the External Mode option. Use this option only if you are generating a main program. The following error check will raise a compile-time error if External Mode is used illegally.
| Model Entry Points | Code Generation Options and Optimizations | ![]() |