Intialization of local variables in model_step() function

Is it possible to initialize the local variables (with zero or with any value) in model_step() function in the code generated by Embedded coder ?
I am using R2011b.
I want code to generated like this.
void model_step()
{
boolean_T rtbxyz = 0;
uint8_T rtbklm[2] = {0,0};
/* Model logic */
}
I gone through the code generation settings but not found any way.

1 Comment

I am facing the same issue.Is there any solution or do I need to contact technical team of Mathworks?

Sign in to comment.

Answers (1)

What block generates the code that uses these variables? The block is responsible for initialization of these variables. If it is an S-function block, it's TLC file might need fixing. If it is a shipped Simulink library block, uninitialized variables should be considered a bug.

4 Comments

Thanks for your response Kaustubha.
I am using model for AUTOSAR and block responsible for generating these variables is Invoke AUTOSAR server operation which is basically a s-function shipped with autosar package.
But I think local variables in the model_step (Runnable in case of AUTOSAR) are never initialized. Below are some example of local variables generated in the code:
void XYZRunnable(void)
{
boolean_T rtb_UnitDelay;
boolean_T rtb_UnitDelay_k;
boolean_T rtb_UnitDelay_m;
boolean_T rtb_UnitDelay_d;
boolean_T rtb_LogicalOperator;
boolean_T rtb_LogicalOperator_f;
boolean_T rtb_LogicalOperator_fi;
boolean_T rtb_UnitDelay_p;
uint8_T rtb_DataTypeConversion5;
uint8_T rtb_DataTypeConversion2_m;
uint8_T rtb_DataTypeConversion3_a;
......
......
......
}
You can see in the code that all local variables are un-initialized. :-(
TAB: I've usually seen such variables initialized before use (even if not initialization at declaration) - does that not happen in this case? If so, I would recommend reporting this to MathWorks Technical Support. Thanks!
Again thanks kaustubha for your reply.
I am sure that these variables are not initialized before use. They are generally use to store intermediate data for calculation. Please see the below example of generated code
void XYZRunnable(void)
{
/* In the declaration */
uint8_T rtb_XYZ_Direction[2];
/* In the code */
Rte_Call_XYZ_Direction_data_read(&rtb_XYZ_Direction);
}
In my code Rte_Call_XYZ_Direction_data_read returns only 1 byte so 2nd byte in local variable rtb_XYZ_Direction must be zero. Thus initialization of the rtb_XYZ_Direction is needed as
uint8_T rtb_XYZ_Direction = {0,0};
Otherwise 2nd byte in it will have garbage value.
And......... Reporting some issue to mathwork is usually a long procedure (as they ask for license number & it should be under maintenance etc...) I will wait here to see if somebody has any solution.
The last option for me is to modify the generated code using some script or manually.
TAB: Please report this as a bug to MathWorks Support. Hopefully they will also provide a workaround for you.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

TAB
on 26 Oct 2012

Commented:

on 16 Apr 2020

Community Treasure Hunt

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

Start Hunting!