bugAVR C Runtime Library - Bugs: bug #34278, Seemingly overzealous...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #34278: Seemingly overzealous "__builtin_avr_delay_cycles expects an integer constant"

Submitter:  Yann Dirson <ydirson>
Submitted:  Mon 12 Sep 2011 09:55:32 PM UTC
   
 
Category:  Header Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Header files
Status:  Invalid Assigned to:  joerg_wunsch
Percent Complete:  0% Open/Closed:  Closed
Release:  1.7.1 Fixed Release:  None

Wed 14 Sep 2011 07:52:14 AM UTC, comment #2: 

Thanks for the archive, now I finally see the problem.  Sorry
for being blind in the first place.

The compiler is correct.  The code is:


// Delay in 1/10's of a millisecond
void msleep(INT16U ms)
    { /* This loop does not work with optimization != 0. Therefore we use
         avr-libc _delay routines K. Schwichtenberg
        INT16S i,j;
        for (i = 1; i < ms; i++)
                for (j = 1; j < ONETENTH_MS; j++); / * to give 1/10 ms*/
        _delay_ms(ms); // Changed K. Schwichtenberg
    }


Thus, _delay_ms() is called with "ms" which is a function
parameter.  This is not supported (and has never been, but
with the current implementation, you finally get an error
while the code simply didn't do what it was expected to
do before).

A correct (with respect to what the comment above the
function says) implementation would look like:


// Delay in 1/10's of a millisecond
void msleep(INT16U ms)
{
  while (ms-- != 0)
    _delay_ms(0.1);
}


In addition (and unlike the original comment), optimization
must be turned on for any of the _delay_us/ms functions
to work correctly.

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 13 Sep 2011 08:04:36 AM UTC, comment #1: 

The strange thing is I cannot reproduce that at all.

I've got another report owhere this happened, but there,
-ffreestanding was in effect, preventing the compiler from
resolving the calls to fabs() and ceil() at compile-time.
We have to find a solution to that problem.

In your case, there's no -ffreestanding though, and if I
compile a smimple test program using your compiler options,
all works fine.

Can you please run the compiler with the additional option
-da, then pack all the StdDefs.* files into an archive, and
attach that archive to this bug tracker?

Joerg Wunsch <joerg_wunsch>
Group administrator
Mon 12 Sep 2011 09:55:32 PM UTC, original submission:  

The problem occurs while compiling examples/atmel_key/ in simulavr (master from git), on a Debian testing amd64 host:

make[2]: Entering directory `/work/yann/elec/avr/simulavr/examples/atmel_key'
avr-gcc -mmcu=atmega128 -I. -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes  -c -o StdDefs.o StdDefs.c
StdDefs.c: In function ‘putstr’:
StdDefs.c:122:4: warning: pointer targets in passing argument 1 of ‘strlen’ differ in signedness
/usr/lib/gcc/avr/4.5.3/../../../avr/include/string.h:133:15: note: expected ‘const char ’ but argument is of type ‘CHARU
In file included from StdDefs.c:8:0:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h: In function ‘msleep’:
/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:153:28: error: __builtin_avr_delay_cycles expects an integer constant.
make[2]: * [StdDefs.o] Error 1


The _delay_ms() cpp expansion looks correct, though - seems strange at first sight:

# 132 "/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h" 3
void
_delay_ms(double __ms)
{
 uint16_t __ticks;
 double __tmp ;

 uint32_t __ticks_dc;
 extern void __builtin_avr_delay_cycles(unsigned long);
 __tmp = ((4000000UL) / 1e3) * __ms;
# 150 "/usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h" 3
  __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));

Yann Dirson <ydirson>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #23972:  stddefs.tgz added by ydirson (54KiB - application/x-compressed-tar - The -da archive)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  • -email is unavailable- added by ydirson (Submitted the item)
  •  

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-09-14 joerg_wunsch StatusNeed Info Invalid
        Assigned toNone joerg_wunsch
        Open/ClosedOpen Closed
    2011-09-13 ydirson Attached File- Added stddefs.tgz, #23972
    2011-09-13 joerg_wunsch StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code