avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] broken compiler/avrlibc build symptom?


From: Michael Hennebry
Subject: Re: [avr-chat] broken compiler/avrlibc build symptom?
Date: Tue, 30 Sep 2014 15:10:44 -0500 (CDT)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

On Wed, 24 Sep 2014, Joerg Wunsch wrote:

What you can do is:

#include <stdint.h>

static void
delay_us(uint8_t us)
{
 while (--us != 0)
   _delay_us(1);
}

To reduce the computational damage somewhat:
static void
delay_us(uint8_t us)
{
    #define cyclesforus(us) \
       ((us)*(uint16_t)((uint64_t)(F_CPU)*0x100/1000000)/0x100)

    #define kase(x) case x: \
        __builtin_avr_delay_cycles(cyclesforus(x)-cyclesforus(x-1))
    switch (us & 0x0F) {
    kase(15); kase(14); kase(13); kase(12);
    kase(11); kase(10); kase( 9); kase( 8);
    kase( 7); kase( 6); kase( 5); kase( 4);
    kase( 3); kase( 2); kase( 1); case 0: ;
    }
    if(us & 0x10) _delay_us(0x10);
    if(us & 0x20) _delay_us(0x20);
    if(us & 0x40) _delay_us(0x40);
    if(us & 0x80) _delay_us(0x80);
}
....
  delay_us(42);
  delay_us(43);

While this is quite customary to do in the millisecond range
(using _delay_ms(1)), it's questionable though whether your
call and computational overhead would not rather twice the
delays in the microsecond range.

--
Michael   address@hidden
"SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then."   --   John Woods



reply via email to

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