+#ifdef UCLINUX
+void usleep_watchdevice(unsigned long usecs)
+{
+int err;
+fd_set readfds;
+struct timeval target,timeout;
+
+ if (gettimeofday(&target/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) init");
+ target.tv_usec+=usecs%1000000;
+ target.tv_sec +=usecs/1000000 + (target.tv_usec/1000000);
+ target.tv_usec%=1000000;
+
+ for (;;)
+ FD_ZERO(&readfds);
+ if (device_portfd>=0)
+ FD_SET(device_portfd,&readfds);
+
+ if (gettimeofday(&timeout/*tv*/,NULL/*tz*/))
+ perror("usleep_watchdevice()/gettimeofday(2) loop");
+ if (target.tv_sec < timeout.tv_sec)
+ return;
+ timeout.tv_sec =target.tv_sec - timeout.tv_sec;
+ if (target.tv_usec < timeout.tv_usec) {
+ target.tv_usec+=1000000;
+ if (target.tv_sec <= 0)
+ return;
+ target.tv_sec--;
+ }
+ timeout.tv_usec=target.tv_usec - timeout.tv_usec;
+
+ err=select((device_portfd<0 ? 0 : device_portfd+1),&readfds,NULL,NULL,&timeout);
+ if ( err > 0 ) {
+ if (device_portfd>=0 && FD_ISSET(device_portfd,&readfds)) {
+ /* call singal handler to process incoming data */
+ SigHandler(0);
+ }
+ } else {
+ if (err == -1)
+ perror("Error in SelectLoop");
+ }
+}
+#endif