summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Linux_x86/phDal4Nfc.c61
-rw-r--r--src/phLibNfc.c10
-rw-r--r--src/phLibNfc.h2
3 files changed, 50 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
-
diff --git a/src/phLibNfc.c b/src/phLibNfc.c
index 71225ba..fa28bf5 100644
--- a/src/phLibNfc.c
+++ b/src/phLibNfc.c
@@ -45,6 +45,8 @@
*************************** Macro's ******************************************
*/
+extern int dlopen_firmware();
+
#ifndef STATIC_DISABLE
#define STATIC static
#else
@@ -106,6 +108,7 @@ NFCSTATUS phLibNfc_HW_Reset ()
{
NFCSTATUS Status = NFCSTATUS_SUCCESS;
+ Status = phDal4Nfc_Reset(1);
Status = phDal4Nfc_Reset(0);
Status = phDal4Nfc_Reset(1);
@@ -117,6 +120,13 @@ NFCSTATUS phLibNfc_Download_Mode ()
return phDal4Nfc_Download();
}
+int phLibNfc_Load_Firmware_Image ()
+{
+ int status;
+ status = dlopen_firmware();
+ return status;
+}
+
extern uint8_t nxp_nfc_isoxchg_timeout;
NFCSTATUS phLibNfc_SetIsoXchgTimeout(uint8_t timeout) {
diff --git a/src/phLibNfc.h b/src/phLibNfc.h
index 790d619..719cfc1 100644
--- a/src/phLibNfc.h
+++ b/src/phLibNfc.h
@@ -851,6 +851,8 @@ NFCSTATUS phLibNfc_HW_Reset ();
NFCSTATUS phLibNfc_Download_Mode ();
+int phLibNfc_Load_Firmware_Image ();
+
// timeout is 8 bits
// bits [0..3] => timeout value, (256*16/13.56*10^6) * 2^value
// [0] -> 0.0003s