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_proto_tcl.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'rfid_proto_tcl.c') diff --git a/rfid_proto_tcl.c b/rfid_proto_tcl.c index a992f70..b8586f5 100644 --- a/rfid_proto_tcl.c +++ b/rfid_proto_tcl.c @@ -40,15 +40,33 @@ static unsigned int sfgi_to_sfgt(struct rfid_protocol_handle *h, unsigned char sfgi) { - /* ISO 14443-4:2000(E) Section 5.2.5. */ - return (256 * 16 / h->l2h->rh->ah->fc) * (2 ^ sfgi); + unsigned int multiplier; + + if (sfgi > 14) + sfgi = 14; + + multiplier = 1 << sfgi; /* 2 to the power of sfgi */ + + /* ISO 14443-4:2000(E) Section 5.2.5: + * (256 * 16 / h->l2h->rh->ah->fc) * (2 ^ sfgi) */ + + return (1000000 * 256*16 / h->l2h->rh->ah->fc) * multiplier; } static unsigned int fwi_to_fwt(struct rfid_protocol_handle *h, unsigned char fwi) { - /* ISO 14443-4:2000(E) Section 7.2. */ - return (256*16 / h->l2h->rh->ah->fc) * (2 ^ fwi); + unsigned int multiplier; + + if (fwi > 14) + fwi = 14; + + multiplier = 1 << fwi; /* 2 to the power of fwi */ + + /* ISO 14443-4:2000(E) Section 7.2.: + * (256*16 / h->l2h->rh->ah->fc) * (2 ^ fwi) */ + + return (1000000 * 256*16 / h->l2h->rh->ah->fc) * multiplier; } #define activation_fwt(x) (65536 / x->l2h->rh->ah->fc) -- cgit v1.2.3