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]

RedBoot: patch to improve net timekeeping.



Here's a patch to net_io.c that changes the getc() routines
to call MS_TICKS() rather than CYGACC_CALL_IF_DELAY_US() when
waiting for input.

If a similar approach is used in the HAL's serial i/o routines,
it results in the system time being fairly accurate if the CPU
isn't heavily loaded.  As long as you call MS_TICKS() when
you're in a busy-idle loop, the accuracy of the system time is
determined by the CPU usage: 10% CPU means the clock is 10%
slow.  This should make it fairly useful for non-critical
interval timing.

NB: This changes the incremental wait in the net_io getc
    routines from 100us to 1ms.  If somebody really needs 100us
    wiats, a second delay routine could be added to ticks.c
    that delays for 100us and increments the "ticks" variable
    every 10th call.

-- 
Grant Edwards
grante@visi.com
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 -U5 -r1.7 net_io.c
--- net_io.c	2000/12/08 03:30:09	1.7
+++ net_io.c	2001/01/22 23:00:37
@@ -88,10 +88,14 @@
     );
 #endif
 
 #define TCP_CHANNEL CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
 
+#if !defined(CYGPKG_REDBOOT_NETWORKING)
+#define MS_TICKS() hal_delay_us(1000)
+#endif
+
 #ifdef DEBUG_TCP
 int show_tcp = 0;
 #endif 
 
 static tcp_socket_t tcp_sock;
@@ -192,20 +196,20 @@
 
 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();
         }
     }
     CYGARC_HAL_RESTORE_GP();
     return ch;
 }
@@ -312,17 +316,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();
     }
 
     CYGARC_HAL_RESTORE_GP();
     return res;
 }

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