How Can I modify const boolean_T variable initialization from 0 to false in generated code (ert.tlc)

2 次查看(过去 30 天)
Hi, in generated code by Embedded coder(ert.tlc), I trying to modify initialization from 0 to 'false' to reduce violation misra C Rule 10.3.
In simulink model, in fact, I used Invariant port input and I initialized it's value to 0.
so, I satisfied about declaration code below.
/* Invariant block signals (default storage) */
typedef struct {
const boolean_T Compare; /* '<S846>/Compare' */
const boolean_T Compare_g; /* '<S844>/Compare' */
const boolean_T Compare_p; /* '<S1012>/Compare' */
const boolean_T Compare_j; /* '<S1698>/Compare' */
const boolean_T Compare_b; /* '<S704>/Compare' */
const boolean_T Compare_l; /* '<S1252>/Compare' */
const boolean_T Compare_bz; /* '<S1250>/Compare' */
const boolean_T Compare_h; /* '<S1026>/Compare' */
const boolean_T Compare_ht; /* '<S1138>/Compare' */
const boolean_T Compare_a; /* '<S1180>/Compare' */
...
} ConstB_TCS_T;
Further, I want to modify initialized code from 0 to false.But, I can't find right way.
/* Invariant block signals (default storage) */
const ConstB_TCS_T TCS_ConstB = {
0, /* '<S846>/Compare' */
0, /* '<S844>/Compare' */
0, /* '<S1012>/Compare' */
0, /* '<S1698>/Compare' */
0, /* '<S704>/Compare' */
0, /* '<S1252>/Compare' */
0, /* '<S1250>/Compare' */
0, /* '<S1026>/Compare' */
0, /* '<S1138>/Compare' */
0, /* '<S1180>/Compare' */
...
}
Already generated code above, desired code below.
/* Invariant block signals (default storage) */
const ConstB_TCS_T TCS_ConstB = {
false, /* '<S846>/Compare' */
false, /* '<S844>/Compare' */
false, /* '<S1012>/Compare' */
false, /* '<S1698>/Compare' */
false, /* '<S704>/Compare' */
false, /* '<S1252>/Compare' */
false, /* '<S1250>/Compare' */
false, /* '<S1026>/Compare' */
false, /* '<S1138>/Compare' */
false, /* '<S1180>/Compare' */
...
}
How can I resolve this problem without manual code modification, just only generating code?
thank you for your help.

回答(1 个)

Karan Singh
Karan Singh 2023-9-6
Hi 다훈 ,
From what I understand, you have a Simulink model that includes an Invariant block with an initial condition value of 0 and you wish to change this initialization value to false.
To modify the initialization values from 0 to false in the generated code without manual code modification, you can follow these steps:
  1. Open the Simulink model in which you have defined the Invariant block.
  2. Double-click on the Invariant block to open its Block Parameters dialog box.
  3. In the Block Parameters dialog box, locate the "Initial condition" parameter. This parameter defines the initial value of the Invariant block's output. By default, it is set to 0.
  4. Change the initial condition value from 0 to false.
  5. Save the Simulink model.
  6. Regenerate the code using the Embedded Coder (ERT.TLC) target.
The generated code should now reflect the modified initialization values, where 0 is replaced with false in the ConstB_TCS_T structure.
Attached below are some documentation links that you may find helpful:
Hope this helps!

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by