This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

MS_TICKS() revisited



I've modified my ms_ticks stuff so that there are two routines.
Both return the current system time, but one delays for a
millisecond and the other doesn't.

do_ms_tick()      // delays for 1ms, returns system time
get_ms_ticks()    // returns system time

#define MS_TICKS()  get_ms_ticks()
#define MS_TICKS_DELAY() -> do_ms_tick()

This saves a few milliseconds of overhead here and there
(nothing worth worrying about), but mostly it makes it clear
whether the caller wants to delay for a millisecond or just to
read the system time.

Attached is a patch against CVS sources for anybody who wants it.

I've only done limited testing, so it's possible I'm missing a
delay where I need one.  IOW, there may be an MS_TICKS() that
should be MS_TICKS_DELAY() -- but I don't think so.

NB: this patch also includes a fix to net_io_getc_nonblock() so
    that it always sets its return value properly.  AFAICT, the
    old version worked OK because whatever happened to be left
    in R0 when the function fell off the bottom always had a
    non-zero.

-- 
Grant Edwards
grante@visi.com
Index: include/net/net.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/include/net/net.h,v
retrieving revision 1.3
diff -u -5 -r1.3 net.h
--- net.h	2000/12/08 03:30:08	1.3
+++ net.h	2001/02/09 18:59:02
@@ -51,11 +51,13 @@
 #include <cyg/hal/basetype.h>
 
 extern bool net_debug;
 
 extern unsigned long do_ms_tick(void);
-#define MS_TICKS() do_ms_tick()
+extern unsigned long get_ms_ticks(void);
+#define MS_TICKS() get_ms_ticks()
+#define MS_TICKS_DELAY() do_ms_tick()
 
 /* #define NET_SUPPORT_RARP  1 */
 #define NET_SUPPORT_ICMP 1
 #define NET_SUPPORT_UDP  1
 #define NET_SUPPORT_TCP  1
Index: src/net/arp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/arp.c,v
retrieving revision 1.1
diff -u -5 -r1.1 arp.c
--- arp.c	2000/08/25 17:33:47	1.1
+++ arp.c	2001/02/09 18:59:03
@@ -143,11 +143,11 @@
         /* send the packet */
 	pkt->pkt_bytes = sizeof(arp_header_t);
         __enet_send(pkt, &bcast_addr, ETH_TYPE_ARP);
 
         retry_start = MS_TICKS();
-	while ((MS_TICKS() - retry_start) < 250) {
+	while ((MS_TICKS_DELAY() - retry_start) < 250) {
 	    __enet_poll();
 	    if (!arp_req.waiting) {
 		__pktbuf_free(pkt);
 		return 0;
 	    }
Index: src/net/bootp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/bootp.c,v
retrieving revision 1.1
diff -u -5 -r1.1 bootp.c
--- bootp.c	2000/08/25 17:33:47	1.1
+++ bootp.c	2001/02/09 18:59:03
@@ -129,11 +129,11 @@
 		__local_ip_addr[2] || __local_ip_addr[3]) {
 		/* success */
 		__udp_remove_listener(IPPORT_BOOTPC);
 		return 0;
 	    }
-	} while ((MS_TICKS() - start) < RETRY_TIME);
+	} while ((MS_TICKS_DELAY() - start) < RETRY_TIME);
     }
 
     /* timed out */
     __udp_remove_listener(IPPORT_BOOTPC);
     net_debug = 0;
Index: src/net/net_io.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.7
diff -u -5 -r1.7 net_io.c
--- net_io.c	2000/12/08 03:30:09	1.7
+++ net_io.c	2001/02/09 18:59:03
@@ -88,10 +88,14 @@
     );
 #endif
 
 #define TCP_CHANNEL CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
 
+#if !defined(CYGPKG_REDBOOT_NETWORKING)
+#define MS_TICKS_DELAY() hal_delay_us(1000)
+#endif
+
 #ifdef DEBUG_TCP
 int show_tcp = 0;
 #endif 
 
 static tcp_socket_t tcp_sock;
@@ -158,54 +162,59 @@
 }
 
 static cyg_bool
 net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
 {
-    if (_net_io_getc_nonblock(__ch_data, ch)) {
-        if (*ch == TELNET_IAC) {
-            cyg_uint8 esc;
-            // Telnet escape - need to read/handle more
-            while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
-            if (esc == TELNET_IP) {
-                // Special case for ^C == Interrupt Process
-                *ch = 0x03;  
-                // Just in case the other end needs synchronizing
-                net_io_putc(__ch_data, TELNET_IAC);
-                net_io_putc(__ch_data, TELNET_WONT);
-                net_io_putc(__ch_data, TELNET_TM);
-                net_io_flush();
-                return true;
-            }
-            if (esc == TELNET_DO) {
-                // Telnet DO option
-                while (!_net_io_getc_nonblock(__ch_data, &esc)) ;                
-                // Respond with WONT option
-                net_io_putc(__ch_data, TELNET_IAC);
-                net_io_putc(__ch_data, TELNET_WONT);
-                net_io_putc(__ch_data, esc);
-                return false;  // Ignore this whole thing!
-            }
-        }
-    } else {
-        return false;
-    }
+	cyg_uint8 esc;
+	
+    if (!_net_io_getc_nonblock(__ch_data, ch))
+		return false;
+
+	if (*ch != TELNET_IAC)
+		return true;
+	  
+	// Telnet escape - need to read/handle more
+
+	while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
+	
+	if (esc == TELNET_IP) {
+		// Special case for ^C == Interrupt Process
+		*ch = 0x03;  
+		// Just in case the other end needs synchronizing
+		net_io_putc(__ch_data, TELNET_IAC);
+		net_io_putc(__ch_data, TELNET_WONT);
+		net_io_putc(__ch_data, TELNET_TM);
+		net_io_flush();
+		return true;
+	}
+	else if (esc == TELNET_DO) {
+		// Telnet DO option
+		while (!_net_io_getc_nonblock(__ch_data, &esc)) ;                
+		// Respond with WONT option
+		net_io_putc(__ch_data, TELNET_IAC);
+		net_io_putc(__ch_data, TELNET_WONT);
+		net_io_putc(__ch_data, esc);
+		return false;  // Ignore this whole thing!
+	}
+
+	return false;
 }
 
 static cyg_uint8
 net_io_getc(void* __ch_data)
 {
     cyg_uint8 ch;
-    int idle_timeout = 100;  // 10ms
+    int idle_timeout = 10;  // 10ms
 
     CYGARC_HAL_SAVE_GP();
     while (true) {
         if (net_io_getc_nonblock(__ch_data, &ch)) break;
         if (--idle_timeout == 0) {
             net_io_flush();
-            idle_timeout = 100;
+            idle_timeout = 10;
         } else {
-            CYGACC_CALL_IF_DELAY_US(100);
+            MS_TICKS_DELAY();
         }
     }
     CYGARC_HAL_RESTORE_GP();
     return ch;
 }
@@ -312,17 +321,17 @@
     int delay_count;
     cyg_bool res;
     CYGARC_HAL_SAVE_GP();
 
     net_io_flush();  // Make sure any output has been sent
-    delay_count = _timeout * 10; // delay in .1 ms steps
+    delay_count = _timeout;
 
     for(;;) {
         res = net_io_getc_nonblock(__ch_data, ch);
         if (res || 0 == delay_count--)
             break;
-        CYGACC_CALL_IF_DELAY_US(100);
+        MS_TICKS_DELAY();
     }
 
     CYGARC_HAL_RESTORE_GP();
     return res;
 }
Index: src/net/udp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/udp.c,v
retrieving revision 1.2
diff -u -5 -r1.2 udp.c
--- udp.c	2000/10/31 20:53:15	1.2
+++ udp.c	2001/02/09 18:59:03
@@ -237,11 +237,11 @@
     recvfrom_len = len;
     recvfrom_server = server;
     total_ms = (timo->tv_sec * 1000) + (timo->tv_usec / 1000);
     start = MS_TICKS();
     res = -1;
-    while ((MS_TICKS() - start) < total_ms) {
+    while ((MS_TICKS_DELAY() - start) < total_ms) {
         __enet_poll();  // Handle the hardware
         if (!recvfrom_buf) {
             // Data have arrived
             res = recvfrom_len;
             break;
Index: src/ticks.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/ticks.c,v
retrieving revision 1.1
diff -u -5 -r1.1 ticks.c
--- ticks.c	2000/08/25 17:33:47	1.1
+++ ticks.c	2001/02/09 18:59:03
@@ -43,12 +43,20 @@
 //
 //==========================================================================
 
 #include "redboot.h"
 
+static unsigned long ticks = 0;
+
+
 unsigned long
 do_ms_tick(void)
 {
-    static unsigned long ticks = 0;
     CYGACC_CALL_IF_DELAY_US(1000);   // Wait for 1ms
     return ++ticks;
+}
+
+unsigned long
+get_ms_ticks(void)
+{
+    return ticks;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]