From 8177bccf5bae60dcf70ab86de3591d0332f752e7 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 27 May 2006 18:31:36 +0000 Subject: [PATCH] add some very rudimentary timeout handling, i.e. abort if there is no response. tolerance = 10000% git-svn-id: https://svn.gnumonks.org/trunk/librfid@1807 e0336214-984f-0b4b-a45f-81c69e1f0ede --- src/rfid_asic_rc632.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c index 0c38052..58b075c 100644 --- a/src/rfid_asic_rc632.c +++ b/src/rfid_asic_rc632.c @@ -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; -- 2.20.1