Configure elements for code generation

조회 수: 19 (최근 30일)
Thomas Becker
Thomas Becker 2021년 7월 28일
답변: Rahul 2025년 8월 13일 7:00
My question relates to code generation for Language = C with the Embedded Coder
  1. Is it correct, that the option's Configuration Parameters > Code Generation > Interface > Code interface packaging main impact is the function interface? With Nonreusable function meaning void-void interface; and Reusable function meaning the model data being passed to the functions according to question 2)?
  2. Additionally to the option from question 1), only for Reusable function, the option Pass root-level I/O determines whether to pass the argument(s) individually or by structure references, right?
  3. Additionally to the global options from 1) and 2), Code Interface > Individual Element Code Mappings gives access to configure function prototype and arguments in detail, is that correct?
  4. Defaults for 3) can be configured in Code Interface > Default Code Mappings?
  5. What's the purpose of the Code Mappings Editor, compared to the options from 1) and 2)? Is it only a newer way of doing the configuration (that's how I interprete the migration guide)? Or is it rather a mean for configuring single elements like inport, parameter, signal, ...?
  6. Last, but not least: If it's possible to configure signals and parameters in 5), are Simulink.Signal and Simulink.Parameter objects still needed?
Sorry for being a little confused... And thanks in advance!

답변 (1개)

Rahul
Rahul 2025년 8월 13일 7:00
Hi Thomas,
I understand that you are configuring code generation with Embedded Coder for C output and want to clarify how the Code interface packaging and Code Mappings Editor settings interact, and whether 'Simulink.Signal' and 'Simulink.Parameter' objects remain necessary. Based on the Embedded Coder documentation, here’s a detailed breakdown:
1. Code interface packaging (Configuration Parameters > Code Generation > Interface)
This setting indeed controls the nature of the generated function interface:
  • Nonreusable function (default for C) creates a void-to-void interface and relies on static, globally accessible model data structures.
  • Reusable function generates reentrant code that accepts a model data structure (e.g., 'model_M') as an argument, enabling multiple instances, so the interface differs significantly.
Fore more information regarding Code Interface Packaging, you can refer to the following documentation link: https://www.mathworks.com/help/releases/r2021a/rtw/ref/codeinterfacepackaging.html
2. ‘Pass root-level I/O’ setting (only applicable with Reusable function)
Yes, when 'Reusable function' is selected, the 'Pass root-level I/O' as option determines whether root-level inports/outports are passed individually or packaged within a structure (part of model data). That decision affects the function prototype.
3. Individual Element Code Mappings vs. Default Code Mappings
  • Default Code Mappings (Configuration Parameters > Code Interface > Default Code Mappings) provide global defaults for how data and functions are packaged in generated code (storage class, headers, etc.).
  • Individual Element Code Mappings allow fine-grained customization on a per-port, parameter, or signal basis adjusting naming, storage class, and code location.
4. Purpose of the Code Mappings Editor
The Code Mappings Editor is not just a modern alternative it’s the primary interface for configuring how each individual element (inport, outport, parameter, signal, etc.) appears in the generated code. It lets you control properties like visibility ('public', 'private'), storage class, naming, and header placement. In short:
  • Global options set the overall interface style.
  • Code Mappings Editor enables element-level control.
Fore more information regarding Code Mappings Editor, you can refer to the following documentation link: https://www.mathworks.com/help/releases/r2021a/ecoder/ref/codemappingseditorc.html
5. 'Simulink.Signal' and 'Simulink.Parameter' objects
  • Even with element mappings, data objects like 'Simulink.Parameter' and 'Simulink.Signal' allow you to define properties such as storage classes, tuning settings, and visualization.
  • These objects help organize data definitions and support certain mapping configurations in the Code Mappings Editor, especially when you rely on storage classes defined in an Embedded Coder Dictionary.
Fore more information regarding 'Simulink.Signal' and 'Simulink.Parameter' objects, you can refer to the following documentation links:

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by