Target: ST uPSD3454 running at 36.8864 Mhz
What seems simple is causing extreme confusion.
Enhanced template code from Keil:
; Define instructions executed on a hardware timer interrupt. HW_TIMER_CODE MACRO EXTRN CODE (TIMER_Update) USING 2 ; Registerbank 2 for following code LCALL TIMER_Update ; C-func RETI ENDM
C-func:
void TIMER_Update( void ) { unsigned char data i; for( i=0; i<NUM_TIMERS; i++ ) { timers[i]--; if( timers[i] == 0 ) { timers[i] = reload[i]; if( events[i] < 255 ) events[i]++; } } }
HW_TIMER_CODE is ISR and occurring ever 10ms. TIMER_update is attempt to implement software timers for additional systems functionality.
After about the 3rd HW_TIMER_CODE execution (between 30 and 50ms) system resets.
No stack corruption is detected in trace.
What silly thing am I overlooking?
You might need to also add USING 2 to the TIMER_Update( ) function, or omit the register bank part in the ISR vector routine.
Maybe I should have said "exclusive or" (XOR).
My point was to ensure that both code sections are identical. If you are going to use the "USING" command, do it in both places. Otherwise don't use the "USING" directive in either place (maybe).
Not that I think that this is your problem, it is just a risk area I saw in your code.
The Keil compiler does not know if one module has a different 'USING' value than another module. When you have a file "Timer.C" and another file "Interrupts.C" and one of them uses a non-standard "USING" directive, then you could have a problem.
Case in point:
/* ** Timer.C */ int Get_Timer1( void ) using 3 { return( TimerCounter ); // 'TimerCounter' maintained elsewhere. }
And then your interrupt service vector table is in another location
/* ** ISR_Vectors.C */ void Ext1_ISR( void ) interrupt EXTERNAL1_ISR { ... val = Get_Timer1( ); if( val > LAUNCH_ICBM_DELAY_TIME ) { Launch_Arsenal( ALL ); } ... }
When T1_ISR launches Timer1( ), there MAY be a mismatch in the register bank.
Again, I'm not saying that this is your problem. Just a risk area.
Are you sure that the uPSD3454 is configured properly? especially with respect to the memory mapping (PSD).
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA