I'm using the True-Time Simulator & Real Time Debugger Ver. 6.1 Build 9279.
For some reason, my code keeps breaking in this function on the while loop.
void delay_ms(unsigned short time){ //max delay time should be 65.535 seconds unsigned long count; //enable_timer2_interrupt(); t2Count = 0; set_timer_delay(&count); while(!timer_expired_delay(count, time)){;} //if(startTCPIPflash==FALSE) // DISABLE_INT_TIMER2; }
Please help me figure out what to look for to fix this problem.
It's odd because it works immediatly after initialization, but then a short while later, my 1ms timer interrupts and trys to write data to an LCD. That function calls this delay_ms() function and fails.
Okay, I figured out that when putting "EnableInterrupts" right before my call to delay_ms(), it works.
So, this means something is disabling my interrupts after I've enabled them in my initialization routine. I can't find where though. Any ideas on what to look for?
Okay, I think I'm getting closer. I believe my timer_1_interrupt function is disabling interrupts. Is this normal? Or did the compiler tell it to do this because I'm calling a function in the interrupt that is also called outside the interrupt?
My whole problem occurs when MAIN_service_routine() trys to call delay_ms() which relies on this interrupt (see below). Simply adding "EnableInterrupts;" before my call to MAIN_service_routine() fixes the problem. However, I'd like to understand why this is needed.
/* ================================================================================================= FUNCTION DESCRIPTION:== Interrupt - Hardware Timer 1 - Configured to trigger every 1ms.== Triggers all Service Routines.==== OUTPUTS:== N/A== =============================================================================================*/__interrupt void timer_1_interrupt(void) { /* Local Variables. */ static BLN service_routine_active = FALSE; DEBUG_checkpoint( CP_ENTER_timer_1_interrupt ); //Mark Checkpoint. RESET_TIMER1; //Reset timer (allow this interrupt to occur again). t1Count++; //Update ms counter used for software timers. /* Check if Service Routine already processing (prevent undesired recursion). */ if( service_routine_active == FALSE ) { service_routine_active = TRUE; //Mark service routine active. MAIN_service_routine(); //Call Main Service Routine. service_routine_active = FALSE; //Mark service routine inactive. } DEBUG_checkpoint( CP_EXIT_timer_1_interrupt ); //Mark Checkpoint. } /* timer_1_interrupt() */