diff options
author | Daniel TOMAS <dtomas.nxp@gmail.com> | 2011-09-09 12:08:26 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-09-09 12:08:26 -0700 |
commit | df34eb0ea8cf035c5ca8e118773a614d92da943b (patch) | |
tree | 051e3869f4e125f85eb10adaae8ec646128b7b6c /Linux_x86 | |
parent | 6c66debfd84e2d7206cd566e7234b6f0518bd733 (diff) | |
parent | dd163fe4ad38d2064de2913697907e45229a8dce (diff) | |
download | external_libnfc-nxp-df34eb0ea8cf035c5ca8e118773a614d92da943b.zip external_libnfc-nxp-df34eb0ea8cf035c5ca8e118773a614d92da943b.tar.gz external_libnfc-nxp-df34eb0ea8cf035c5ca8e118773a614d92da943b.tar.bz2 |
am dd163fe4: am df82c4dd: Patch to add an API to load a FW image in the libnfc
* commit 'dd163fe4ad38d2064de2913697907e45229a8dce':
Patch to add an API to load a FW image in the libnfc
Diffstat (limited to 'Linux_x86')
-rw-r--r-- | Linux_x86/phDal4Nfc.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c index 6d3c9fb..ec92566 100644 --- a/Linux_x86/phDal4Nfc.c +++ b/Linux_x86/phDal4Nfc.c @@ -282,7 +282,7 @@ NFCSTATUS phDal4Nfc_Shutdown( void *pContext, void *pHwRef) return result; } -NFCSTATUS phDal4Nfc_ConfigRelease( void *pHwRef) +NFCSTATUS phDal4Nfc_ConfigRelease(void *pHwRef) { NFCSTATUS result = NFCSTATUS_SUCCESS; @@ -292,19 +292,23 @@ NFCSTATUS phDal4Nfc_ConfigRelease( void *pHwRef) if (gDalContext.hw_valid == TRUE) { - DAL_PRINT("Release Read Semaphore"); - sem_post(&nfc_read_sem); - - /* Kill the read and write threads */ - DAL_PRINT("Stop Reader Thread"); - gReadWriteContext.nReadThreadAlive = 0; - gReadWriteContext.nWriteThreadAlive = 0; - - if (pthread_join(gReadWriteContext.nReadThread, &pThreadReturn) != 0) - { - result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED); - DAL_PRINT("phDal4Nfc_ConfigRelease KO"); - } + /* Signal the read and write threads to exit. NOTE: there + actually is no write thread! :) */ + DAL_PRINT("Stop Reader Thread"); + gReadWriteContext.nReadThreadAlive = 0; + gReadWriteContext.nWriteThreadAlive = 0; + + /* Wake up the read thread so it can exit */ + DAL_PRINT("Release Read Semaphore"); + sem_post(&nfc_read_sem); + + DAL_DEBUG("phDal4Nfc_ConfigRelease - doing pthread_join(%d)", + gReadWriteContext.nReadThread); + if (pthread_join(gReadWriteContext.nReadThread, &pThreadReturn) != 0) + { + result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED); + DAL_PRINT("phDal4Nfc_ConfigRelease KO"); + } /* Close the message queue */ #ifdef USE_MQ_MESSAGE_QUEUE @@ -583,6 +587,7 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref) gDalContext.hw_valid = TRUE; + phDal4Nfc_Reset(1); phDal4Nfc_Reset(0); phDal4Nfc_Reset(1); @@ -677,12 +682,20 @@ int phDal4Nfc_ReaderThread(void * pArg) DAL_PRINT("RX Thread Sem Lock\n"); sem_wait(&nfc_read_sem); DAL_PRINT("RX Thread Sem UnLock\n"); + + if (!gReadWriteContext.nReadThreadAlive) + { + /* got the signal that we should exit. NOTE: we don't + attempt to read below, since the read may block */ + break; + } + /* Issue read operation.*/ i2c_error_count = 0; retry: gReadWriteContext.nNbOfBytesRead=0; - DAL_DEBUG("\n*New *** *****Request Length = %d",gReadWriteContext.nNbOfBytesToRead); + DAL_DEBUG("RX Thread *New *** *****Request Length = %d",gReadWriteContext.nNbOfBytesToRead); memsetRet=memset(gReadWriteContext.pReadBuffer,0,gReadWriteContext.nNbOfBytesToRead); /* Wait for IRQ !!! */ @@ -696,12 +709,12 @@ retry: if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57) { i2c_error_count++; - DAL_DEBUG("Read 0x57 %d times\n", i2c_error_count); + DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count); if (i2c_error_count < 5) { usleep(2000); goto retry; } - DAL_PRINT("NOTHING TO READ, RECOVER"); + DAL_PRINT("RX Thread NOTHING TO READ, RECOVER"); phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); } else @@ -710,14 +723,14 @@ retry: #ifdef LOW_LEVEL_TRACES phOsalNfc_PrintData("Received buffer", (uint16_t)gReadWriteContext.nNbOfBytesRead, gReadWriteContext.pReadBuffer); #endif - DAL_DEBUG("Read ok. nbToRead=%d\n", gReadWriteContext.nNbOfBytesToRead); - DAL_DEBUG("NbReallyRead=%d\n", gReadWriteContext.nNbOfBytesRead); - DAL_PRINT("ReadBuff[]={ "); + DAL_DEBUG("RX Thread Read ok. nbToRead=%d\n", gReadWriteContext.nNbOfBytesToRead); + DAL_DEBUG("RX Thread NbReallyRead=%d\n", gReadWriteContext.nNbOfBytesRead); + DAL_PRINT("RX Thread ReadBuff[]={ "); for (i = 0; i < gReadWriteContext.nNbOfBytesRead; i++) { - DAL_DEBUG("0x%x ", gReadWriteContext.pReadBuffer[i]); + DAL_DEBUG("RX Thread 0x%x ", gReadWriteContext.pReadBuffer[i]); } - DAL_PRINT("}\n"); + DAL_PRINT("RX Thread }\n"); /* read completed immediately */ sMsg.eMsgType= PHDAL4NFC_READ_MESSAGE; @@ -729,6 +742,9 @@ retry: } } /* End of thread Loop*/ + + DAL_PRINT("RX Thread exiting"); + return TRUE; } @@ -952,4 +968,3 @@ void phDal4Nfc_DeferredCall(pphDal4Nfc_DeferFuncPointer_t func, void *param) } #undef _DAL_4_NFC_C - |