[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-libc-dev] [patch #6418] Yet another delay routines
From: |
Weddington, Eric |
Subject: |
RE: [avr-libc-dev] [patch #6418] Yet another delay routines |
Date: |
Sun, 11 Oct 2009 08:58:37 -0600 |
> -----Original Message-----
> From:
> address@hidden
> [mailto:address@hidden
> org] On Behalf Of Timothy Baldwin
> Sent: Sunday, October 11, 2009 8:02 PM
> To: Carlos Lamas; Clarence Risher; Timothy Baldwin;
> address@hidden
> Subject: [avr-libc-dev] [patch #6418] Yet another delay routines
>
>
> Follow-up Comment #3, patch #6418 (project avr-libc):
>
> Rather than generating an error when an integer non-constant
> is passed the
> non-exact macros could form a loop around a constant delay.
>
>
> #define _delay_ms(__ms)
>
>
> do {
>
>
> if (!__builtin_constant_p(F_CPU)) {
>
>
> _DELAY_EMIT_ERROR(__STRINGIFY(F_CPU)
>
>
> " is not a constant for
> _delay_ms");
>
> } else if (__builtin_constant_p(__ms)) {
>
>
> _delay_f_ms(F_CPU, __ms);
>
>
> } else if ((__typeof__((_ms) + 0))0.25 == 0) {
>
>
> __typeof__((__ms) + 0) __ms2 = __ms;
>
>
> while (__ms2--) _delay_f_ms(F_CPU, 1);
>
>
> } else {
>
>
> _DELAY_EMIT_ERROR(__STRINGIFY(__ms)
>
>
> " is not a constant or integer for
> _delay_ms");
>
> }
>
>
> } while (0)
>
The only reason why I wouldn't like this is that the 'while' look adds overhead
to the overall delay, thereby reducing the accuracy of the delay. Why should
avr-libc provide this when a user can essentially create a loop in their own
code that does a variable delay, and then they can control how much overhead
they have in their code. Looping at a 1 millisecond resolution is arbitrary.