- Define a new storage class and assign a memory section with the required qualifier:

- Map this storage class to the required parameters:

How do I prepend a variable declaration with a qualifier in my generated code?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 14 Oct 2022
Answered: MathWorks Support Team
on 15 Dec 2022
I am generating C code and I want to add a macro before the variable declarations.
Currently, my generated code looks as follows:
/* Exported block parameters */
float32 variableName = 0.5F; /* Variable: variableName
* Referenced by: '<S5>/Constant1'
*/
I want to add a macro, which is defined in an external header file such that my generated code is as follows:
/* Exported block parameters */macro float32 variableName= 0.5F; /* Variable: variableName
* Referenced by: '<S5>/Constant1'
*/
How do I do this?
Accepted Answer
MathWorks Support Team
on 14 Oct 2022
There are 2 possible ways to prepend the variable declarations in your generated code with a macro, depending on where these parameters are defined in your model.
Parameters Defined in Model Workspace
You can map the parameter to "ConstantMemory" and use additional native type qualifiers to prepend the keywords, by setting "AdditionalNativeTypeQualifier" to be 'macro'.
You can find more about this in the documentation here: https://www.mathworks.com/help/releases/R2021b/autosar/ug/map-model-elements-using-simulink-autosar-mapping-explorer.html#mw_f8f8aab0-d352-46e0-ae2f-9b3e3bdf5da9
Parameters Defined in Base Workspace or SLDD (Simulink Data Dictionary)
You can define a new storage class, assign a memory section with the defined qualifier and map this storage class to the required parameters. You can do this as follows:
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!