changeset 1122:92e31da869cc

Add ^C abort functionality to BOOTP and PING operations.
author gthomas
date Wed, 16 Jul 2003 19:08:54 +0000
parents 7992fe4e88eb
children 36b042c3698d
files packages/redboot/current/ChangeLog packages/redboot/current/include/redboot.h packages/redboot/current/src/io.c packages/redboot/current/src/net/bootp.c packages/redboot/current/src/net/ping.c
diffstat 5 files changed, 62 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,12 @@
+2003-07-16  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/net/ping.c:
+	* src/net/bootp.c: Allow ^C to abort.
+
+	* src/io.c: 
+	* include/redboot.h: New function _rb_break() used to test for ^C
+	on the console.  Used to break out of long operations like BOOTP.
+
 2003-07-15  Gary Thomas  <gary@mlbassoc.com>
 
 	* src/net/bootp.c: Use correct options for DHCP discover.  This has
--- a/packages/redboot/current/include/redboot.h
+++ b/packages/redboot/current/include/redboot.h
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -139,6 +139,10 @@ externC int  _rb_gets_preloaded(char *li
 #define _GETS_CTRLC   -2
 #define _GETS_GDB      0
 #define _GETS_OK       1
+// Test for ^C on the console.  This function should only be used if any
+// other console input can be discarded, e.g. while performing some long
+// computation, waiting for the network, etc.  Returns 'true' if ^C typed.
+externC bool _rb_break(int timeout);
 
 // "console" selection
 externC int  start_console(void);
--- a/packages/redboot/current/src/io.c
+++ b/packages/redboot/current/src/io.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -247,6 +247,22 @@ mon_set_read_char_timeout(int ms)
     }
 }
 
+//
+// Test for ^C on the console.  CAUTION! discards all console input
+//
+bool
+_rb_break(int timeout)
+{
+    char c;
+    mon_set_read_char_timeout(timeout);
+    if (mon_read_char_with_timeout(&c)) {
+        if (c == 0x03) {  // Test for ^C
+            return true;
+        }
+    }
+    return false;
+}
+
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
 #define __STRINGIFY(x) #x
 #define _STRINGIFY(x) __STRINGIFY(x)
--- a/packages/redboot/current/src/net/bootp.c
+++ b/packages/redboot/current/src/net/bootp.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -62,7 +62,7 @@ extern int net_debug;
 #define SHOULD_BE_RANDOM  0x12345555
 
 /* How many milliseconds to wait before retrying the request */
-#define RETRY_TIME  1000
+#define RETRY_TIME   500
 #define MAX_RETRIES   30
 
 static bootp_header_t *bp_info;
@@ -155,6 +155,7 @@ int
     unsigned char *p;
 #endif
     int txSize;
+    bool abort = false;
 
     bp_info = info;
 
@@ -199,8 +200,8 @@ int
     /* setup a socket listener for bootp replies */
     __udp_install_listener(&udp_skt, IPPORT_BOOTPC, bootp_handler);
 
-    retry = MAX_RETRIES;
-    while (retry-- > 0) {
+    retry = MAX_RETRIES;  
+    while (!abort && (retry-- > 0)) {
 	start = MS_TICKS();
 
 	__udp_send((char *)&b, txSize, &r, IPPORT_BOOTPS, IPPORT_BOOTPC);
@@ -213,7 +214,18 @@ int
 		__udp_remove_listener(IPPORT_BOOTPC);
 		return 0;
 	    }
+            if (_rb_break(1)) {
+                // The user typed ^C on the console
+                abort = true;
+                break;
+            }
+            MS_TICKS_DELAY();  // Count for ^C test
 	} while ((MS_TICKS_DELAY() - start) < RETRY_TIME);
+
+        // Warn the user that we're polling for BOOTP info
+        if (retry == (MAX_RETRIES-1)) {
+            diag_printf("... waiting for BOOTP information\n");
+        }
     }
 
     /* timed out */
--- a/packages/redboot/current/src/net/ping.c
+++ b/packages/redboot/current/src/net/ping.c
@@ -9,6 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -177,9 +178,10 @@ do_ping(int argc, char *argv[])
                 inet_ntoa((in_addr_t *)&host_addr));
     received = 0;    
     __icmp_install_listener(handle_icmp);
+    // Save default "local" address
+    memcpy(hold_addr, __local_ip_addr, sizeof(hold_addr));
     for (tries = 0;  tries < count;  tries++) {
         // The network stack uses the global variable '__local_ip_addr'
-        memcpy(hold_addr, __local_ip_addr, sizeof(hold_addr));
         memcpy(__local_ip_addr, &local_addr, sizeof(__local_ip_addr));
         // Build 'ping' request
         if ((pkt = __pktbuf_alloc(ETH_MAX_PKTLEN)) == NULL) {
@@ -209,19 +211,24 @@ do_ping(int argc, char *argv[])
         start_time = MS_TICKS();
         timer = start_time + timeout;
         icmp_received = false;
-        while (!icmp_received && (MS_TICKS_DELAY() < timer)) {
+        while (!icmp_received && (MS_TICKS_DELAY() < timer)) {            
+            if (_rb_break(1)) {
+                goto abort;
+            }
+            MS_TICKS_DELAY();
             __enet_poll();
         } 
         end_time = MS_TICKS();
 
         timer = MS_TICKS() + rate;
         while (MS_TICKS_DELAY() < timer) {
+            if (_rb_break(1)) {
+                goto abort;
+            }
+            MS_TICKS_DELAY();
             __enet_poll();
         } 
 
-        // Clean up
-        memcpy(__local_ip_addr, &hold_addr, sizeof(__local_ip_addr));
-
         if (icmp_received) {
             received++;
             if (verbose) {
@@ -230,7 +237,10 @@ do_ping(int argc, char *argv[])
             }
         }
     }
+ abort:
     __icmp_remove_listener();
+    // Clean up
+    memcpy(__local_ip_addr, &hold_addr, sizeof(__local_ip_addr));
     // Report
     diag_printf("PING - received %ld of %ld expected\n", received, count);
 }