Hi all,
I'm having problems to get this piece of code to work properly on an atmega328p:
Code:
void ModemEnable( void )
{
// Turn Modem on
PORTB |= _BV( PB2 );
//
Timer1Start();
set_sleep_mode( SLEEP_MODE_IDLE );
do{
sleep_mode();
}while( (T1Timeout == 0) ); // 16.5s per timeout
//
Timer1Stop();
SwUartEnable();
}
It seems that the call to Timer1Start does not have any effect because the MCU gets stuck at the loop, I pause the debugger and I can check that Timer1 is nor configured neither running. Timer1Start works as it should cause I'm using this function in other parts of the code with no trouble. As I'm using size optimizations I assumed that the optimizer was dropping that function call but in the lss file I can check that is not dropping any call:
Code:
void ModemEnable( void )
{
// Turn Modem on
PORTB |= _BV( PB2 );
ad6: 2a 9a sbi 0x05, 2 ; 5
//
Timer1Start();
ad8: 1c d1 rcall .+568 ; 0xd12 <Timer1Start>
set_sleep_mode( SLEEP_MODE_IDLE );
ada: 83 b7 in r24, 0x33 ; 51
adc: 81 7f andi r24, 0xF1 ; 241
ade: 83 bf out 0x33, r24 ; 51
do{
sleep_mode();
ae0: 83 b7 in r24, 0x33 ; 51
ae2: 81 60 ori r24, 0x01 ; 1
ae4: 83 bf out 0x33, r24 ; 51
ae6: 88 95 sleep
ae8: 83 b7 in r24, 0x33 ; 51
aea: 8e 7f andi r24, 0xFE ; 254
aec: 83 bf out 0x33, r24 ; 51
}while( (T1Timeout == 0) ); // 16.5s per timeout
aee: 80 91 92 02 lds r24, 0x0292
af2: 88 23 and r24, r24
af4: a9 f3 breq .-22 ; 0xae0 <ModemEnable+0xa>
//
Timer1Stop();
af6: 1c d1 rcall .+568 ; 0xd30 <Timer1Stop>
SwUartEnable();
}
af8: 00 c0 rjmp .+0 ; 0xafa <SwUartEnable>
In fact, if I set a breakpoint at the beginning of the function ModemEnable, before the call to Timer1Start(), everything works as it should. If there is no breakpoint then the call to Timer1Start has no effect. If compile the code with optimization turned off everything works as expected, no breakpoint needed.
Any idea what can be happening? I'm using AS6+AVR Dragon for debugging and WinAVR-20100110+Eclipse+AVR Plugin for development.
Regards |