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 484f4ac026590151d5731bcff2656ffd10135991 1 parent 41e4380
Werner Almesberger authored February 27, 2012

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

  1. 53  src/shellext.c
53  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,41 @@ 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, 10*1024 /*RTEMS_MINIMUM_STACK_SIZE*/,
  293
+            2, RTEMS_MINIMUM_STACK_SIZE,
  294
+	    RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
  295
+	    0, &task_id);
  296
+	assert(sc == RTEMS_SUCCESSFUL);
  297
+	sc = rtems_task_start(task_id, keypress_task, 0);
  298
+	assert(sc == RTEMS_SUCCESSFUL);
  299
+
  300
+	do {
  301
+		usb_debug_flush();
  302
+		rtems_task_wake_after(1);
  303
+	}
  304
+	while(keypress_wait);
287 305
 
288 306
 	return 0;
289 307
 }
@@ -302,7 +320,7 @@ static void usb_usage(void)
302 320
 {
303 321
 	printf("  usb [help]\n");
304 322
 	printf("  usb load file\n");
305  
-	printf("  usb debug [seconds]\n");
  323
+	printf("  usb debug [wait]\n");
306 324
 }
307 325
 
308 326
 static int main_usb(int argc, char **argv)
@@ -313,7 +331,8 @@ static int main_usb(int argc, char **argv)
313 331
 	}
314 332
 	if(!strcmp(argv[1], "load") && argc == 3)
315 333
 		return usb_load(argc-1, argv+1);
316  
-	if(!strcmp(argv[1], "debug") && (argc == 2 || argc == 3))
  334
+	if(!strcmp(argv[1], "debug") &&
  335
+	    (argc == 2 || (argc == 3 && !strcmp(argv[2], "wait"))))
317 336
 		return usb_debug(argc-1, argv+1);
318 337
 	usb_usage();
319 338
 	return 1;

0 notes on commit 484f4ac

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