patchAVR Downloader/UploaDEr - Patches: patch #7010, Win32 enhanced bitbang_delay

 
 

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

patch #7010: Win32 enhanced bitbang_delay

Submitter:  Doug <dougy83>
Submitted:  Wed 02 Dec 2009 09:37:40 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  joerg_wunsch Open/Closed:  Closed

Fri 08 Jan 2010 08:31:55 PM UTC, comment #1: 

I implemented it a little differently (I've put the probing
into the bitbang_calibrate_delay routine rather than having
it in bitbang_delay itself), but otherwise thanks for the
nice contribution.

Joerg Wunsch <joerg_wunsch>
Group administrator
Wed 02 Dec 2009 09:37:40 AM UTC, original submission:  

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.


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 */
}

Doug <dougy83>

 

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

No files currently attached

 

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 (Updated the item)
  • -email is unavailable- added by dougy83 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-01-08 joerg_wunsch StatusIn Progress Done
        Open/ClosedOpen Closed
    2010-01-08 joerg_wunsch StatusNone In Progress
        Assigned toNone joerg_wunsch

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code