Complier issue on MC9S12Xdp512

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Complier issue on MC9S12Xdp512

751件の閲覧回数
richardlin
Contributor I

Dear All,

    This is Richard from sgcc, developing on mc9s12xdp512. I met the following issue: 
volatile unsigned long gCounter=0; //locate at 0x2cd4 

__interrupt timer_tick(){ //interrupt every 1ms 
gCounter++; 


unsigned long getCurrentTime() 

return gCounter; 


unsigned long readback=0; // locate at 0x398e 
void main() 

while(1) 

readback = getCurrentTime(); // Assembly: CALL 0xc793, 00 
LDX 0x2cd4 
LDD 0x2cd6 
RTC 
SEX D,X 
STX 0x398e 
STD 0x3985 
....delay; 



The problem is: 
as gCounter increase, for example gCounter = 0x18001; 
LDX 0x2cd4 
LDD 0x2cd6 
//Here, IX=1, D=0x8001 
RTC 
SEX D,X 
// Here, IX changes from 1 to 0xffff, cuz' the highest bit of D is "1". 
STX 0x398e 
STD 0x3985 
// Here, readback = 0xffff8001. 

I don't know why "SEX D,X" is inserted and leads to the strange result.---- only lower word of gCounter is assgined to feedback, and the higher word is wrong. how could i avoid the comiler to do such things which really take me much time to find the bug out. 
see attachment for sample code and snapshot. plz rename the file to .rar and extract first.
Debug suggest: 
See the communication.c for the bug. Don't worry about other modules. Just run the project, and set a breakpoint at gChargeManager.timeStamp=GetCurrentTime(); Then u can see from the assembly window that "SEX D,X" is inserted. Then add expressions "gTimerCount"(increased by interrupt every 1ms) and "gChargeManager.timeStamp"(assigned by GetCurrenttime(), gTimerCount), remove the breakpoint to run, u will see the issue

ラベル(1)
0 件の賞賛
1 返信

401件の閲覧回数
kef
Specialist I

First of all you should mention compiler version.  If it's Codewarrior, just show exact snippet of disassembled code.

 

STX 0x398e
STD 0x3985

 

E and 5 at the end of address can't belong to the same 32bit variable.

0 件の賞賛