Cross-Release Code Integration - MATLAB & Simulink (original) (raw)

If you have an Embedded Coder® license, you can integrate generated C code from previous releases with generated code from the current release when the source models are single-rate and the generated C code is from:

If you can reuse existing code without modification, you can reduce the cost of reverification.

Note

crossReleaseImport supports the import of generated code from only the previous eight releases.

Workflow

Consider this control system model.

The Controller Model block references a model that consists of three components:

To integrate code from previous releases with generated code from the current release, use this workflow:

  1. Specify an existing shared code folder
    You can specify the reuse of shared code from an existing folder, for example, a library of verified code that an administrator maintains and updates. Specify the shared code folder for model components that require code generation in the current release, for example,Controller and C1.
    In the Configuration Parameters dialog box, in the field, enter the full path to the shared code folder.
  2. Import components into current release
    From the current release, import generated component code from previous releases as software-in-the-loop (SIL) blocks or processor-in-the-loop (PIL) blocks. For example:
    crossReleaseImport(folderPathForP1_ert_rtw,'Controller', ...
    'SimulationMode','SIL');
    crossReleaseImport(folderPathForP2_ert_rtw,'Controller', ...
    'SimulationMode','SIL');
    crossReleaseImport(folderPathForP3,'Controller', ...
    'SimulationMode','SIL');
    In the current working folder, the crossReleaseImport function creates the xrel subfolder that contains software-in-the-loop (SIL) blocks and subfolders:
    • P1_R20XXb_sil andP1_R20XXb_sil_resources
    • P2_R20YYa_sil andP2_R20YYa_sil_resources
    • P3_R20YYb_sil andP3_R20YYb_sil_resources
  3. Incorporate components into current release model
    To replace components with SIL or PIL blocks, use the Simulink® Editor or the pil_block_replace command. For example, replace:
    • P1 with P1_R20XXb_sil.
    • P2 with P2_R20YYa_sil.
    • P3 with P3_R20YYb_sil.
      When you run a model simulation, the simulation runs the previous release code through the SIL or PIL blocks.
      When you build the Controller model (slbuild('Controller')), the code generator does not generate new code for the components represented by the SIL or PIL blocks. The model code calls code generated by previous releases.
      The Simulink Code Inspector™ supports call-site validation for a cross-release SIL or PIL block. The block provides a specification of the expected function call, which is derived from the generated code. During analysis, the Simulink Code Inspector compares the expected function call with the block behavior. For information about analysis limitations, see S-Function (Simulink Code Inspector).

Limitations

The cross-release code integration workflow does not support:

At the end of the model build process, the code generation report displays shared files that are directly used by the integration model, for example, Controller. The report does not display shared files used by the components of the model, for example,P1 and P2.

If your model has:

You can run:

For information about other cross-release AUTOSAR code integration limitations, see Import AUTOSAR Code from Previous Releases.

Simulink.Bus Support

To use a bus object as a data type in cross-release ERT code integration, use one of these approaches.

Approach Code Export Code Import
Automatic In the previous release, before generating code, set theDataScope property of the Simulink.Bus object toAuto. Do not assign a value to theHeaderFile property.The code generator creates the Simulink.Bus data type definition in the default header file, which is located in the code generation folder for the model. In the current release, before running crossReleaseImport, set the DataScope property of the Simulink.Bus object toAuto.When you build the integration model, the build process uses the Simulink.Bus data type from the header file in the imported code.
Exported bus In the previous release, before generating code, specify these properties of the Simulink.Bus object: DataScope — Set toExported.HeaderFile — Specify a filename, for example,prevRelBusType.The code generator creates prevRelBusType.h in the shared utility code folder. This header file contains the definition for theSimulink.Bus data type. Use sharedCodeUpdate to add prevRelBusType.h to the shared code folder that ExistingSharedCode specifies. In the current release, before running crossReleaseImport, set the DataScope property of the Simulink.Bus object toImported.When you build the integration model that incorporates the imported SIL or PIL block, the build process uses theSimulink.Bus data type definition inprevRelBusType.h. When you build the integration model, the build process uses the Simulink.Bus data type definition in modelName_types.h.
Imported bus In the previous release, before generating code, specify these properties of the Simulink.Bus object: DataScope — Set toImported.HeaderFile — Specify a path to a file that contains the Simulink.Bus data type definition, for example, aBusType.h. In the current release, after importing generated code, you do not have to change the Simulink.Bus.When you build the integration model that incorporates the imported SIL or PIL block, the build process uses the Simulink.Bus data type definition fromaBusType.h.

Root-Level I/O Through Global Variables in Generated Code

When imported ERT code from a previous release implements an input or output port through a global variable, the code that is generated from the integration model depends on the properties of the signal connected to the port in the integration model.

If the integration model signal does not map to a generated code variable that has the same name as the signal in the imported code, the generated code:

If the integration model signal maps to a variable with the same name as the signal in the imported code, the variable used by the imported code is also used by the code generated from the integration model. You must use a compatible storage class for the signal.

Storage Class Property Property Value Support
Type Unstructured only
Data access Cannot connect a port implemented as aPointer variable in the imported code to a signal of the same name that is implemented through a Direct storage class in the integration modelCannot connect a port implemented as a Direct variable in the imported code to a signal of the same name that is implemented as aPointer in the integration model
Data scope If the imported code declares but does not define the variable (i.e. code is generated from a signal that uses theImported value), then one of the following is required: The integration model uses the Exported value.External code defines the variable.If the imported code defines the variable (i.e. code is generated from a signal that uses the Exported value): For signals in the integration model that are connected to root-level I/O ports: Set the EnableDataOwnership configuration parameter to on.Use a custom storage class with these properties: Type –UnstructuredData access –DirectData scope –ExportedOwner – Non-empty value that is not the name of the integration model. For example, the value can be the name of the imported component.For signals in the integration model that are not connected to root-level I/O ports, use a custom storage class with these property values: Data scope -ImportedData access -Direct

Communicate Between Current and Previous Release Components Through Global Data Stores

Current and previous release components can communicate through global data stores associated with Simulink.Signal objects in the MATLAB base workspace or a Simulink data dictionary. The workflow described here applies to cross-release ERT code integration.

Code Generation Configuration

Before generating model component code in the old release, configure data store memory to use a storage class that imports external code.

If a top-model or subsystem build process generates the code, set theStorage class property of the Simulink.Signal objects to one of these classes:

If a model reference build process generates the code, you can also use these classes:

Import Configuration

In the current release, before you run crossReleaseImport, define aSimulink.Signal object in the MATLAB base workspace or a Simulink data dictionary for each global data store of the component that you want to import:

  1. For the object name and the Data type,Complexity, and Dimensions object properties, specify values that match values of the corresponding object in the component that you want to import.
  2. For the Storage class property, specify a value that is compatible. If the previous release value isImportedExtern, specify one of these values for the current release:
    • ImportedExtern
    • ExportedGlobal
    • ImportFromFile orExportToFile custom storage class.
      If the previous release value isImportedExternPointer, then specifyImportedExternPointer for the current release.
  3. For the Identifier property, specify a matching value only if the property is specified for the object in the component that you want to import.
  4. Save the Simulink.Signal objects. The objects are required each time you simulate or build the imported SIL or PIL block.

For more information, see Data Stores in Generated Code.

Parameter Tuning

The cross-release ERT code integration workflow supports parameter tuning in an integration model that contains component code with tunable parameters from previous releases.

In the current release, before you run crossReleaseImport, for each tunable parameter of the component that you want to import:

  1. Define a Simulink.Parameter object in the MATLAB base workspace or a Simulink data dictionary.
  2. For the object name and the Data type,Complexity, and Dimensions object properties, specify values that match the previous release object values. If the variable in the imported source code does not have the same name as the object, for the Identifier property, specify a value that matches the variable name.
  3. If the previous release object uses the GetSet custom storage class, specify:

For code generated by a top-model or subsystem build process in a previous release, these limitations apply:

Use Multiple Instances of Code Generated from Reusable Referenced Model

Using a reusable referenced model, you can specify unique model argument values for each instance of the referenced model in a parent model. Import previously generated code for the reusable referenced model into the current release as a parameterized cross-release SIL or PIL block, and then insert multiple instances of the block into an integration model. For each block instance, you can specify unique model argument values.

  1. Update existing shared code folder.
    sharedCodeUpdate(sourceFolder,destinationFolder)
  2. Import generated code for the reusable referenced model into the current release as a parameterized cross-release block, for example, a SIL block.
    handleSILBlock = crossReleaseImport(reusableReferencedModelcodeLocation, ...
    configSetIntegrationModel, 'SimulationMode', 'SIL');
  3. In the integration model, replace, for example, two instances of the referenced model with instances of the cross-release SIL block.
    open_system(integrationModel);
    blockInstanceName1 = 'refModelInstanceName1';
    blockinstanceName2 = 'refModelInstanceName2';
    SILBlockFullName = getfullname(handleSILBlock);
    replace_block(integrationModel, 'Name', blockInstanceName1, ...
    SILBlockFullName, 'noprompt');

replace_block(integrationModel, 'Name', blockInstanceName2, ...
SILBlockFullName, 'noprompt'); 4. Suppose the reusable referenced model has model arguments_`paramA`_ and_`paramB`_, and the values for the referenced model instances,_`refModelInstanceName1`_ and_`refModelInstanceName2`_, are workspace variables. In this case, you can specify argument values for the cross-release block instances that are workspace variables.
pathToBlockInstanceName1 = [integrationModel, '/', blockInstanceName1];
pathToBlockInstanceName2 = [integrationModel, '/', blockInstanceName2];
set_param(pathToBlockInstanceName1, 'paramA', 'paramAinstName1');
set_param(pathToBlockInstanceName1, 'paramB', 'paramBinstName1');
set_param(pathToBlockInstanceName2, 'paramA', 'paramAinstName2');
set_param(pathToBlockInstanceName2, 'paramB', 'paramBinstName2'); 5. To specify unique model argument values for the block instances in the integration model, assign values to the workspace variables,_`paramAinstName1`_,_`paramBinstName1`_,_`paramAinstName2`_, and_`paramBinstName2`_.

Compare Simulation Behavior of Model Component in Current Release and Generated Code from Previous Release

In a previous release, suppose that you developed a model component, generated code for the component, and tested and deployed the generated code. Now, in the current release, you want to add features to the model component and use the model component in system development and code generation. Before you proceed, you can compare the functional behavior of the model component and the generated code from the previous release.

To test the numerical equivalence between the model component and the generated code from the previous release, use Simulink Test™. With the Test Manager (Simulink Test), you can perform back-to-back tests and output comparisons:

  1. Bring the model component into the current release as a Model block with the Simulation mode block parameter set toNormal.
  2. With the Model block, create a top model that specifies test input data.
  3. Import the code generated in the previous release into the current release as a SIL block.
  4. With the SIL block, create another top model that specifies the same the test input data.
  5. In the Test Manager, create an equivalence test case that runs simulations of the top models and compares outputs.
  6. Run the test case and review results.

For more information, see .

Note

If you want to compare the behavior of generated code from the current and previous release, in step 1, specify these Model block parameters:

Import AUTOSAR Code from Previous Releases

If you install the Embedded Coder Support Package for AUTOSAR Standard, you can import into the current release AUTOSAR component code that you generated in a previous release.

When you run crossReleaseImport, the function imports the AUTOSAR code as a cross-release Model block instead of a SIL or PIL block. TheSimulation mode parameter of the Model block is set toSoftware-in-the-loop (SIL) orProcessor-in-the-loop (PIL). Incorporate theModel block into the current release model.

These limitations apply:

See Also

sharedCodeMATLABVersions | sharedCodeUpdate | crossReleaseImport

Topics