Embedded Code Format

Introduction

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.

Using the Real-Time Model Data Structure

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

rtmGetdX(rtm)

Get the derivatives of a block's continuous states

rtmGetOffsetTimePtr(RT_MDL rtM)

Return the pointer of vector that store all sample time offset of the model associated with rtM

rtmGetNumSampleTimes(RT_MDL rtM)

Get the number of sample times that a block has

rtmGetPerTaskSampleHitsPtr(RT_MDL)

Return a pointer of NumSampleTime × NumSampleTime matrix

rtmGetRTWExtModeInfo(RT_MDL rtM)

Return an external mode information data structure of the model. This data structure is used internally for external mode.

rtmGetRTWLogInfo(RT_MDL)

Return a data structure used by Real-Time Workshop logging. Internal use.

rtmGetRTWRTModelMethodsInfo(RT_MDL)

Return a data structure of Real-Time Workshop real-time model methods information. Internal use.

rtmGetRTWSolverInfo(RT_MDL)

Return data structure containing solver information of the model. Internal use.

rtmGetSampleHitPtr(RT_MDL)

Return a pointer of Sample Hit flag vector

rtmGetSampleTime(RT_MDL rtM, int TID)

Get a task's sample time

rtmGetSampleTimePtr(RT_MDL rtM)

Get pointer to a task's sample time

rtmGetSampleTimeTaskIDPtr(RT_MDL rtM)

Get pointer to a task's ID

rtmGetSimTimeStep(RT_MDL)

Return simulation step type ID (MINOR_TIME_STEP, MAJOR_TIME_STEP)

rtmGetStepSize(RT_MDL)

Return the fundamental step size of the model

rtmGetT(RT_MDL,t)

Get the current simulation time

rtmSetT(RT_MDL,t)

Set the time of the next sample hit

rtmGetTaskTime(RT_MDL,tid)

Get the current time for the current task

rtmGetTFinal(RT_MDL)

Get the simulation stop time

rtmSetTFinal(RT_MDL,finalT)

Set the simulation stop time

rtmGetTimingData(RT_MDL)

Return a data structure used by timing engine of the model. Internal use.

rtmGetTPtr(RT_MDL)

Return a pointer of the current time

rtmGetTStart(RT_MDL)

Get the simulation start time

rtmIsContinuousTask(rtm)

Determine whether a task is continuous

rtmIsMajorTimeStep(rtm)

Determine whether the simulation is in a major step

rtmIsSampleHit(RT_MDL,tid)

Determine whether the sample time is hit

For additional details on usage, see SimStruct Functions — Alphabetical List in the Writing S-Functions documentation.

Making GRT-Based Targets ERT-Compatible

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:

For details on how GRT targets are made call-compatible with previous Real-Time Workshop product versions, see The Real-Time Model Data Structure.

Converting Your Target to Use rtModel

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

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:

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:

Generating GRT Wrapper Code from the ERT target

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.

  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS