I have a static global structure
variable say Struct1
in a file which is modified only in the file(say Struct1file.c)
I have a State Machine
in the same file(Struct1file.c) which is called within a task(Struct1Task) after every 1ms. This State Machine
has functions which access and changes the value of the static global structure
variable. After certain number of times, the statemachine is called, all the variables within the global structure variable changes to 0xFF except the arrays within Strcut1
.
typedef Struct1{
short int Data[20];
char cData[40];
bool flag1;
short int value1;
bool flag2;
short int value2;
estate switch_var;
Callback callbackfunction();
};
All the values within Struct1
change except the values in Data
and Data1
.
Minimal code:
switch(Strcut1var.switch_var)
{
case IDLE: ReadintoData();
Strcut1var.switch_var = TAKE_ACTION;
break;
case TAKE_ACTION: if(Struct1var.Data[1]== some_enum)
{
Callbackfunction(Data,LengthofData);
Struct1var.switch_var = SEND;
}
break;
case SEND: if(Struct1var.flag1 == TRUE)
SendData();
break;
}
I am working on C and on Keil. I tried changing the stack and heap size, but to no effect!
In which case the most likely cause is overrunning the bounds of
Data1
.Keil provide compilers for several targets. It would be more useful to know the target, and the debug capability available to you. If hardware memory access breakpoints are available for example, you could place a write access breakpoint on the address of the
flag1
member, and determine precisely where it is overwritten.You could probably avoid the problem by not using global data in the first instance. Even if the problem is not avoided by that it is certainly easier to debug because use of access functions provide an opportunity to use more generally available program-counter breakpoints to trap data access.