Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
Mar 03, 2012
Werner Almesberger usb load: show how many bytes were loaded
Not having this seemingly redundant information caused quite the
ghost hunt when we loaded only the first 4 kB, chopping off some
code at the end.
58b27b0
Werner Almesberger usb debug: emit a newline only before returning to the shell
Before, we ended the line each time usb_debug_flush returned, causing
"usb debug wait" to potentially produce very choppy output.
73b5506
Werner Almesberger Merge branch 'master' of github.com:milkymist/flickernoise 002aa33
18  src/shellext.c
@@ -251,10 +251,10 @@ static int main_pfpu(int argc, char **argv)
251 251
 
252 252
 static uint8_t debug_consume = 0;
253 253
 static volatile int keypress_wait;
  254
+static int nl = 1;
254 255
 
255 256
 static void usb_debug_flush(void)
256 257
 {
257  
-	int nl = 1;
258 258
 	char c;
259 259
 
260 260
 	while(debug_consume != COMLOC_DEBUG_PRODUCE) {
@@ -263,8 +263,14 @@ static void usb_debug_flush(void)
263 263
 		nl = c == '\n';
264 264
                 debug_consume++;
265 265
         }
266  
-	if(!nl)
  266
+}
  267
+
  268
+static void end_line(void)
  269
+{
  270
+	if(!nl) {
267 271
 		putchar('\n');
  272
+		nl = 1;
  273
+	}
268 274
 }
269 275
 
270 276
 static rtems_task keypress_task(rtems_task_argument argument)
@@ -283,6 +289,7 @@ static int usb_debug(int argc, char **argv)
283 289
 
284 290
 	if(argc == 1) {
285 291
 		usb_debug_flush();
  292
+		end_line();
286 293
 		return 0;
287 294
 	}
288 295
 
@@ -301,16 +308,21 @@ static int usb_debug(int argc, char **argv)
301 308
 		rtems_task_wake_after(1);
302 309
 	}
303 310
 	while(keypress_wait);
  311
+	end_line();
304 312
 
305 313
 	return 0;
306 314
 }
307 315
 
308 316
 static int usb_load(int argc, char **argv)
309 317
 {
310  
-	if(!load_usb_firmware_file(argv[1])) {
  318
+	int size;
  319
+
  320
+	size = load_usb_firmware_file(argv[1]);
  321
+	if(size < 0) {
311 322
 		fprintf(stderr, "load failed\n");
312 323
 		return 2;
313 324
 	}
  325
+	printf("loaded %d byte%s\n", size, size == 1 ? "" : "s");
314 326
 	debug_consume = 0;
315 327
 	return 0;
316 328
 }
9  src/usbfirmware.c
@@ -63,11 +63,10 @@ int load_usb_firmware_file(const char *name)
63 63
 
64 64
 	file = fopen(name, "r");
65 65
 	if(!file)
66  
-		return 0;
  66
+		return -1;
67 67
 	dsc.length = fread(buf, 1, sizeof(buf), file);
68 68
 	fclose(file);
69  
-	if(dsc.length <= 0)
70  
-		return 0;
71  
-	do_load_usb_firmware(&dsc);
72  
-	return 1;
  69
+	if(dsc.length >= 0)
  70
+		do_load_usb_firmware(&dsc);
  71
+	return dsc.length;
73 72
 }

No commit comments for this range

Something went wrong with that request. Please try again.