delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2008/03/30/10:48:31

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: RayeR <glaux AT centrum DOT cz>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: timing problems using uclock()
Date: Sun, 30 Mar 2008 08:36:22 -0700 (PDT)
Organization: http://groups.google.com
Lines: 34
Message-ID: <13387b91-554d-4e43-8389-2388f03ba2e4@x41g2000hsb.googlegroups.com>
References: <532aac2f-c863-49f4-8d4b-43b22350f9d8 AT e23g2000prf DOT googlegroups DOT com>
NNTP-Posting-Host: 89.176.208.108
Mime-Version: 1.0
X-Trace: posting.google.com 1206891383 13372 127.0.0.1 (30 Mar 2008 15:36:23 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Sun, 30 Mar 2008 15:36:23 +0000 (UTC)
Complaints-To: groups-abuse AT google DOT com
Injection-Info: x41g2000hsb.googlegroups.com; posting-host=89.176.208.108;
posting-account=Q0wMHAoAAADjYrghh94FTf6YnbpTqZgp
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1.12)
Gecko/20080201 SeaMonkey/1.1.8,gzip(gfe),gzip(gfe)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I have also found some weird behavior of uclock()
I made udelay() function based on some other function using clock()
I use it for I2C and SPI communication under pure DOS. I don't know
what
exactly goes wrong but when using udelay() it sometimes trashes
communication
with SMBus host and it gets locked. If I replace say udelay(1000) by
delay(1) it doesn't
never happed. I tried udelay in a loops and measure run time but it
seems to be OK.
Maybe there's some random jitter. Any Idea how to make a precise
timer?

//***************** wait for delay us
***************************************
void udelay(DWord usec)                // based on precise 1us timer
uclock(), usable for 10us resolution
{                                      // works under DOS/Win9X/NT but
not Win3.x
  volatile uclock_t cl_time;
  volatile uclock_t start_time=uclock();
  if (usec==0)                         // pokud je prodleva nulova
    return;                            // tak hned skonci
  cl_time=(usec*UCLOCKS_PER_SEC)/977000;
  while (1)                            // cekaci smycka
    {
    clock_t elapsed=uclock()-start_time;
    if (elapsed>=cl_time)              // pokud citac dosel k cilove
hodnote
      break;                           // tak skonci
    __dpmi_yield();                    // vzdej se zbytku slice time
ve prospech jinych procsu
    }
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019