So I've got functions:
int f1(uint8_t* a, int b)
{
for(int i = 0; i < b; i++)
f2(&a[i]);
return 1;
}
static void f2(uint8_t* a)
{
REG1 = *a;
...
*a = REG2;
}
"a" is a data register that is used as a buffer to put the data all the way from the main loop into the target function f2() through different wrapper functions.
"REG1" and "REG2" are I/O registers into and out of which the data is passed with "a". The value of "REG2" implicitly changes while in f2() through hardware operations.
When I watch the variable changes in debug mode, the following happens:
- b = 2
- declare i = 0, i < b
- call f2
- increment i to i = 1, i < b
- call f2
- increment i to i = 0, i < b
And since "i" never reaches 2, the loop never ends. The program is compiled and debugged with IAR EW for AVR. The optimisation for the compiler is turned off.
@Lundin is correct, I was passing an address of a pointer instead of the pointer itself with:
f2(&a[i]);