Generate an ASAP2 File
About Generating ASAP2 Files
You can generate an ASAP2 file from your model in one of the following ways:
-
Use the Generic Real-Time Target or a Embedded Coder target to generate an ASAP2 file as part of the code generation and build process.
-
Use the ASAM-ASAP2 Data Definition Target to generate only an ASAP2 file, without building an executable.
This section discusses how to generate an ASAP2 file by using the targets that have built-in ASAP2 support. For an example, see the ASAP2 example model rtwdemo_asap2
.
Use GRT or ERT System Target File
The procedure for generating the ASAP2 data definition for a model using the Generic Real-Time Target or Embedded Coder system target file is as follows:
-
Use the Model Data Editor (View > Model Data Editor) to apply storage classes to signals, block states, and block parameters as described in Apply Storage Classes to Individual Signal, State, and Parameter Data Elements. Use signal and state names to refer to corresponding MEASUREMENT records and parameter object names to refer to CHARACTERISTIC records.
Use any storage class or custom storage class other than
Auto
,FileScope
, or, if you set the default storage class of the corresponding data category toDefault
in the Code Mapping Editor (the default setting),Model default
. For example, usingExportedGlobal
configures the data item as an unstructured global variable in the generated code.Note
The data item is not represented in the ASAP2 file if any of the following conditions exist:
-
You apply one of the storage classes
Auto
,FileScope
, orDefault
(throughModel default
). -
You apply a custom storage class that causes the code generator to generate a macro or non-addressable variable.
-
-
Use the Model Data Editor to configure the remaining properties as desired for each data item.
-
On the Code Generation pane, click Browse to open the System Target File Browser. In the browser, select
grt.tlc
or an ERT based target file and click OK. -
On the Code Generation > Interface pane, in the Data exchange interface subgroup, select ASAP2 interface.
-
Select the Generate code only check box on the Code Generation pane.
-
Click Apply.
-
Build the model.
The code generator writes the ASAP2 file to the build folder. By default, the file is named
, wheremodel
.a2l
is the name of the model. The ASAP2 setup file controls the ASAP2 file name. For details, see Customize Generated ASAP2 File.model
Use the ASAM-ASAP2 Data Definition Target
The procedure for generating the ASAP2 data definition for a model using the ASAM-ASAP2 Data Definition Target is as follows:
-
Use the Model Data Editor (View > Model Data Editor) to apply storage classes to signals, block states, and block parameters as described in Apply Storage Classes to Individual Signal, State, and Parameter Data Elements. Use signal and state names to refer to corresponding MEASUREMENT records and parameter object names to refer to CHARACTERISTIC records.
Use any storage class or custom storage class other than
Auto
,FileScope
, or, if you set the default storage class of the corresponding data category toDefault
in the Code Mapping Editor (the default setting),Model default
. For example, usingExportedGlobal
configures the data item as an unstructured global variable in the generated code.Note
The data item is not represented in the ASAP2 file if any of the following conditions exist:
-
You apply one of the storage classes
Auto
,FileScope
, orDefault
(throughModel default
). -
You apply a custom storage class that causes the code generator to generate a macro or non-addressable variable.
-
-
Use the Model Data Editor to configure the remaining properties as desired for each data item.
-
On the Code Generation pane, click Browse to open the System Target File Browser. In the browser, select
asap2.tlc
and click OK. -
Select the Generate code only check box on the Code Generation pane.
-
Click Apply.
-
Build the model.
The Simulink Coder code generator writes the ASAP2 file to the build folder. By default, the file is named
, wheremodel
.a2l
is the name of the model. The ASAP2 setup file controls the ASAP2 file name. For details, see Customize Generated ASAP2 File.model
Generate ASAP2 Files for Referenced Models
The build process can generate an ASAP2 file for each referenced model in a model reference hierarchy. In the generated ASAP2 file, MEASUREMENT records represent signals and states inside the referenced model.
To generate ASAP2 files for referenced models, select ASAP2 file generation for the top model and for each referenced model in the reference hierarchy. For example, if you are using the Generic Real-Time Target or an Embedded Coder target, follow the procedure described in Use GRT or ERT System Target File for the top model and each referenced model.
Merge ASAP2 Files for Top and Referenced Models
Use function rtw.asap2MergeMdlRefs
to merge the ASAP2 files generated for top and referenced models. The function has the following syntax:
[status,info] = rtw.asap2MergeMdlRefs(topModelName,asap2FileName)
-
topModelName
is the name of the model containing one or more referenced models. -
asap2FileName
is the name you specify for the merged ASAP2 file. -
Optional::
status
returns false (logical 0) if the merge completes and true (logical 1) otherwise. -
Optional::
info
returns additional information about merge failure ifstatus
is true. Otherwise, it returns an empty character vector.
Consider the following example.
[status,info] = rtw.asap2MergeMdlRefs('myTopMdl','merged.a2l')
This command merges the ASAP2 files generated for the top model myTopMdl
and its referenced models in the file merged.a2l
.
The example model rtwdemo_asap2
includes an example of merging ASAP2 files.