[aadk-commits] dbailey: toolchain/trunk r139 - in /toolchain/trunk/ldrviewer: ldr.c ldrviewer.c

aadk-commits at lists.digium.com aadk-commits at lists.digium.com
Tue Jan 30 13:08:25 MST 2007


Author: dbailey
Date: Tue Jan 30 14:08:24 2007
New Revision: 139

URL: http://svn.digium.com/view/aadk?view=rev&rev=139
Log:
Added patch that allows USB to serial adapters to function
Added timeout to character read so that program does not hang when booting an unresponsive board. 
Made return of the program meaningful so that scripts can react if the serial boot fails. 
Added more feedback to user.

Modified:
    toolchain/trunk/ldrviewer/ldr.c
    toolchain/trunk/ldrviewer/ldrviewer.c

Modified: toolchain/trunk/ldrviewer/ldr.c
URL: http://svn.digium.com/view/aadk/toolchain/trunk/ldrviewer/ldr.c?view=diff&rev=139&r1=138&r2=139
==============================================================================
--- toolchain/trunk/ldrviewer/ldr.c (original)
+++ toolchain/trunk/ldrviewer/ldr.c Tue Jan 30 14:08:24 2007
@@ -6,7 +6,7 @@
  *               Based on the "Visual DSP++ 4.0 Loader Manual"
  *               and misc Blackfin HRMs
  *
- * Rev:          $Id: ldr.c,v 1.3 2006/10/19 20:35:48 vapier Exp $
+ * Rev:          $Id: ldr.c,v 1.2 2006/09/22 01:44:59 vapier Exp $
  *
  * Modified:     Copyright 2006 Analog Devices Inc.
  *
@@ -358,16 +358,21 @@
 {
 	unsigned char autobaud[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
 	int fd;
+        fd_set readfs;    /* file descriptor set */
+	int maxfd;
+        struct timeval st_timeout;
+
+	int byte_sent_count = 0; 
 	ssize_t ret;
 	size_t d, b, baud, sclock;
 
 	setbuf(stdout, NULL);
 
-	printf("Opening %s ... ", tty);
+	printf("Opening %s ...", tty);
 	fd = open(tty, O_RDWR);
 	if (fd == -1) {
 canned_failure:
-		perror("Failed");
+		perror("Failed opening port - Is the serial port connection operational???");
 		return -1;
 	}
 	printf("OK!\n");
@@ -379,15 +384,42 @@
 	printf("OK!\n");
 
 	printf("Trying to read autobaud ... ");
+	/* Add a timeout here if nothing is incoming */
+
+        /* set timeout value for input wait */
+        st_timeout.tv_usec = 0;  /* milliseconds */
+        st_timeout.tv_sec  = 5;  /* seconds */
+
+	FD_SET(fd, &readfs);  	/* set testing for source 1 */
+	maxfd = fd +1;  	/* maximum bit entry (fd) to test */
+        ret = select(maxfd, &readfs, NULL, NULL, &st_timeout);
+        if (0 == ret || !FD_ISSET(fd, &readfs)){	/* timeout occurred */
+		printf("Giving up on waiting for a response.\n");
+		return -1;
+	}
+
 	ret = read(fd, autobaud, 4);
-	if (ret != 4)
-		goto canned_failure;
+	if (ret != 4) {
+         if ((autobaud[0]==0xBF) && (ret > 1)) {
+           ret += read(fd, &autobaud[ret], 4-ret);
+           /*
+           printf(" after 2nd read ret = %d\n", ret);
+
+           printf(" Data %02x %02x %02x %02x \n",
+                  autobaud[0],
+                  autobaud[1],
+                  autobaud[2],
+                  autobaud[3]);
+           */
+         }
+         if ( ret != 4 ) goto canned_failure;
+	}
 	printf("OK!\n");
 
 	printf("Checking autobaud ... ");
 	if (autobaud[0] != 0xBF || autobaud[3] != 0x00) {
-		printf("Failed: wanted {0xBF,..,..,0x00} but got {0x%02X,[0x%02X],[0x%02X],0x%02X}\n",
-			autobaud[0], autobaud[1], autobaud[2], autobaud[3]);
+		printf("Failed: wanted {0xBF,..,..,0x00} but got {0x%02X,..,..,0x%02X}\n",
+			autobaud[0], autobaud[3]);
 		return -1;
 	}
 	printf("OK!\n");
@@ -395,12 +427,15 @@
 	/* bitrate = SCLK / (16 * Divisor) */
 	baud = _tty_get_baud(fd);
 	sclock = baud * 16 * (autobaud[1] + (autobaud[2] << 8));
-	printf("Autobaud result: %zibps %zi.%zimhz (header:0x%02X DLL:0x%02X DLH:0x%02X fin:0x%02X)\n",
+	if (!quiet) {
+		printf("Autobaud result: %zibps %zi.%zimhz (header:0x%02X DLL:0x%02X DLH:0x%02X fin:0x%02X)\n",
 	       baud, sclock / 1000000, sclock / 1000 - sclock / 1000000 * 1000,
 	       autobaud[0], autobaud[1], autobaud[2], autobaud[3]);
+	}
 
 	for (d = 0; d < ldr->num_dxes; ++d) {
-		printf("Sending blocks of DXE %zi ... ", d+1);
+		printf("Sending blocks of DXE %zi ...\n", d+1);
+		sleep(1);
 		for (b = 0; b < ldr->dxes[d].num_blocks; ++b) {
 			BLOCK *block = &(ldr->dxes[d].blocks[b]);
 
@@ -408,15 +443,21 @@
 			ret = write(fd, block->header, sizeof(block->header));
 			if (ret != sizeof(block->header))
 				goto canned_failure;
-
+			byte_sent_count = ret; 
+			
 			printf("%zi] ", ldr->dxes[d].num_blocks);
 			if (block->data != NULL) {
 				ret = write(fd, block->data, block->byte_count);
-				if (ret != block->byte_count)
+				if ((unsigned)ret != block->byte_count)
 					goto canned_failure;
+				byte_sent_count += ret; 
 			}
-		}
-		printf("OK!\n");
+			if (!quiet) {
+				printf(" %d bytes\n", byte_sent_count);
+			}
+			sleep(1);
+		}
+		printf("DXE Complete\n");
 	}
 
 	close(fd);

Modified: toolchain/trunk/ldrviewer/ldrviewer.c
URL: http://svn.digium.com/view/aadk/toolchain/trunk/ldrviewer/ldrviewer.c?view=diff&rev=139&r1=138&r2=139
==============================================================================
--- toolchain/trunk/ldrviewer/ldrviewer.c (original)
+++ toolchain/trunk/ldrviewer/ldrviewer.c Tue Jan 30 14:08:24 2007
@@ -95,44 +95,49 @@
 #define show_create_usage(status) show_some_usage(create_long_opts, create_opts_help, CREATE_PARSE_FLAGS, status)
 
 
-static void show_ldr(const char *filename)
+static int show_ldr(const char *filename)
 {
 	LDR *ldr;
 	printf("Showing LDR %s ...\n", filename);
 	ldr = ldr_read(filename);
 	if (ldr == NULL) {
 		printf("Unable to read specified LDR\n");
-		return;
+		return -1;
 	}
 	ldr_print(ldr);
 	ldr_free(ldr);
-}
-
-static void dump_ldr(const char *filename)
+	return 0;
+}
+
+static int dump_ldr(const char *filename)
 {
 	LDR *ldr;
 	printf("Dumping LDR %s ...\n", filename);
 	ldr = ldr_read(filename);
 	if (ldr == NULL) {
 		perror("Unable to read specified LDR");
-		return;
+		return -1;
 	}
 	ldr_dump(filename, ldr);
 	ldr_free(ldr);
-}
-
-static void load_ldr(const char *filename, const char *tty)
+	return 0;
+}
+
+static int load_ldr(const char *filename, const char *tty)
 {
 	LDR *ldr;
+	int res = 0;
+
 	printf("Loading LDR %s ... ", filename);
 	ldr = ldr_read(filename);
 	if (ldr == NULL) {
 		perror("Unable to read specified LDR");
-		return;
+		return EXIT_FAILURE;
 	}
 	printf("OK!\n");
-	ldr_send(ldr, tty);
+	res = ldr_send(ldr, tty);
 	ldr_free(ldr);
+	return res;
 }
 
 static void create_ldr(int argc, char *argv[])
@@ -226,9 +231,13 @@
 				dump_ldr(argv[i]);
 			break;
 		case LOAD:
-			if (optind + 2 != argc)
+			if (optind + 2 != argc) {
 				err("Load requires exactly two arguments: <ldr> <tty>");
-			load_ldr(argv[optind], argv[optind+1]);
+				exit(EXIT_FAILURE);
+			}
+			if(0 != load_ldr(argv[optind], argv[optind+1])){
+				exit(EXIT_FAILURE);
+			}
 			break;
 		case CREATE:
 			--optind;



More information about the aadk-commits mailing list