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

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

Re: [avr-gcc-list] Compile problem...


From: E. Weddington
Subject: Re: [avr-gcc-list] Compile problem...
Date: Mon, 18 Nov 2002 15:08:16 -0700

On 18 Nov 2002 at 17:28, Tvrtko A. Ursulin wrote:

> 
> What could cause GCC 3.2 to compile this function:
> 
> uint8_t       i2c_send_block(uint8_t address, uint8_t *buffer, uint8_t len)
> {
>  uint8_t      flags;
> 
>  irq_save(flags);
> 
>  if ( i2c_start_transmission(address) )
>   goto fail;
> 
>  do
>  {
>   uint8_t     val = *buffer;          
>   if ( i2c_transmit(val) )
>    goto fail;
>   buffer++;
>  } while ( --len );                   
> 
>  i2c_stop();
>  irq_restore(flags);
>  return I2C_NO_ERROR;
> 
>  fail:
>  i2c_stop();
>  irq_restore(flags);
>  return I2C_ERROR;
> }
> 
> Into this piece of code:
> 
> uint8_t i2c_send_block(uint8_t address, uint8_t *buffer, uint8_t len)
> {
>  28e:   1f 93           push    r17
>  290:   18 2f           mov     r17, r24
>         uint8_t flags;
> 
>         irq_save(flags);
>  292:   8f b7           in      r24, 0x3f       ; 63
>  294:   f8 94           cli
> 
>         if ( i2c_start_transmission(address) )
>  296:   92 df           rcall   .-220           ; 0x1bc
>  298:   81 2f           mov     r24, r17
>  29a:   a4 df           rcall   .-184           ; 0x1e4
>  29c:   99 27           eor     r25, r25
>                 goto fail;
> 
>         do
>         {
>                 uint8_t val = *buffer;
>                 if ( i2c_transmit(val) )
>                         goto fail;
>                 buffer++;
>         } while ( --len );
> 
>         i2c_stop();
>         irq_restore(flags);
>         return I2C_NO_ERROR;
> 
>         fail:
>         i2c_stop();
>         irq_restore(flags);
>         return I2C_ERROR;
> }
>  29e:   1f 91           pop     r17
>  2a0:   08 95           ret
> 
> 

Usually, in a case like this, in your code:

if ( i2c_start_transmission(address) )
  goto fail;

the condition would *always* compile to be true, hence the block goto 
fail would always be the path taken and all code in between would be 
removed.

So, take a look at i2c_start_transmission() and see if you have a bug 
that the causes the condition to always be true.

Eric

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



reply via email to

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