Other Parts Discussed in Thread: C2000WARE
Tool/software: TI C/C++ Compiler
My problem is I am passing a pointer to a structure as a function parameter. The error occurs when I have passed a pointer to a structure to the function several times, then I change the pointer to another structure on the next function call. The address that is received in the function as it executes is incorrect. The received address is different than the address that was passed when the function was. called (the correct address).
Here is an illustration of the problem in the debugger. Here is the address that is being passed to the function:
And this is what the function receives:
These two views are separated by one press of the F5 "step into" key. Needless to say, when this function runs it makes a hash of things, writing into the wrong addresses.
The structure looks like this:
/ Define Sweep structures
struct Sweep {
float value;
float first;
float last;
float delta;
Uint16 i;
Uint16 n;
};
struct Sweep VoutSweep;
struct Sweep VinSweep;
struct Sweep VcoSweep;
The function:
int SweepStep( struct Sweep *sweep, int Reset ) {
int carry1 = 0;
if (Reset){
sweep->value = sweep->first;
sweep->i = 0;
if (sweep->delta == 0) sweep->delta = 1; // no divide by zero
sweep->n = (int)((sweep->last - sweep->first)/sweep->delta + .5);
} else if (sweep->i==sweep->n){
carry1 = 1;
sweep->value = sweep->first;
sweep->i = 0;
} else {
sweep->value += sweep->delta;
sweep->i++;
}
return carry1;
}
The function calls:
if (carry && vin_sweep_on){
carry = SweepStep(&VinSweep, 0); // when previous sweep reaches final value, increment next sweep
}
if (carry && vout_sweep_on){
carry = SweepStep(&VoutSweep, 0); // sweep returns 1 when it reaches its final value, 0 otherwise
}
if (carry && vco_sweep_on){
carry = SweepStep(&VcoSweep, 0); // when previous sweep reaches final value, increment next sweep
}
The program runs through the sweep of SweepStep(&VinSweep, 0) until it wraps around and returns a 1. Then SweepStep(&VoutSweep, 0) runs, with a pointer to a different structure.
That is when the problem occurs.
Another feature of this problem is that it has been difficult to reproduce, as seemingly unrelated changes affect its occurrence. Initially I used the local "carry" variable in both the function making the call
(the B4 state machine function) and in the SweepStep function. I found that if I changed the name of the carry variable in either place, the problem went away. That didn't make sense because both are
local variables, but that was my observation. But now the problem has reoccurred as documented above, and the two variables have different names.
I am running C2000Ware_3.01.00.00 and CCS 9.2.0.00013

