Index: firmware_eclairexl/usb/hid.c
===================================================================
--- firmware_eclairexl/usb/hid.c	(revision 955)
+++ firmware_eclairexl/usb/hid.c	(revision 956)
@@ -672,7 +672,7 @@
     
     if(iface->device_type != HID_DEVICE_UNKNOWN) {
 
-      if (iface->qNextPollTime <= timer_get_msec()) {
+      if (timer_elapsed(iface->qNextPollTime)) {
 	//      hid_debugf("poll %d...", iface->ep.epAddr);
       
 	uint16_t read = iface->ep.maxPktSize;
Index: firmware_eclairexl/usb/hub.c
===================================================================
--- firmware_eclairexl/usb/hub.c	(revision 955)
+++ firmware_eclairexl/usb/hub.c	(revision 956)
@@ -288,7 +288,7 @@
   if (!info->bPollEnable)
     return 0;
   
-  if (info->qNextPollTime <= timer_get_msec()) {
+  if (timer_elapsed(info->qNextPollTime)) {
     rcode = usb_hub_check_hub_status(dev, info->bNbrPorts);
     //info->qNextPollTime = timer_get_msec() + 100;   // poll 10 times a second 
     info->qNextPollTime = timer_get_msec() + 2000;   // poll every 2 seconds
Index: firmware_eclairexl/usb/timer.c
===================================================================
--- firmware_eclairexl/usb/timer.c	(revision 955)
+++ firmware_eclairexl/usb/timer.c	(revision 956)
@@ -20,7 +20,25 @@
 msec_t timer_get_msec() {
 	int res = *zpu_timer;
 	res = res >> 10; // Divide by 1024, good enough for here!
+
 	return res;
 }
+
+bool timer_elapsed(msec_t until)
+{
+	msec_t now = timer_get_msec();
+	if (now>=until)
+		return true;
+	else 
+	{
+		unsigned int delay = until - now;
+
+		if (delay > 0x200000)
+			return true;  //overflow
+		else
+			return false; //normal case
+	}
+}
+
 #endif
 
Index: firmware_eclairexl/usb/timer.h
===================================================================
--- firmware_eclairexl/usb/timer.h	(revision 955)
+++ firmware_eclairexl/usb/timer.h	(revision 956)
@@ -10,4 +10,6 @@
 void timer_init();
 msec_t timer_get_msec();
 
+bool timer_elapsed(msec_t end);
+
 #endif // TIMER_H
Index: firmware_eclairexl/usb/usb.c
===================================================================
--- firmware_eclairexl/usb/usb.c	(revision 955)
+++ firmware_eclairexl/usb/usb.c	(revision 956)
@@ -140,7 +140,7 @@
   uint8_t retry_count = 0;
   uint16_t nak_count = 0;
 	
-  while( timeout > timer_get_msec() )  {
+  while( !timer_elapsed(timeout) )  {
     //MWW max3421e_write_u08( MAX3421E_HXFR, ( token|ep )); //launch the transfer
     USBHOSTSLAVE_WRITE(OHS900_TXENDPREG, ep);
     uint8_t control = OHS900_HCTLMASK_TRANS_REQ|controlAdj;
@@ -227,7 +227,7 @@
     
     // wait for transfer completion
 	//printf("Wait:%x %x ", timer_get_msec(), timeout);
-    while( timer_get_msec() < timeout )	{
+    while( !timer_elapsed(timeout) )	{
       //tmpdata = max3421e_read_u08( MAX3421E_HIRQ );
       // MWW
       tmpdata = USBHOSTSLAVE_READ(OHS900_IRQ_STATUS);
@@ -637,7 +637,7 @@
   usbhostslave = host->addr;
 
   // max poll 1ms
-  if(timer_get_msec() > host->poll) {
+  if(timer_elapsed(host->poll)) {
     host->poll = timer_get_msec()+1;
 
     // poll underlaying hardware layer
@@ -719,7 +719,7 @@
       break;
       
     case USB_ATTACHED_SUBSTATE_SETTLE:              //settle time for just attached device            
-      if( host->delay < timer_get_msec() ) 
+      if( timer_elapsed(host->delay) ) 
 	host->usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
       break;
       
@@ -732,7 +732,7 @@
       break;
       
     case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
-      if( host->delay < timer_get_msec() )
+      if( timer_elapsed(host->delay) )
       {
         USBHOSTSLAVE_WRITE(OHS900_SOFENREG, OHS900_MASK_SOF_ENA);
         USBHOSTSLAVE_WRITE(OHS900_TXLINECTLREG, OHS900_TXLCTL_MASK_NORMAL);
@@ -752,7 +752,7 @@
       if (USBHOSTSLAVE_READ(OHS900_IRQ_STATUS)&OHS900_INTMASK_SOFINTR)
       {
         USBHOSTSLAVE_WRITE(OHS900_IRQ_STATUS, OHS900_INTMASK_SOFINTR);
-	if( host->delay < timer_get_msec() ) //20ms passed
+	if( timer_elapsed(host->delay) ) //20ms passed
 	  host->usb_task_state = USB_STATE_CONFIGURING;
       }
       break;
