Browse Source

more RTS code on avalon.c/h

Xiangfu 13 years ago
parent
commit
cf65548866
2 changed files with 22 additions and 5 deletions
  1. 20 5
      driver-avalon.c
  2. 2 0
      driver-avalon.h

+ 20 - 5
driver-avalon.c

@@ -114,11 +114,12 @@ static int avalon_gets(uint8_t *buf, int fd, struct timeval *tv_finish,
 	int read_amount = AVALON_READ_SIZE;
 	int read_amount = AVALON_READ_SIZE;
 	bool first = true;
 	bool first = true;
 
 
-	int cts = get_serial_cts(fd);
+	/* FIXME: we should set RTS to 0 and CTS to be 1, before read? */
+	int done = avalon_task_done(fd);
 	if (opt_debug)
 	if (opt_debug)
-		applog(LOG_DEBUG, "Avalon bulk task statue: %d", cts);
-	if (cts) {
-		/* TODO return here. and tell avalon all task are done */
+		applog(LOG_DEBUG, "Avalon bulk task statue: %d", done);
+	if (done) {
+		/* TODO: return here. and tell avalon all task are done */
 	}
 	}
 	// Read reply 1 byte at a time to get earliest tv_finish
 	// Read reply 1 byte at a time to get earliest tv_finish
 	while (true) {
 	while (true) {
@@ -184,11 +185,25 @@ static int avalon_send_task(int fd, const void *buf, size_t bufLen)
 {
 {
 	size_t ret;
 	size_t ret;
 
 
+	/* FIXME: we should set RTS to 1 and wait CTS became 1, before write? */
+	int empty = avalon_buffer_empty(fd);
+	if (empty < 0) {
+		/* FIXME: ERROR */
+	}
+	if (!empty) {
+		/* FIXME: the buffer was full */
+	}
+
 	ret = write(fd, buf, bufLen);
 	ret = write(fd, buf, bufLen);
 	if (unlikely(ret != bufLen))
 	if (unlikely(ret != bufLen))
 		return 1;
 		return 1;
 
 
-	/* FIXME: there should be a nanosleep() according to the document */
+	/* From the document. avalon needs some time space between two write */
+	struct timespec p;
+	p.tv_sec = 0;
+	p.tv_nsec = 5 * 1000;
+	nanosleep(&p, NULL);
+
 	return 0;
 	return 0;
 }
 }
 
 

+ 2 - 0
driver-avalon.h

@@ -171,4 +171,6 @@ struct AVALON_INFO {
 #define AVA_GETS_RESTART 1
 #define AVA_GETS_RESTART 1
 #define AVA_GETS_TIMEOUT 2
 #define AVA_GETS_TIMEOUT 2
 
 
+#define avalon_buffer_empty(fd)	get_serial_cts(fd)
+#define avalon_task_done(fd)	get_serial_cts(fd)
 #endif	/* AVALON_H */
 #endif	/* AVALON_H */