Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

usb debug: wait for keypress; removed timeout

usb debug  works as before.
usb debug <seconds>  no longer exists.
usb debug wait  now waits for a keystroke.
  • Loading branch information...
commit 85d0626d2b3248f7de9acb33e25388e95b7d2ae4 1 parent 41e4380
Werner Almesberger authored February 27, 2012

Showing 1 changed file with 35 additions and 17 deletions. Show diff stats Hide diff stats

  1. 52  src/shellext.c
52  src/shellext.c
@@ -30,7 +30,7 @@
30 30
 #include <stdlib.h>
31 31
 #include <stdio.h>
32 32
 #include <string.h>
33  
-#include <time.h>
  33
+#include <assert.h>
34 34
 #include <bsp/milkymist_pfpu.h>
35 35
 #include <bsp/milkymist_tmu.h>
36 36
 
@@ -250,6 +250,7 @@ static int main_pfpu(int argc, char **argv)
250 250
 #define	COMLOC_DEBUG(offset)	COMLOCV(SOFTUSB_DMEM_BASE+0x1001+(offset))
251 251
 
252 252
 static uint8_t debug_consume = 0;
  253
+static volatile int keypress_wait;
253 254
 
254 255
 static void usb_debug_flush(void)
255 256
 {
@@ -266,24 +267,40 @@ static void usb_debug_flush(void)
266 267
 		putchar('\n');
267 268
 }
268 269
 
  270
+static rtems_task keypress_task(rtems_task_argument argument)
  271
+{
  272
+	char buf[1];
  273
+
  274
+	read(0, buf, 1);
  275
+	keypress_wait = 0;
  276
+	rtems_task_delete(RTEMS_SELF);
  277
+}
  278
+
269 279
 static int usb_debug(int argc, char **argv)
270 280
 {
271  
-	unsigned long n = 0;
272  
-	char *end;
273  
-	time_t t;
274  
-
275  
-	if(argc == 2) {
276  
-		n = strtoul(argv[1], &end, 0);
277  
-		if(*end) {
278  
-			fprintf(stderr, "invalid interval: \"%s\"\n", argv[1]);
279  
-			return 1;
280  
-		}
  281
+	rtems_id task_id;
  282
+	rtems_status_code sc;
  283
+
  284
+	if(argc == 1) {
  285
+		usb_debug_flush();
  286
+		return 0;
281 287
 	}
282 288
 
283  
-	time(&t);
284  
-	t += n;
285  
-	do usb_debug_flush();
286  
-	while (time(NULL) < t);
  289
+	keypress_wait = 1;
  290
+
  291
+	sc =  rtems_task_create(rtems_build_name('U', 'D', 'B', 'G'),
  292
+            2, RTEMS_MINIMUM_STACK_SIZE,
  293
+	    RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
  294
+	    0, &task_id);
  295
+	assert(sc == RTEMS_SUCCESSFUL);
  296
+	sc = rtems_task_start(task_id, keypress_task, 0);
  297
+	assert(sc == RTEMS_SUCCESSFUL);
  298
+
  299
+	do {
  300
+		usb_debug_flush();
  301
+		rtems_task_wake_after(1);
  302
+	}
  303
+	while(keypress_wait);
287 304
 
288 305
 	return 0;
289 306
 }
@@ -302,7 +319,7 @@ static void usb_usage(void)
302 319
 {
303 320
 	printf("  usb [help]\n");
304 321
 	printf("  usb load file\n");
305  
-	printf("  usb debug [seconds]\n");
  322
+	printf("  usb debug [wait]\n");
306 323
 }
307 324
 
308 325
 static int main_usb(int argc, char **argv)
@@ -313,7 +330,8 @@ static int main_usb(int argc, char **argv)
313 330
 	}
314 331
 	if(!strcmp(argv[1], "load") && argc == 3)
315 332
 		return usb_load(argc-1, argv+1);
316  
-	if(!strcmp(argv[1], "debug") && (argc == 2 || argc == 3))
  333
+	if(!strcmp(argv[1], "debug") &&
  334
+	    (argc == 2 || (argc == 3 && !strcmp(argv[2], "wait"))))
317 335
 		return usb_debug(argc-1, argv+1);
318 336
 	usb_usage();
319 337
 	return 1;

0 notes on commit 85d0626

Please sign in to comment.
Something went wrong with that request. Please try again.