diff options
author | Rakesh Goyal <rgoyal@nvidia.com> | 2012-01-27 15:51:26 +0530 |
---|---|---|
committer | Ramanan Rajeswaran <ramanan@google.com> | 2012-03-09 08:51:44 -0800 |
commit | 3f791036276b6f535ad253dd25650fad60c72695 (patch) | |
tree | aaeaa4d26a5d496be9b05182c85723058f2decc0 | |
parent | 8c56cd9e0bc2808d73e6596ba3bb128cc2fbcd7c (diff) | |
download | external_libnfc-nxp-3f791036276b6f535ad253dd25650fad60c72695.zip external_libnfc-nxp-3f791036276b6f535ad253dd25650fad60c72695.tar.gz external_libnfc-nxp-3f791036276b6f535ad253dd25650fad60c72695.tar.bz2 |
nfc-hal: generalize error handling in Reader thread.
If host runs faster than the nfc chip, it tries to read response immediately.
In this scenario nfc chip responds back with it's read address and software
should ignore this data and retry. This patch generalizes the retry mechanism
to accomodate other versions of the nfc chip.
Change-Id: I3e18e34fd3edf6ed0a7f302a6be9321ab8ed7875
-rw-r--r-- | Linux_x86/phDal4Nfc.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c index 3e031f1..ae2d3bf 100644 --- a/Linux_x86/phDal4Nfc.c +++ b/Linux_x86/phDal4Nfc.c @@ -718,8 +718,17 @@ int phDal4Nfc_ReaderThread(void * pArg) int i; int i2c_error_count; int i2c_workaround; + int i2c_device_address = 0x57; if (gDalContext.pDev != NULL) { i2c_workaround = gDalContext.pDev->enable_i2c_workaround; + if (gDalContext.pDev->i2c_device_address) { + i2c_device_address = gDalContext.pDev->i2c_device_address; + if (i2c_workaround && i2c_device_address < 32) + { + LOGE("i2c_device_address not set to valid value"); + return NFCSTATUS_FAILED; + } + } } else { LOGE("gDalContext.pDev is not set"); return NFCSTATUS_FAILED; @@ -758,15 +767,17 @@ retry: /* Wait for IRQ !!! */ gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead); - /* Reading the value 0x57 indicates a HW I2C error at I2C address 0x57 + /* A read value equal to the i2c_device_address indicates a HW I2C error at I2C address i2c_device_address * (pn544). There should not be false positives because a read of length 1 - * must be a HCI length read, and a length of 0x57 is impossible (max is 33). + * must be a HCI length read, and a length of i2c_device_address is impossible (max is 33). */ - if(i2c_workaround && gReadWriteContext.nNbOfBytesToRead == 1 && - gReadWriteContext.pReadBuffer[0] == 0x57) + if (i2c_workaround && gReadWriteContext.nNbOfBytesToRead == 1 && + gReadWriteContext.pReadBuffer[0] == i2c_device_address) { i2c_error_count++; - DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count); + DAL_DEBUG("RX Thread Read 0x%02x ", i2c_device_address); + DAL_DEBUG("%d times\n", i2c_error_count); + if (i2c_error_count < 5) { usleep(2000); goto retry; |