Use Configuration Reference to Select Code Generation Target
This example shows how to use a configuration reference to select a code generation target for a model reference hierarchy without modifying individual models.
Open Example Model
Open the example model ConfigSetCodegenTargetTop
.
open_system('ConfigSetCodegenTargetTop');
To open the active configuration set for the model ConfigSetCodegenTargetTop
, on the Modeling tab, click the Model Configuration Parameters button.
Because the model is using a referenced configuration, the Configuration Reference dialog box opens and displays a read-only view of the referenced configuration set. Information at the top of the dialog box indicates that the model is using the configuration set, Reference
, located in the data dictionary, ConfigSetRefData.sldd
. In this example, Reference
is another configuration reference, Configuration_ERT
.
In the model editor, right-click the Model block, Amplifier
, and select Open As Top Model. This opens the referenced model ConfigSetCodegenTargetRef
.
open_system('ConfigSetCodegenTargetTop/Amplifier');
Open the active configuration set for this model. The name and location for the referenced configuration is the same as in ConfigSetCodegenTargetTop
.
Open the Referenced Configuration Set
If you need to change and apply parameter values in the configuration set, open Configuration_ERT
for edit in the Configuration Parameters dialog box by clicking the Model Configuration Parameters icon at the top of either of the Configuration Reference dialog boxes.
Generate Code for ERT Target
The referenced configuration set is customized for ERT code generation. To generate code, press Ctrl+B.
slbuild('ConfigSetCodegenTargetTop');
### Searching for referenced models in model 'ConfigSetCodegenTargetTop'. ### Found 1 model reference targets to update. ### Starting serial model reference code generation build. ### Starting build procedure for: ConfigSetCodegenTargetRef ### Successful completion of code generation for: ConfigSetCodegenTargetRef ### Starting build procedure for: ConfigSetCodegenTargetTop ### Successful completion of code generation for: ConfigSetCodegenTargetTop Build Summary Model reference code generation targets: Model Build Reason Status Build Duration =============================================================================================================== ConfigSetCodegenTargetRef Target (ConfigSetCodegenTargetRef.c) did not exist. Code generated. 0h 0m 9.622s Top model targets: Model Build Reason Status Build Duration =============================================================================================================== ConfigSetCodegenTargetTop Information cache folder or artifacts were missing. Code generated. 0h 0m 13.414s 2 of 2 models built (0 models already up to date) Build duration: 0h 0m 25.343s
The code generation report displays once code generation is complete.
Switch Targets and Generate Code for AUTOSAR Target
For this model there is another configuration set, Configuration_AUTOSAR, that is customized for AUTOSAR code generation. At the top of the Configuration Reference dialog box, in the rightmost drop-down list, select Configuration_AUTOSAR. slexConfigSetREfExample
and its referenced model, slexConfigSetMdlRef
, now both use the configuration set, Configuration_AUTOSAR
.
Because you edited the configuration reference, the data dictionary has unsaved changes. The configurations are stored outside of the models so the models do not have unsaved changes.
If you have downloaded the AUTOSAR package, you can now generate code for an AUTOSAR target. In the model editor window, press Ctrl+B.