summaryrefslogtreecommitdiff
path: root/cross/icdprog/patches/patch-ab
blob: 201d8b33f369c30de3e2e45960cba818aa749fe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$NetBSD: patch-ab,v 1.3 2006/11/28 16:20:48 tv Exp $

--- icd.c.orig	2001-03-29 05:29:01.000000000 -0500
+++ icd.c
@@ -12,9 +12,16 @@
 
 #define BAUDRATE B57600
 
+#if defined(__DragonFly__) && !defined(O_SYNC)
+#define O_SYNC O_FSYNC
+#endif
+
 int icd_fd;  /* file descriptor for serial port */
 int controller_type=-1;
 
+#ifdef __INTERIX
+#define udelay usleep
+#else
 void udelay(unsigned usec)
 {
 	/* wait for msec milliseconds or more ... */
@@ -26,6 +33,7 @@ void udelay(unsigned usec)
 
 	nanosleep(&time,NULL);
 }
+#endif
 
 void dtr_set()
 {
@@ -278,7 +286,7 @@ int icd_init(char *port)
 {
 	struct termios oldtio, newtio;
 
-	if((icd_fd=open(port, O_NOCTTY | O_RDWR | O_SYNC)) == -1) {
+	if((icd_fd=open(port, O_NOCTTY | O_RDWR | O_SYNC | O_NONBLOCK)) == -1) {
 		perror("Error opening device:");
 		return -1;
 	}
@@ -286,10 +294,11 @@ int icd_init(char *port)
 	tcgetattr(icd_fd, &oldtio);
 
 	memset(&newtio,0, sizeof(newtio));
-	newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;
+	newtio.c_cflag = CS8 | CLOCAL | CREAD;
 	newtio.c_iflag = IGNPAR;
 	newtio.c_oflag =  0;
 	newtio.c_lflag =  0;
+	newtio.c_ispeed = newtio.c_ospeed = BAUDRATE;
 
 	newtio.c_cc[VTIME] = 20;
         newtio.c_cc[VMIN] = 0;
@@ -297,6 +306,8 @@ int icd_init(char *port)
 	tcflush(icd_fd, TCIFLUSH);
 	tcsetattr(icd_fd, TCSANOW, &newtio);
 
+	fcntl(icd_fd, F_SETFL, 0); /* clear nonblock */
+	
 	icd_hw_reset();
 
 	rts_set();