Browse Source

Plan 9 from Bell Labs 2010-01-27

David du Colombier 14 years ago
parent
commit
63bddbdf72
2 changed files with 22 additions and 9 deletions
  1. 6 3
      sys/src/cmd/usb/serial/ftdi.c
  2. 16 6
      sys/src/cmd/usb/serial/serial.c

+ 6 - 3
sys/src/cmd/usb/serial/ftdi.c

@@ -474,7 +474,8 @@ ftgettype(Serial *ser)
 		 * to 0x200 when serial is 0.
 		 */
 		if(dno < 0x500)
-			fprint(2, "serial: warning: dno too low for multi-interfacedevice\n");
+			fprint(2, "serial: warning: dno too low for "
+				"multi-interface device\n");
 	} else if(dno < 0x200) {
 		/* Old device.  Assume it is the original SIO. */
 		ser->type = SIO;
@@ -569,6 +570,8 @@ wait4data(Serial *ser, uchar *data, int count)
 		count = ser->ndata;
 		ser->ndata = 0;
 	}
+	assert(count >= 0);
+	assert(ser->ndata >= 0);
 	memmove(data, ser->data, count);
 	if(ser->ndata != 0)
 		memmove(ser->data, ser->data+count, ser->ndata);
@@ -654,7 +657,7 @@ epreader(void *u)
 	} while(rcount >= 0 || (rcount < 0 && strstr(err, "timed out") != nil));
 
 	if(rcount < 0)
-		fprint(2, "error reading: %r\n");
+		fprint(2, "%s: error reading %s: %r\n", argv0, ser->fs.name);
 	free(p);
 	sendp(c, nil);
 	closedev(ser->dev);
@@ -691,7 +694,7 @@ statusreader(void *u)
 			recvul(ser->gotdata);
 		}
 	}
-	free(a);
+	/* don't free a; epreader may still be using it. */
 	free(c);
 	closedev(ser->dev);
 }

+ 16 - 6
sys/src/cmd/usb/serial/serial.c

@@ -230,7 +230,12 @@ serialctl(Serial *p, char *cmd)
 			}
 			break;
 		}
-		if (nop)
+		/*
+		 * don't print.  the condition is harmless and the print
+		 * splatters all over the display.
+		 */
+		USED(nop);
+		if (0 && nop)
 			fprint(2, "serial: %c, unsupported nop ctl\n", c);
 	}
 	if(drain)
@@ -413,7 +418,7 @@ dread(Usbfs *fs, Fid *fid, void *data, long count, vlong offset)
 	char *e, *buf, *err;	/* change */
 	Qid q;
 	Serial *ser;
-	static int errrun;
+	static int errrun, good;
 
 	q = fid->qid;
 	path = fid->qid.path & ~fs->qid;
@@ -436,6 +441,7 @@ dread(Usbfs *fs, Fid *fid, void *data, long count, vlong offset)
 			if(usbdebug >= 3)
 				dsprint(2, "serial: reading: %ld\n", count);
 
+			assert(count > 0);
 			if(ser->wait4data != nil)
 				rcount = ser->wait4data(ser, data, count);
 			else{
@@ -450,15 +456,19 @@ dread(Usbfs *fs, Fid *fid, void *data, long count, vlong offset)
 			 */
 			if(rcount < 0) {
 				snprint(err, Serbufsize, "%r");
-				if (++errrun > 1000) {
+				++errrun;
+				sleep(20);
+				if (good > 0 && errrun > 10000) {
 					/* the line has been dropped; give up */
 					qunlock(ser);
-					fprint(2, "%s: line is gone: %r\n",
-						argv0);
+					fprint(2, "%s: line %s is gone: %r\n",
+						argv0, ser->fs.name);
 					threadexitsall("serial line gone");
 				}
-			} else
+			} else {
 				errrun = 0;
+				good++;
+			}
 			if(usbdebug >= 3)
 				dsprint(2, "serial: read: %s %ld\n", err, rcount);
 		} while(rcount < 0 && strstr(err, "timed out") != nil);