add some very rudimentary timeout handling, i.e. abort if there is no response. toler...
authorHarald Welte <laforge@gnumonks.org>
Sat, 27 May 2006 18:31:36 +0000 (18:31 +0000)
committerHarald Welte <laforge@gnumonks.org>
Sat, 27 May 2006 18:31:36 +0000 (18:31 +0000)
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1807 e0336214-984f-0b4b-a45f-81c69e1f0ede

src/rfid_asic_rc632.c

index 0c38052..58b075c 100644 (file)
@@ -170,7 +170,8 @@ static int
 rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t timeout)
 {
        u_int8_t cmd = 0xff;
-       int ret;
+       int ret, cycles = 0;
+#define USLEEP_PER_CYCLE       128
 
        while (cmd != 0) {
                ret = rc632_reg_read(handle, RC632_REG_COMMAND, &cmd);
@@ -189,9 +190,14 @@ rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t timeout)
                                rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &foo);
                }
 
-               usleep(100);
+               /* Abort after some timeout */
+               if (cycles > timeout*10/USLEEP_PER_CYCLE) {
+                       fprintf(stderr, "TIMEOUT!!\n");
+                       return -1;
+               }
 
-               /* Fixme: Abort after some timeout */
+               cycles++;
+               usleep(USLEEP_PER_CYCLE);
        }
 
        return 0;