Main Content

Write External Code to Access Generated C API Code

Once you configure your model to include C API elements in the generated code, you can write code to access and use these generated code elements. To access C API elements in the generated code, your code uses a multi-tier, interconnected, structured mapping system through which it navigates to obtain metadata and real-time information about model elements it needs to interact with. Real-time information includes computer memory addresses that hold element values. By accessing memory addresses, your code can measure and tune model elements while the generated model code is running on the target platform.

Note

The C API layer is an extension of the generated code, so model elements that are optimized away cannot exist in the generated C API code.

Your code can access C API elements in one of two equivalent ways, or through a combination of the two:

  • Directly access C API data structures.

  • Use predefined get-functions and macros that look and behave like get-functions.

This table summarizes how to access the generated C API code layer and to write code that can interact with it.

Gateway toDescriptionEntitiesTopic
Generated C API code layerStructure containers through which you access C API elements

  • Main C API model map

  • Static C API model map

Access C API Model Maps
Information about model elementsElement-specific structure arrays that store information about distinct types of model elements, such as model signals
  • Model root-level input signals

  • Model inner signals

  • Model root-level output signals

  • Block parameters

  • Model parameters

  • Block states

Access Element-Specific C API Maps
Information about properties of model elementsProperty-specific arrays that catalog and store information about generic properties, such as the data type property

  • Data type gateway map

  • Dimension gateway map

  • Fixed-point gateway map

  • Simulink® bus structure gateway map

  • Sample time gateway map

  • Dimension array

Access Property-Specific C API Arrays
Real-time information of model elementsReal-time values of model elementsData map array that contains real-time values of model elementsAccess Real-time C API Information
Real-time information of model elements in multiple coexisting model instances Real-time values of multi-instance model elementsMain C API model map array of child modelsAccess Multiple Model Instance C API Information

Related Topics