From 92c7e0144b84a27b4573043fef718a8ba458d062 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Sat, 7 May 2011 20:25:41 -0700 Subject: Retry i2c read 5 times on i2c read error. Change-Id: I9fd0291bfd8ba9d26a0c93bc14d7184a9a188b90 --- Linux_x86/phDal4Nfc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Linux_x86') diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c index d7e306b..a39f062 100644 --- a/Linux_x86/phDal4Nfc.c +++ b/Linux_x86/phDal4Nfc.c @@ -661,6 +661,7 @@ int phDal4Nfc_ReaderThread(void * pArg) phDal4Nfc_Message_t sMsg; phOsalNfc_Message_t OsalMsg ; int i; + int i2c_error_count; pthread_setname_np(pthread_self(), "reader"); @@ -677,6 +678,9 @@ int phDal4Nfc_ReaderThread(void * pArg) sem_wait(&nfc_read_sem); DAL_PRINT("RX Thread Sem UnLock\n"); /* Issue read operation.*/ + + i2c_error_count = 0; +retry: gReadWriteContext.nNbOfBytesRead=0; DAL_DEBUG("\n*New *** *****Request Length = %d",gReadWriteContext.nNbOfBytesToRead); memsetRet=memset(gReadWriteContext.pReadBuffer,0,gReadWriteContext.nNbOfBytesToRead); @@ -691,11 +695,18 @@ int phDal4Nfc_ReaderThread(void * pArg) */ if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57) { + i2c_error_count++; + DAL_DEBUG("Read 0x57 %d times\n", i2c_error_count); + if (i2c_error_count < 5) { + usleep(2000); + goto retry; + } DAL_PRINT("NOTHING TO READ, RECOVER"); phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); } else { + i2c_error_count = 0; DAL_DEBUG("Read ok. nbToRead=%d\n", gReadWriteContext.nNbOfBytesToRead); DAL_DEBUG("NbReallyRead=%d\n", gReadWriteContext.nNbOfBytesRead); DAL_PRINT("ReadBuff[]={ "); -- cgit v1.1