Main Content

Optional: Generate AUTOSAR Software Component Code (Requires Embedded Coder)

如果您可以访问金宝app®Coder™and Embedded Coder®software, you can build an AUTOSAR model. When you build an AUTOSAR model, the code generator produces C code that complies with the AUTOSAR standard and ARXML descriptions.

  1. If not already open, open your configured version of modelmy_autosar_swc

  2. 通过按下启动代码生成Ctrl+B。代码生成器生成C代码和ARXML文件。生成的代码符合AutoSar标准,因此您可以使用AutoSar运行时环境安排代码。

    The code generator also produces and displays a code generation report.

  3. 在代码生成报告中,查看生成的代码。在您目前的MATLAB中®folder, themy_autosar_swc_autosar_rtw文件夹包含此表中列出的主要文件。

    Generated Code Files

    Files Description
    my_autosar_swc.c Contains entry points for the code that implements the model algorithm. This file includes rate scheduling code.
    my_autosar_swc.h Declares model data structures and a public interface to the model entry points and data structures.
    rtwtypes.h Defines data types, structures, and macros that the generated code requires.
    my_autosar_swc_component.arxml
    my_autosar_swc_datatype.arxml
    my_autosar_swc_implementation.arxml
    my_autosar_swc_interface.arxml
    Contain elements and objects that represent AUTOSAR software components, ports, interfaces, data types, and packages. You integrate ARXML files into an AUTOSAR run-time environment. You can import ARXML files into the Simulink environment by using the AUTOSAR ARXML importer tool.
  4. 打开并查看代码接口报告。此信息在ARXML文件中捕获。运行时环境生成器使用ARXML描述将代码连接到AutoSar运行时环境中。

    入口点功能:

    • Initialization entry-point function —void my_autosar_swc_Init(void)。At startup, call this function once.

    • Output and update entry-point function —void my_autosar_swc_Step(void)。Call this function periodically at the fastest rate in the model. For this model, call the function every second. To achieve real-time execution, attach this function to a timer.

    • Output and update entry-point function —void my_autosar_swc_Step1(void)。Call this function periodically at the second fastest rate in the model. For this model, call the function every 2 seconds. To achieve real-time execution, attach this function to a timer.

    The entry-point functions are also accessible in the Code Mappings editor, on theFunctions标签。您可以从外部代码或您修改的生成主函数的版本中调用这些生成的功能。如果需要,您可以更改函数的名称。对于基于速率的模型的基本速率步骤函数和导出功能模型的步骤函数,您可以自定义函数名称和参数。

    Input ports:

    • Block In1_1s — Require port, interface: sender-receiver of type real-T of 1 dimension

    • Block In2_2s — Require port, interface: sender-receiver of type real-T of 1 dimension

    Output ports:

    • Block Out1 — Provide port, interface: sender-receiver of type real-T of 1 dimension

    • Block Out2 — Provide port, interface: sender-receiver of type real-T of 1 dimension

  5. Check whether the configuration changes that you made appear in the generated code by using the Code panel in the Code perspective. To open the Code panel, on the AUTOSAR tab, clickView Code。The Code panel opens to the right of the model. In the search field, typeIn1_1s_SS1, the new name for AUTOSAR software component portIn1_1s。Then, click the arrow button to advance to instances of the name in the ARXML filemy_autosar_swc_component.arxml。Verify that the settings of communication attributes that you modified for the AUTOSAR software component port appear correctly.

  6. 使用代码透视代码面板探索生成代码的其他方面。例如,如果选择文件my_autosar_swc.c, and then click in the search field, a list of links to code elements, including the entry-point functions, appears. Use the links to quickly navigate to key areas of the generated C code.

相关话题