Main Content

Select Code Generation Output for Target Platform Deployment

When you want to generate code for a specific target platform, you configure the model at a high level by selecting the code output and, for C code, the code interface configuration. These high-level code output options determine which configuration parameters and code interface options are available for your model.

Example Model Hierarchy

For this example, open the model RollAxisAutopilotHarness by entering this command at the MATLAB® Command Window:

openExample("RollAxisAutopilotHarness")
The top model is a harness model that generates test inputs for the component model RollAxisAutopilot. The harness model is for simulation only. You generate code for the model RollAxisAutopilot.

Select Output for Simulation Harness

For the simulation harness model, specify the output as simulation only. This specification indicates to the code generator to not generate code for this model.

  1. Navigate to the top model RollAxisAutopilotHarness.

  2. Open the Embedded Coder app.

  3. On the C Code tab, from the Output drop-down list, click Simulation Only.

Model RollAxisAutopilotHarness showing the C Code tab. The model is configured for simulation only and the C Code tab does not show code generation options.

The C Code tab hides the code generation actions because you do not generate code for this model. The code generation actions appear when you navigate into a model that is configured for code generation.

Specify Code Generation Output

To generate code for a target platform, specify the target and language as the code generation output for a model. You can specify these code generation output types:

  • Embedded Code − C — Generate a C to run on the target device. The generated code is either a standalone program that runs on the target or a component that the target middleware runs, depending on the code interface configuration.

  • Embedded Code − C++ — Generate C++ code to run on the target device.

  • Shared Library — Generate shared library code.

For the model RollAxisAutopilot, select the output Embedded Code − C.

  1. Navigate to the referenced model RollAxisAutopilot.

  2. On the C Code tab, from the Output drop-down list, click Embedded Code − C.

Model RollAxisAutopilot configured for embedded C code. The C Code tab shows code generation options.

Next, configure the model to use a code interface configuration to generate code for the target platform.

Select C Code Interface Configuration

When you generate C code, you can generate code for a specific target platform by selecting a code interface configuration. A code interface configuration defines the interfaces in the generated code and controls how the code interacts with the target platform on which you run the code. You select one of these types of code interface configurations:

  • Data interface configuration — The code generator creates a standalone executable program intended to run on the target device. The generated code includes the scheduler and services for the target device and uses the data interfaces that you define.

  • Service interface configuration — The code generator creates an algorithm that you intend to deploy within a larger application. The platform middleware calls the algorithm code and provides the services for the target device. The generated code calls the services according to your definitions in the service interface configuration. To create a service interface configuration, you must use an Embedded Coder Dictionary that is stored in a Simulink data dictionary.

To apply a code interface configuration, select the Embedded Coder Dictionary that contains the configuration. For this example, configure the component model RollAxisAutopilot to use the dictionary and service code interface configuration that you create in Create a Service Interface Configuration.

  1. Navigate to the referenced model RollAxisAutopilot.

  2. On the C Code tab, from the Code Interface drop-down list, click Set up shared Embedded Coder Dictionary.

  3. Select an .SLDD file that contains your Embedded Coder Dictionary. For this example, select InterfaceCoderDictionary.sldd, which you create in Create a Service Interface Configuration. Click Open and Next.

The Embedded Coder Dictionary provides the code interface configuration for the model. You can configure the code interface in more detail by mapping model elements to code definitions from the interface configuration.

Related Topics