From a740a7a578cb8a3f53b1b12b2e0833c8dbf4dcff Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 11 Sep 2005 19:59:05 +0000 Subject: As Juergen Heinzl pointed out, much of my original fwi calculations evaluated to zero due to the integer range limitations. shifting everything to the microsecond range should solve this problem without introducing ugly floating point arithmetics. git-svn-id: https://svn.gnumonks.org/trunk/librfid@1425 e0336214-984f-0b4b-a45f-81c69e1f0ede --- rfid_layer2_iso14443b.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'rfid_layer2_iso14443b.c') diff --git a/rfid_layer2_iso14443b.c b/rfid_layer2_iso14443b.c index 6207827..d36b5da 100644 --- a/rfid_layer2_iso14443b.c +++ b/rfid_layer2_iso14443b.c @@ -36,10 +36,23 @@ static inline int fwi_to_fwt(struct rfid_layer2_handle *h, unsigned int *fwt, unsigned int fwi) { + unsigned int multiplier; + + /* 15 is RFU */ if (fwi > 14) return -1; - return (256 * 16 / h->rh->ah->asic->fc) * 2 ^ fwi; + /* According to ISO 14443-3:200(E), Chapter 7.9.4.3, the forumala is + * (256 * 16 / fC) * 2^fwi We avoid floating point computations by + * shifting everything into the microsecond range. In integer + * calculations 1000000*256*16/13560000 evaluates to 302 (instead of + * 302.064897), which provides sufficient precision, IMHO. The max + * result is 302 * 16384 (4947968), which fits well within the 31/32 + * bit range of an integer */ + + multiplier = 1 << fwi; /* 2 to the power of fwi */ + + return (1000000 * 256 * 16 / h->rh->ah->asic->fc) * multiplier } static int -- cgit v1.2.3