From 8169da37017ef64417d9b395a719302bcc0fcd6b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 3 May 2011 13:55:20 +0000 Subject: [PATCH] pn53x: Fix bug in _timed fcts --- libnfc/chips/pn53x.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index ef91ad7..10ef840 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -859,7 +859,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, (void) pbtTxPar; (void) pbtRxPar; unsigned int i; - uint8_t sz; + uint8_t sz, sz2; // Sorry, no arbitrary parity bits support for now if (!pnd->bPar) { @@ -899,6 +899,14 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, for (i=0; i< sz; i++) { pn53x_read_register (pnd, REG_CIU_FIFODATA, &(pbtRx[i])); } + // Did we get more data meanwhile? + pn53x_read_register (pnd, REG_CIU_FIFOLEVEL, &sz2); + if (sz2 != 0) { + *pszRxBits += (sz2 & SYMBOL_FIFO_LEVEL) * 8; + for (i=0; i< sz2; i++) { + pn53x_read_register (pnd, REG_CIU_FIFODATA, &(pbtRx[i+sz])); + } + } // Recv corrected timer value *cycles = __pn53x_get_timer (pnd, pbtTx[szTxBits / 8]); @@ -911,7 +919,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx size_t * pszRx, uint16_t * cycles) { unsigned int i; - uint8_t sz; + uint8_t sz, sz2; // We can not just send bytes without parity while the PN53X expects we handled them if (!pnd->bPar) { @@ -946,6 +954,14 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx for (i=0; ibCrc) {