| Real-Time Workshop® | ![]() |
| On this page… |
|---|
The Embedded-C code format corresponds to the Real-Time Workshop Embedded Coder target (ERT), and targets derived from ERT. This code format includes a number of memory-saving and performance optimizations. See the Real-Time Workshop Embedded Coder documentation for details.
The Embedded-C format uses the real-time model (RT_MODEL) data structure. This structure is also referred to as the rtModel data structure. You can access rtModel data by using a set of macros analogous to the ssSetxxx and ssGetxxx macros that S-functions use to access SimStruct data, including noninlined S-functions compiled by the Real-Time Workshop code generator, and are documented in the Writing S-Functions documentation.
You need to use the set of macros rtmGetxxx and rtmSetxxx to access the real-time model data structure, which is specific to the Real-Time Workshop product. The rtModel is an optimized data structure that replaces SimStruct as the top level data structure for a model. The rtmGetxxx and rtmSetxxx macros are used in the generated code as well as from the main.c or main.cpp module. If you are customizing main.c or main.cpp (either a static file or a generated file), you need to use rtmGetxxx and rtmSetxxx instead of the ssSetxxx and ssGetxxx macros.
Usage of rtmGetxxx and rtmSetxxx macros is the same as for the ssSetxxx and ssGetxxx versions, except that you replace SimStruct S by real-time model data structure rtM. The following table lists rtmGetxxx and rtmSetxxx macros that are used in grt_main.c, grt_main.cpp, grt_malloc_main.c, and grt_malloc_main.cpp.
Macros for Accessing the Real-Time Model Data Structure
rtm Macro Syntax | Description |
|---|---|
Get the derivatives of a block's continuous states | |
Return the pointer of vector that store all sample time offset of the model associated with rtM | |
Get the number of sample times that a block has | |
Return a pointer of NumSampleTime × NumSampleTime matrix | |
Return an external mode information data structure of the model. This data structure is used internally for external mode. | |
Return a data structure used by Real-Time Workshop logging. Internal use. | |
Return a data structure of Real-Time Workshop real-time model methods information. Internal use. | |
Return data structure containing solver information of the model. Internal use. | |
Return a pointer of Sample Hit flag vector | |
Get a task's sample time | |
Get pointer to a task's sample time | |
Get pointer to a task's ID | |
Return simulation step type ID (MINOR_TIME_STEP, MAJOR_TIME_STEP) | |
Return the fundamental step size of the model | |
Get the current simulation time | |
Set the time of the next sample hit | |
Get the current time for the current task | |
Get the simulation stop time | |
Set the simulation stop time | |
Return a data structure used by timing engine of the model. Internal use. | |
Return a pointer of the current time | |
Get the simulation start time | |
Determine whether a task is continuous | |
Determine whether the simulation is in a major step | |
Determine whether the sample time is hit |
For additional details on usage, see SimStruct Functions — Alphabetical List in the Writing S-Functions documentation.
If you have developed a GRT-based custom target, it is simple to make your target ERT compatible. By doing so, you can take advantage of many efficiencies.
There are several approaches to ERT compatibility:
If your installation does not include a Real-Time Workshop Embedded Coder license, you can convert a GRT-based target as described in Converting Your Target to Use rtModel. This enables your custom target to support all current GRT features, including back end Embedded-C code generation.
You can create an ERT-based target, but continue to use your customized version of the grt_main.c or grt_main.cpp module. To do this, you can configure the ERT target to generate a GRT-compatible calling interface, as described in Generating GRT Wrapper Code from the ERT target. This lets your target support the full ERT feature set, without changing your GRT-based run-time interface. This approach requires that your installation has a Real-Time Workshop Embedded Coder license.
If your installation includes a Real-Time Workshop Embedded Coder license, you can reimplement your custom target as a completely ERT-based target, including use of an ERT generated main program. This approach lets your target support the full ERT feature set, without the overhead caused by wrapper calls.
Note If you intend to use custom storage classes (CSCs) with a custom target, you must use an ERT-based target. See Using Custom Storage Classes in the Real-Time Workshop Embedded Coder documentation for detailed information on CSCs. |
For details on how GRT targets are made call-compatible with previous Real-Time Workshop product versions, see The Real-Time Model Data Structure.
The real-time model data structure (rtModel) encapsulates model-specific information in a much more compact form than the SimStruct. Many ERT-related efficiencies depend on generation of rtModel rather than SimStruct, including
Integer absolute and elapsed timing services
Independent timers for asynchronous tasks
Generation of improved C API code for signal and parameter monitoring
Pruning the data structure to minimize its size (ERT-derived targets only)
To take advantage of such efficiencies, you must update your GRT-based target to use the rtModel (unless you already did so for Release 13). The conversion requires changes to your system target file, template makefile, and main program module.
The following changes to the system target file and template makefile are required to use rtModel instead of SimStruct:
In the system target file, add the following global variable assignment:
%assign GenRTModel = TLC_TRUE
In the template makefile, define the symbol USE_RTMODEL. See one of the GRT template makefiles for an example.
The following changes to your main program module (that is, your customized version of grt_main.c or grt_main.cpp) are required to use rtModel instead of SimStruct:
Include rtmodel.h instead of simstruc.h.
Since the rtModel data structure has a type that includes the model name, define the following macros at the top of the main program file:
#define EXPAND_CONCAT(name1,name2) name1 ## name2 #define CONCAT(name1,name2) EXPAND_CONCAT(name1,name2) #define RT_MODEL CONCAT(MODEL,_rtModel)
Change the extern declaration for the function that creates and initializes the SimStruct to
extern RT_MODEL *MODEL(void);
Change the definitions of rt_CreateIntegrationData and rt_UpdateContinuousStates to be as shown in the Release 14 version of grt_main.c.
Change all function prototypes to have the argument 'RT_MODEL' instead of the argument 'SimStruct'.
The prototypes for the functions rt_GetNextSampleHit, rt_UpdateDiscreteTaskSampleHits, rt_UpdateContinuousStates, rt_UpdateDiscreteEvents, rt_UpdateDiscreteTaskTime, and rt_InitTimingEngine have changed. Change their names to use the prefix rt_Sim instead of rt_ and then change the arguments you pass in to them.
See the Release 14 version of grt_main.c for the list of arguments passed in to each function.
Modify all macros that refer to the SimStruct to now refer to the rtModel. SimStruct macros begin with the prefix ss, whereas rtModel macros begin with the prefix rtm. For example, change ssGetErrorStatus to rtmGetErrorStatus.
The Real-Time Workshop Embedded Coder product supports the GRT compatible call interface option. When this option is selected, the Real-Time Workshop Embedded Coder product generates model function calls that are compatible with the main program module of the GRT target (grt_main.c or grt_main.cpp). These calls act as wrappers that interface to ERT (Embedded-C format) generated code.
This option provides a quick way to use ERT target features with a GRT-based custom target that has a main program module based on grt_main.c or grt_main.cpp.
See the Code Generation Options and Optimizations in the Real-Time Workshop Embedded Coder documentation for detailed information on the GRT compatible call interface option.
![]() | S-Function Code Format | Building Subsystems and Working with Referenced Models | ![]() |
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |