MATLAB: Is the definition for internal data types not generated in “Rte_Type.h” when using AUTOSAR

autosardatadatascopedatatypesdefineintenumtypedefinitionEmbedded Codergeneratedheaderfileinternalnotrte_type.hsimulink.defineintenumtypetypetypesunknown

My Simulink model contains an internal data type whose definition is not being exported to "Rte_Type.h". When generating code for my model with AUTOSAR, I get the following error when the generated code is compiled for SIL testing:
error: unknown type name 'myEnumType'
The data type is an enumeration which I define by executing the following code in MATLAB, setting the header file to "Rte_type.h":
Simulink.defineIntEnumType( 'myEnumType', ...
{'a','b','c'}, ...
[0 1 2], ...
'DefaultValue', 'a', ...
'StorageType', 'uint8', ...
'HeaderFile', 'Rte_Type.h', ...
'AddClassNameToEnumNames', true);

Best Answer

Root-cause of the issue:
  • The error in compilation is referring to an internal data type whose definition is not being generated in “Rte_type.h” (we define data types as internal when they are not used on any interfaces with the RTE).
  • It is not recommended for internal types to have “Rte_type.h” set as header file, because in the generated code, none of the RTE calls need to use the internal types (by definition).
  • Instead, having them in a header file corresponding locally to the specific SWC would provide a cleaner partition of the code.
The recommended workaround:
  • I see that you are defining the enumerated data types with Simulink.defineIntEnumType:
  • Currently, I see that the “HeaderFile” is set to “Rte_type.h”, but no setting for “DataScope” is provided when defining your enum types.
  • By default, according to the documentation, when having a HeaderFile but not a DataScope property, Simulink is expecting the type to be imported from “Rte_type.h”, and hence the error message.
Depending on your use case, there are two recommended approaches:
1. Top-down workflow:
  • In this case, you can either:
  • add a “HeaderFile” property with a header file that you choose, and “DataScope” set to “Exported” (this way this internal type’s definition will be generated in that specific header file), or
  • simply do no set any values for “HeaderFile” and “DataScope” properties. In this case, the type will be exported to “modelname_types.h”.
As an example of the two options using the enumerated data type that you showed above:
1. Selecting a HeaderFile and DataScope set to “Exported” (data type definition will be generated in “myheaderfile.h”):
Simulink.defineIntEnumType( 'myEnumType', ...
{'a','b','c'}, ...
[0 1 2], ...
'DefaultValue', 'a', ...
'StorageType', 'uint8', ...
'HeaderFile', 'myheaderfile.h', ...
'DataScope', 'Exported', ...
'AddClassNameToEnumNames', true);
2. Not adding any HeaderFile or DataScope (data type definition by default generated in “modelname_types.h”):
Simulink.defineIntEnumType( 'myEnumType', ...
{'a','b','c'}, ...
[0 1 2], ...
'DefaultValue', 'a', ...
'StorageType', 'uint8', ...
'AddClassNameToEnumNames', true);
2. Bottom-up workflow: (from MATLAB R2020b release)
  • If you are using Simulink as an AUTOSAR authoring tool and would require all data types to be defined in the generated code, you can use this capability from MATLAB R2020b release on.
  • With this new feature, you can export definitions of internal types, and for your particular use case, you can select the internal types to be exported to "Rte_type.h".
  • For this, you can choose "Rte_type.h" as HeaderFile, and set the DataScope property to "Exported", as follows:
Simulink.defineIntEnumType( 'myEnumType', ...
{'a','b','c'}, ...
[0 1 2], ...
'DefaultValue', 'a', ...
'StorageType', 'uint8', ...
'HeaderFile', 'Rte_type.h', ...
'DataScope', 'Exported', ...
'AddClassNameToEnumNames', true);
This would make the definition for "myEnumType" to be generated in "Rte_type.h".