[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avrdude-dev] Fwd: Win32 enhanced bitbang_delay
From: |
Doug Brown |
Subject: |
[avrdude-dev] Fwd: Win32 enhanced bitbang_delay |
Date: |
Wed, 2 Dec 2009 19:11:33 +1000 |
Hi avrdude dev,
I read that the bitbang_delay is not calibrated for Win32 so I wrote the
following code. It uses the performance counters which are high accuracy
hardware counters (3.6MHz on my 5 yr old laptop). If the counters are not
available, it falls back to the uncalibrated delay method. Seems to have a
~3us overhead on my laptop.
Could someone incorporate this into the SVN? I've got no idea how to, & I'm
not on the dev team.
Regards,
Doug.
void bitbang_delay(int us)
{
#if defined(WIN32NATIVE)
static LARGE_INTEGER freq;
static enum {eNotInit, eInitOK, eInitFail}freqInit = eNotInit;
if(freqInit == eNotInit)
{
if(!QueryPerformanceFrequency(&freq))
freqInit = eInitFail; // perf counters not available
else
freqInit = eInitOK;
}
if(freqInit == eInitOK)
{
LARGE_INTEGER countNow, countEnd;
QueryPerformanceCounter(&countNow);
countEnd.QuadPart = countNow.QuadPart + freq.QuadPart * us / 1000000ll;
while (countNow.QuadPart < countEnd.QuadPart)
QueryPerformanceCounter(&countNow);
}
else // no performance counters -- run normal uncalibrated delay
{
volatile int del = us * delay_decrement;
while (del > 0)
del--;
}
#else
volatile int del = us * delay_decrement;
while (del > 0)
del--;
#endif /* WIN32NATIVE */
}
- [avrdude-dev] Fwd: Win32 enhanced bitbang_delay,
Doug Brown <=