summaryrefslogtreecommitdiffstats
path: root/Linux_x86
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2011-07-01 10:43:06 -0700
committerNick Pelly <npelly@google.com>2011-07-01 10:48:51 -0700
commita74fcf0b7a509cb70b69c6362b704d8014edcab1 (patch)
treec2c69e7824ec33abb6cda1ecab05ada08fd389a9 /Linux_x86
parentf6ee24c71b104308e6ee5a71fad9041f3a7aedb5 (diff)
downloadexternal_libnfc-nxp-a74fcf0b7a509cb70b69c6362b704d8014edcab1.zip
external_libnfc-nxp-a74fcf0b7a509cb70b69c6362b704d8014edcab1.tar.gz
external_libnfc-nxp-a74fcf0b7a509cb70b69c6362b704d8014edcab1.tar.bz2
2 second timeout on read().
This restores the previous DAL behavior for read. It turns out this is a necessary hack to allow us to abort a pending read when switching to FW download mode due to a non-responsive NFC controller. Change-Id: Ief6f82600bb0603daaa50097a54a5ac42ae0f6b4
Diffstat (limited to 'Linux_x86')
-rw-r--r--Linux_x86/phDal4Nfc_i2c.c20
-rw-r--r--Linux_x86/phDal4Nfc_uart.c20
2 files changed, 40 insertions, 0 deletions
diff --git a/Linux_x86/phDal4Nfc_i2c.c b/Linux_x86/phDal4Nfc_i2c.c
index 140fc93..72da8e7 100644
--- a/Linux_x86/phDal4Nfc_i2c.c
+++ b/Linux_x86/phDal4Nfc_i2c.c
@@ -191,11 +191,31 @@ int phDal4Nfc_i2c_read(uint8_t * pBuffer, int nNbBytesToRead)
{
int ret;
int numRead = 0;
+ struct timeval tv;
+ fd_set rfds;
DAL_ASSERT_STR(gI2cPortContext.nOpened == 1, "read called but not opened!");
DAL_DEBUG("_i2c_read() called to read %d bytes", nNbBytesToRead);
+ // Read with 2 second timeout, so that the read thread can be aborted
+ // when the pn544 does not respond and we need to switch to FW download
+ // mode. This should be done via a control socket instead.
while (numRead < nNbBytesToRead) {
+ FD_ZERO(&rfds);
+ FD_SET(gI2cPortContext.nHandle, &rfds);
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+ ret = select(gI2cPortContext.nHandle + 1, &rfds, NULL, NULL, &tv);
+ if (ret < 0) {
+ DAL_DEBUG("select() errno=%d", errno);
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ }
+ return -1;
+ } else if (ret == 0) {
+ DAL_PRINT("timeout!");
+ return -1;
+ }
ret = read(gI2cPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead);
if (ret > 0) {
DAL_DEBUG("read %d bytes", ret);
diff --git a/Linux_x86/phDal4Nfc_uart.c b/Linux_x86/phDal4Nfc_uart.c
index b4a282d..7ab4021 100644
--- a/Linux_x86/phDal4Nfc_uart.c
+++ b/Linux_x86/phDal4Nfc_uart.c
@@ -273,11 +273,31 @@ int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead)
{
int ret;
int numRead = 0;
+ struct timeval tv;
+ fd_set rfds;
DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!");
DAL_DEBUG("_uart_read() called to read %d bytes", nNbBytesToRead);
+ // Read with 2 second timeout, so that the read thread can be aborted
+ // when the pn544 does not respond and we need to switch to FW download
+ // mode. This should be done via a control socket instead.
while (numRead < nNbBytesToRead) {
+ FD_ZERO(&rfds);
+ FD_SET(gComPortContext.nHandle, &rfds);
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+ ret = select(gComPortContext.nHandle + 1, &rfds, NULL, NULL, &tv);
+ if (ret < 0) {
+ DAL_DEBUG("select() errno=%d", errno);
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ }
+ return -1;
+ } else if (ret == 0) {
+ DAL_PRINT("timeout!");
+ return -1;
+ }
ret = read(gComPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead);
if (ret > 0) {
DAL_DEBUG("read %d bytes", ret);