Hello, I've just run into a problem I believe is due to the wrong way the compiler handles 64-bit variables when they are declared locally within a function (STACK).
In particular I have the following sample code that gives different results depending on whether TestFunction1() or TestFunction2() get called:
Assuming OSDC__s32Time_Error = 0x24F235C2, OSDC__s16ProportionalGain = 0x5000 and OSDC__s16LoopGain = 0x0028,
void TestFunction1(void)
{
s64Time_Error = (S64)OSDC__s32Time_Error;
s64ProportionalGain = (S64)OSDC__s16ProportionalGain;
s64LoopGain = (S64)OSDC__s16LoopGain;
s64PropComponent = s64Time_Error * s64ProportionalGain;
OSDC__s64IntegratorState += s64Time_Error * s64LoopGain;
}
void TestFunction2(void)
{
S64 s64Time_Error__STACK;
S64 s64ProportionalGain__STACK;
S64 s64LoopGain__STACK;
s64Time_Error__STACK = (S64)OSDC__s32Time_Error;
s64ProportionalGain__STACK = (S64)OSDC__s16ProportionalGain;
s64LoopGain__STACK = (S64)OSDC__s16LoopGain;
s64PropComponentTest = s64Time_Error__STACK * s64ProportionalGain__STACK;
OSDC__s64IntegratorStateTest += s64Time_Error__STACK * s64LoopGain__STACK;
}
In particular, TestFunction2() yields:
s64PropComponentTest = 0x00000B8BB0CCA000 <-- volatile global variable in external RAM
OSDC__s64IntegratorStateTest = 0x000000084D3797E0 <-- volatile global variable in external RAM
while TestFunction1() yields:
s64PropComponent = 0x00000B8BB0CCA000 <-- global variable in internal RAM
OSDC__s64IntegratorState = 0xFFFFFAF737754650 <-- global variable in internal RAM
Any idea of what's happening?
Thanks a lot.
Paolo