source: ISPProgrammer/ISPprog/Delays.pas

Last change on this file was 363, checked in by chronos, 13 years ago
  • Added: Package ISPProgrammer for in-system programming of various chips. Supports Dallas ISP protocol, Presto, Rabbit RFU and some others Atmel devices.
File size: 2.2 KB
Line 
1unit Delays;
2
3{$MODE Delphi}
4
5interface
6
7procedure WaitS(x:integer);
8procedure WaitMS(x:integer);
9procedure WaitUS(x:integer);
10procedure WaitNS(x:integer);
11
12procedure Tic(var t:Int64);
13function TocMS(t:Int64):Int64;
14function TocUS(t:Int64):Int64;
15function TocNS(t:Int64):Int64;
16
17implementation
18
19uses
20 {$IFDEF Windows}Windows,{$ENDIF}LCLIntf, SysUtils, DateUtils, Classes;
21
22var
23 persec:Int64;
24
25procedure WaitS(x:integer);
26begin
27 Sleep(x * 1000);
28end;
29
30procedure WaitMS(x:integer);
31begin
32 Sleep(x);
33end;
34
35procedure WaitUS(x:integer);
36var
37 f1,f2,c:Int64;
38begin
39 {$IFDEF Windows}
40 f1:=0; f2:=0;
41 QueryPerformanceCounter(f1);
42 c:=f1+(persec*x) div 1000000;
43 if c = f1 then
44 c:=f1 + 1;
45 repeat
46 QueryPerformanceCounter(f2);
47 until f2>=c;
48 {$ELSE}
49 Sleep(X div 1000);
50 {$ENDIF}
51end;
52
53procedure WaitNS(x:integer);
54var
55 f1,f2,c:Int64;
56begin
57 {$IFDEF Windows}
58 f1:=0; f2:=0;
59 QueryPerformanceCounter(f1);
60 c:=f1+(persec*x) div 1000000000;
61 if c = f1 then
62 c:=f1 + 1;
63 repeat
64 QueryPerformanceCounter(f2);
65 until f2>=c;
66 {$ELSE}
67 Sleep(X div 1000);
68 {$ENDIF}
69end;
70
71procedure Tic(var t:Int64);
72begin
73 {$IFDEF Windows}
74 QueryPerformanceCounter(t);
75 {$ELSE}
76 T := Trunc(Now / OneMillisecond);
77 {$ENDIF}
78end;
79
80function TocMS(t:Int64):Int64; {returns time difference in ms}
81var
82 t2:Int64;
83begin
84 {$IFDEF Windows}
85 t2:=0;
86 QueryPerformanceCounter(t2);
87 Result:=((t2 - t) * 1000) div persec;
88 {$ELSE}
89 T := Trunc(Now / OneMillisecond);
90 {$ENDIF}
91end;
92
93function TocUS(t:Int64):Int64; {returns time difference in us}
94var
95 t2:Int64;
96begin
97 {$IFDEF Windows}
98 t2:=0;
99 QueryPerformanceCounter(t2);
100 Result:=((t2 - t) * 1000000) div persec;
101 {$ELSE}
102 T := Trunc(Now / OneMillisecond) * 1000;
103 {$ENDIF}
104end;
105
106function TocNS(t:Int64):Int64; {returns time difference in ns}
107var
108 t2:Int64;
109begin
110 {$IFDEF Windows}
111 t2:=0;
112 QueryPerformanceCounter(t2);
113 Result:=((t2 - t) * 1000000000) div persec;
114 {$ELSE}
115 T := Trunc(Now / OneMillisecond) * 1000000;
116 {$ENDIF}
117end;
118
119initialization
120 persec:=0;
121{$IFDEF Windows}
122 QueryPerformanceFrequency(persec);
123{$ENDIF}
124
125end.
Note: See TracBrowser for help on using the repository browser.