avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Is this a Bug??????


From: David Breeze
Subject: Re: [avr-gcc-list] Is this a Bug??????
Date: Wed, 31 Jul 2002 14:08:47 +0100

Yep thats the reason for the "volatile" key word as used in the GNU (and other) 
compilers.
You will see this particular chestnut regularly on AVR Freaks and other AVR 
sites.  I understand someone is already hard at work to provide an FAQ page and 
this will probably be somewhere near the top, as it catches out a lot of people.

DaveB

>>> Lorne Gutz <address@hidden> 31 July 2002 13:21:17 >>>

This C code produced the assembler below.  The 2
write bits to PORTB are just added to help me
identify the code in assmebler.
 
C   code
_________________________________________
cbi( PORTB, 0 );    // sos send
        while( timer_flag == 0 );  //wait for timer
cbi( PORTB, 1 );    // seakey send



In the assembley code, the variable 'timer_flag'
gets put into register r24 and then gets tested
repetedly.  The value of timer_flag never gets
reloaded into r24 the program hangs.


assemble code
______________________________--
/* #NOAPP */
        lds r24,timer_flag
.L28:
/* #APP */
        cbi 24,0
/* #NOAPP */
.L37:
        tst r24
        breq .L37
/* #APP */
        cbi 24,1
/* #NOAPP */
        ldi r24,lo8(0)
        rjmp .L28




The value of timer_flag is being incremented in an
interrupt ISR which works fine.


SIGNAL( SIG_OUTPUT_COMPARE1A )
{
    extern uint8_t timer_flag;
        
    timer_flag++;
}

and the assembler code of this function shows that
timer_flag is being incremented.

assemble code of ISR
_____________________________________
        lds r24,timer_flag
        subi r24,lo8(-(1))
        sts timer_flag,r24



Well then I figured out a work around.  I declared
timer_flag as volatile, and BOB's your uncle, it
works.   Take a look at the assmebler code now.
it reloads r24 before it tests for zero.
_____________________________________________
.L37:
/* #APP */
        cbi 24,1
/* #NOAPP */
.L47:
        lds r24,timer_flag
        tst r24
        breq .L37
        sts timer_flag,__zero_reg__
        rjmp .L28



Well another long days work on the AVR

cheers
Lorne

avr-gcc-list at http://avr1.org

This e-mail is intended only for the person(s)
to whom it is addressed.
If an addressing or transmission error has misdirected
this e-mail,
please notify the author by replying to this e-mail.

If you are not the intended recipient
you must not use, disclose, copy, print
or rely on this e-mail.

Joy Mining Machinery Ltd may monitor
outgoing and incoming e-mails and other telecommunications
on its e-mail and telecommunication systems.

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]