|
Lines 1-89
Link Here
|
| 1 |
--- picport.cc.orig Thu Apr 29 00:08:10 2004 |
1 |
--- picport.cc.orig 2009-12-11 16:33:39.000000000 -0500 |
| 2 |
+++ picport.cc Fri Jul 8 21:46:07 2005 |
2 |
+++ picport.cc 2009-12-11 16:33:53.000000000 -0500 |
| 3 |
@@ -40,7 +40,7 @@ |
3 |
@@ -33,7 +33,6 @@ |
| 4 |
#include <unistd.h> |
4 |
#include <string> |
| 5 |
#include <termios.h> |
|
|
| 6 |
#include <sysexits.h> |
| 7 |
-#include <string.h> |
| 8 |
+#include <string> |
| 9 |
#include <sched.h> |
| 10 |
|
5 |
|
| 11 |
#include "picport.h" |
6 |
#include <sys/ioctl.h> |
| 12 |
@@ -54,6 +54,11 @@ |
7 |
-#include <sys/io.h> |
| 13 |
unsigned int picport::tsc_1000ns = 0; |
8 |
#include <fcntl.h> |
| 14 |
int picport::use_nanosleep = -1; |
9 |
#include <errno.h> |
| 15 |
|
10 |
#include <time.h> |
| 16 |
+// Extra delays for long cables, in us |
11 |
@@ -159,8 +158,6 @@ |
| 17 |
+int picport::t_on = 0; |
12 |
// Not root. Cannot use realtime scheduling. |
| 18 |
+int picport::t_off = 0; |
13 |
use_nanosleep = 0; |
| 19 |
+int picport::t_edge = 0; |
|
|
| 20 |
+ |
| 21 |
void |
| 22 |
picport::set_clock_data (int rts, int dtr) |
| 23 |
{ |
| 24 |
@@ -102,7 +107,7 @@ |
| 25 |
// Before first call to set_clock_data, read the modem status. |
| 26 |
ioctl (fd, TIOCMGET, &modembits); |
| 27 |
set_clock_data (0, 0); |
| 28 |
- usleep (50); |
| 29 |
+ usleep (50+t_edge); |
| 30 |
// Check the CTS. If it is up, even when we just lowered DTR, |
| 31 |
// we probably are not talking to a JDM type programmer. |
| 32 |
int i; |
| 33 |
@@ -200,13 +205,13 @@ |
| 34 |
cerr << "Unable to start break on tty " << tty << ":" << strerror (e) << endl; |
| 35 |
exit (EX_IOERR); |
| 36 |
} |
| 37 |
- usleep (10); |
| 38 |
+ usleep (10+t_off); |
| 39 |
} |
| 40 |
|
| 41 |
picport::~picport () |
| 42 |
{ |
| 43 |
ioctl (fd, TIOCCBRK, 0); |
| 44 |
- usleep (1); |
| 45 |
+ usleep (1+t_off); |
| 46 |
tcsetattr (fd, TCSANOW, &saved); |
| 47 |
close (fd); |
| 48 |
delete [] portname; |
| 49 |
@@ -216,15 +221,15 @@ |
| 50 |
{ |
| 51 |
set_clock_data (0, 0); |
| 52 |
ioctl (fd, TIOCCBRK, 0); |
| 53 |
- usleep (50); |
| 54 |
+ usleep (50+t_off); |
| 55 |
ioctl (fd, TIOCSBRK, 0); |
| 56 |
- usleep (10); |
| 57 |
+ usleep (10+t_on); |
| 58 |
addr = 0; |
| 59 |
} |
| 60 |
|
| 61 |
void picport::delay (long ns) |
| 62 |
{ |
| 63 |
- if (1 == use_nanosleep) { |
| 64 |
+ if (1 == use_nanosleep && !t_edge) { |
| 65 |
timespec ts = {ns / 1000000000, ns % 1000000000}, ts2; |
| 66 |
while (nanosleep (&ts, &ts2) && EINTR == errno) |
| 67 |
ts = ts2; |
| 68 |
@@ -232,7 +237,7 @@ |
| 69 |
} |
14 |
} |
|
|
15 |
- if (iopl (3)) |
| 16 |
- disable_interrupts = 0; |
| 70 |
|
17 |
|
| 71 |
#ifdef RDTSC_WORKS |
18 |
#ifdef CPU_SETSIZE |
| 72 |
- if (tsc_1000ns > 1) { |
19 |
// When computing the delay loops, we do not want the cpu's to change. |
| 73 |
+ if (tsc_1000ns > 1 && !t_edge) { |
|
|
| 74 |
unsigned long a1, d1, a2, d2; |
| 75 |
asm volatile("rdtsc":"=a" (a1), "=d" (d1)); |
| 76 |
d2 = d1; |
| 77 |
@@ -259,10 +264,10 @@ |
| 78 |
volatile int i; |
| 79 |
gettimeofday (&tv1, 0); |
| 80 |
tv2.tv_sec = tv1.tv_sec; |
| 81 |
- tv2.tv_usec = 0xffffffff & (tv1.tv_usec + 1 + (ns + 999)/1000); |
| 82 |
+ tv2.tv_usec = 0xffffffff & (tv1.tv_usec + 1 + (ns + 999)/1000+t_edge); |
| 83 |
if (tv2.tv_usec < tv1.tv_usec) |
| 84 |
tv2.tv_sec++; |
| 85 |
- for (i = 0; i < 10000; i++) { |
| 86 |
+ for (i = 0; i < 10000 || t_edge; i++) { |
| 87 |
gettimeofday (&tv1, 0); |
| 88 |
if (tv1.tv_sec > tv2.tv_sec |
| 89 |
|| tv1.tv_sec == tv2.tv_sec && tv1.tv_usec >= tv2.tv_usec) |