summaryrefslogtreecommitdiffstats
path: root/Linux_x86
diff options
context:
space:
mode:
authorJeff Hamilton <jham@android.com>2010-10-27 21:29:08 -0500
committerJeff Hamilton <jham@android.com>2010-10-28 02:02:26 -0500
commit3e98767aaf73b4779a2bb39601806045b2ba1739 (patch)
tree6906ecae34f195da704264a2fc25dfd4ab9eb1d4 /Linux_x86
parent8763a1998eee9b43169bf0824a77b00b3b88a938 (diff)
downloadexternal_libnfc-nxp-3e98767aaf73b4779a2bb39601806045b2ba1739.zip
external_libnfc-nxp-3e98767aaf73b4779a2bb39601806045b2ba1739.tar.gz
external_libnfc-nxp-3e98767aaf73b4779a2bb39601806045b2ba1739.tar.bz2
Patch from NXP. Libnfc - Download,Reset mode management and driver workaround with delay
Change-Id: I736e5f50db749c9570b24194fe3963efbacc5c52
Diffstat (limited to 'Linux_x86')
-rw-r--r--Linux_x86/phDal4Nfc.c63
-rw-r--r--Linux_x86/phDal4Nfc_debug.h2
-rw-r--r--Linux_x86/phDal4Nfc_i2c.c51
-rw-r--r--Linux_x86/phDal4Nfc_i2c.h3
-rw-r--r--Linux_x86/phDal4Nfc_link.h5
-rw-r--r--Linux_x86/phDal4Nfc_uart.c29
-rw-r--r--Linux_x86/phDal4Nfc_uart.h3
7 files changed, 146 insertions, 10 deletions
diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c
index 88be4c8..8d0f6d3 100644
--- a/Linux_x86/phDal4Nfc.c
+++ b/Linux_x86/phDal4Nfc.c
@@ -80,6 +80,7 @@ typedef struct Dal_RdWr_st
pthread_t nWriteThread; /* Write thread Hanlde */
pthread_mutex_t nWriteEventMutex; /* Mutex to signal a write has been requested */
uint8_t * pWriteBuffer; /* Write local buffer */
+ uint8_t * pTempWriteBuffer; /* Temp Write local buffer */
int nNbOfBytesToWrite; /* Number of bytes to write */
int nNbOfBytesWritten; /* Number of bytes written */
char nWaitingOnWrite; /* Write state machine */
@@ -387,10 +388,14 @@ NFCSTATUS phDal4Nfc_Write( void *pContext, void *pHwRef,uint8_t *pBuffer, uint16
{
if((!gReadWriteContext.nWriteBusy)&&
(!gReadWriteContext.nWaitingOnWrite))
- {
+ {
+
+ gReadWriteContext.pTempWriteBuffer = (uint8_t*)malloc(length * sizeof(uint8_t));
+ memcpy(gReadWriteContext.pTempWriteBuffer,pBuffer,length);
+
DAL_DEBUG("phDal4Nfc_Write(): %d\n", length);
/* Make a copy of the passed arguments */
- gReadWriteContext.pWriteBuffer = pBuffer;
+ gReadWriteContext.pWriteBuffer = gReadWriteContext.pTempWriteBuffer;
gReadWriteContext.nNbOfBytesToWrite = length;
/* Change the write state so that thread can take over the write */
gReadWriteContext.nWriteBusy = TRUE;
@@ -596,6 +601,7 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
case ENUM_DAL_LINK_TYPE_COM5:
case ENUM_DAL_LINK_TYPE_USB:
{
+ DAL_PRINT("UART link Config");
/* Uart link interface */
gLinkFunc.init = phDal4Nfc_uart_initialize;
gLinkFunc.open_from_handle = phDal4Nfc_uart_set_open_from_handle;
@@ -605,12 +611,15 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
gLinkFunc.open_and_configure = phDal4Nfc_uart_open_and_configure;
gLinkFunc.read = phDal4Nfc_uart_read;
gLinkFunc.write = phDal4Nfc_uart_write;
+ gLinkFunc.download = phDal4Nfc_uart_download;
+ gLinkFunc.reset = phDal4Nfc_uart_reset;
}
break;
case ENUM_DAL_LINK_TYPE_I2C:
{
- /* Uart link interface */
+ DAL_PRINT("I2C link Config");
+ /* i2c link interface */
gLinkFunc.init = phDal4Nfc_i2c_initialize;
gLinkFunc.open_from_handle = phDal4Nfc_i2c_set_open_from_handle;
gLinkFunc.is_opened = phDal4Nfc_i2c_is_opened;
@@ -619,6 +628,8 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
gLinkFunc.open_and_configure = phDal4Nfc_i2c_open_and_configure;
gLinkFunc.read = phDal4Nfc_i2c_read;
gLinkFunc.write = phDal4Nfc_i2c_write;
+ gLinkFunc.download = phDal4Nfc_i2c_download;
+ gLinkFunc.reset = phDal4Nfc_i2c_reset;
break;
}
@@ -666,9 +677,47 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
gDalContext.hw_valid = TRUE;
+ phDal4Nfc_Reset(0);
+ phDal4Nfc_Reset(1);
+
return NFCSTATUS_SUCCESS;
}
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_Reset
+
+PURPOSE: Reset the PN544, using the VEN pin
+
+-----------------------------------------------------------------------------*/
+NFCSTATUS phDal4Nfc_Reset(long level)
+{
+ NFCSTATUS retstatus = NFCSTATUS_SUCCESS;
+
+ DAL_DEBUG("phDal4Nfc_Reset: VEN to %d",level);
+
+ retstatus = gLinkFunc.reset(level);
+
+ return retstatus;
+}
+
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_Download
+
+PURPOSE: Put the PN544 in download mode, using the GPIO4 pin
+
+-----------------------------------------------------------------------------*/
+NFCSTATUS phDal4Nfc_Download(long level)
+{
+ NFCSTATUS retstatus = NFCSTATUS_SUCCESS;
+
+ DAL_DEBUG("phDal4Nfc_Download: GPIO4 to %d",level);
+
+ retstatus = gLinkFunc.download(level);
+
+ return retstatus;
+}
@@ -730,7 +779,7 @@ int phDal4Nfc_ReaderThread(void * pArg)
memsetRet=memset(gReadWriteContext.pReadBuffer,0,gReadWriteContext.nNbOfBytesToRead);
/* Wait for Write Completion */
- usleep(2500);
+ usleep(5000);
gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead);
if (gReadWriteContext.nNbOfBytesRead == -1)
{
@@ -880,6 +929,12 @@ int phDal4Nfc_WriterThread(void * pArg)
}/*end writeFile*/
else /* Results ready */
{
+ // Free TempWriteBuffer
+ if(gReadWriteContext.pTempWriteBuffer != NULL)
+ {
+ free(gReadWriteContext.pTempWriteBuffer);
+ }
+
/* Write operation completed successfully.*/
sMsg.eMsgType = PHDAL4NFC_WRITE_MESSAGE;
//sMsg.pContext = pgDalContext;
diff --git a/Linux_x86/phDal4Nfc_debug.h b/Linux_x86/phDal4Nfc_debug.h
index bd6ae91..ab586ef 100644
--- a/Linux_x86/phDal4Nfc_debug.h
+++ b/Linux_x86/phDal4Nfc_debug.h
@@ -5,7 +5,7 @@
DEBUG CORNER
------------------------------------------------------------------------------------*/
/* Activate for debug */
-//#define DAL_TRACE
+#define DAL_TRACE
#ifdef DAL_TRACE
#include <stdio.h>
diff --git a/Linux_x86/phDal4Nfc_i2c.c b/Linux_x86/phDal4Nfc_i2c.c
index 8a54bee..8cd4a1a 100644
--- a/Linux_x86/phDal4Nfc_i2c.c
+++ b/Linux_x86/phDal4Nfc_i2c.c
@@ -36,6 +36,9 @@
#include <string.h>
#endif
+#define PN544_RESET_CMD 0
+#define PN544_DOWNLOAD_CMD 1
+
typedef struct
{
int nHandle;
@@ -78,7 +81,7 @@ PURPOSE: The application could have opened the link itself. So we just need
void phDal4Nfc_i2c_set_open_from_handle(phHal_sHwReference_t * pDalHwContext)
{
gI2cPortContext.nHandle = (int) pDalHwContext->p_board_driver;
- DAL_ASSERT_STR(gComPortContext.nHandle >= 0, "Bad passed com port handle");
+ DAL_ASSERT_STR(gI2cPortContext.nHandle >= 0, "Bad passed com port handle");
gI2cPortContext.nOpened = 1;
}
@@ -183,7 +186,7 @@ PURPOSE: Reads nNbBytesToRead bytes and writes them in pBuffer.
int phDal4Nfc_i2c_read(uint8_t * pBuffer, int nNbBytesToRead)
{
int ret;
- DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!");
+ DAL_ASSERT_STR(gI2cPortContext.nOpened == 1, "read called but not opened!");
DAL_DEBUG("Reading %d bytes\n", nNbBytesToRead);
ret = read(gI2cPortContext.nHandle, pBuffer, nNbBytesToRead);
@@ -210,7 +213,7 @@ PURPOSE: Writes nNbBytesToWrite bytes from pBuffer to the link
int phDal4Nfc_i2c_write(uint8_t * pBuffer, int nNbBytesToWrite)
{
int ret;
- DAL_ASSERT_STR(gComPortContext.nOpened == 1, "write called but not opened!");
+ DAL_ASSERT_STR(gI2cPortContext.nOpened == 1, "write called but not opened!");
DAL_DEBUG("Writing %d bytes\n", nNbBytesToWrite);
ret = write(gI2cPortContext.nHandle, pBuffer, nNbBytesToWrite);
@@ -224,3 +227,45 @@ int phDal4Nfc_i2c_write(uint8_t * pBuffer, int nNbBytesToWrite)
}
return ret;
}
+
+
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_i2c_reset
+
+PURPOSE: Reset the PN544, using the VEN pin
+
+-----------------------------------------------------------------------------*/
+int phDal4Nfc_i2c_reset(long level)
+{
+ int ret = NFCSTATUS_SUCCESS;
+
+ DAL_DEBUG("phDal4Nfc_i2c_reset, VEN level = %d",level);
+
+ ret = ioctl(gI2cPortContext.nHandle, PN544_RESET_CMD, level);
+
+ return ret;
+}
+
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_i2c_write
+
+PURPOSE: Put the PN544 in download mode, using the GPIO4 pin
+
+-----------------------------------------------------------------------------*/
+int phDal4Nfc_i2c_download(long level)
+{
+ int ret = NFCSTATUS_SUCCESS;
+
+ DAL_DEBUG("phDal4Nfc_i2c_download, GPIO4 level = %d",level);
+
+ ret = ioctl(gI2cPortContext.nHandle, PN544_DOWNLOAD_CMD, level);
+
+ return ret;
+}
+
+
+
+
+
diff --git a/Linux_x86/phDal4Nfc_i2c.h b/Linux_x86/phDal4Nfc_i2c.h
index fe391aa..f9dda6a 100644
--- a/Linux_x86/phDal4Nfc_i2c.h
+++ b/Linux_x86/phDal4Nfc_i2c.h
@@ -36,4 +36,5 @@ void phDal4Nfc_i2c_close(void);
NFCSTATUS phDal4Nfc_i2c_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle);
int phDal4Nfc_i2c_read(uint8_t * pBuffer, int nNbBytesToRead);
int phDal4Nfc_i2c_write(uint8_t * pBuffer, int nNbBytesToWrite);
-
+int phDal4Nfc_i2c_reset(long level);
+int phDal4Nfc_i2c_download(long level);
diff --git a/Linux_x86/phDal4Nfc_link.h b/Linux_x86/phDal4Nfc_link.h
index e26ab11..89dec1c 100644
--- a/Linux_x86/phDal4Nfc_link.h
+++ b/Linux_x86/phDal4Nfc_link.h
@@ -40,6 +40,9 @@ typedef void (*phDal4Nfc_link_close_CB_t) (void);
typedef NFCSTATUS (*phDal4Nfc_link_open_and_configure_CB_t) (pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle);
typedef int (*phDal4Nfc_link_read_CB_t) (uint8_t * pBuffer, int nNbBytesToRead);
typedef int (*phDal4Nfc_link_write_CB_t) (uint8_t * pBuffer, int nNbBytesToWrite);
+typedef int (*phDal4Nfc_link_download_CB_t) (long level);
+typedef int (*phDal4Nfc_link_reset_CB_t) (long level);
+
typedef struct
{
@@ -51,6 +54,8 @@ typedef struct
phDal4Nfc_link_open_and_configure_CB_t open_and_configure;
phDal4Nfc_link_read_CB_t read;
phDal4Nfc_link_write_CB_t write;
+ phDal4Nfc_link_download_CB_t download;
+ phDal4Nfc_link_reset_CB_t reset;
} phDal4Nfc_link_cbk_interface_t;
diff --git a/Linux_x86/phDal4Nfc_uart.c b/Linux_x86/phDal4Nfc_uart.c
index 9d230f1..30cb500 100644
--- a/Linux_x86/phDal4Nfc_uart.c
+++ b/Linux_x86/phDal4Nfc_uart.c
@@ -324,3 +324,32 @@ int phDal4Nfc_uart_write(uint8_t * pBuffer, int nNbBytesToWrite)
return 0;
}
+
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_uart_reset
+
+PURPOSE: Reset the PN544, using the VEN pin
+
+-----------------------------------------------------------------------------*/
+int phDal4Nfc_uart_reset()
+{
+ DAL_PRINT("phDal4Nfc_uart_reset");
+
+ return NFCSTATUS_FEATURE_NOT_SUPPORTED;
+}
+
+/*-----------------------------------------------------------------------------
+
+FUNCTION: phDal4Nfc_uart_write
+
+PURPOSE: Put the PN544 in download mode, using the GPIO4 pin
+
+-----------------------------------------------------------------------------*/
+int phDal4Nfc_uart_download()
+{
+ DAL_PRINT("phDal4Nfc_uart_download");
+
+ return NFCSTATUS_FEATURE_NOT_SUPPORTED;
+}
+
diff --git a/Linux_x86/phDal4Nfc_uart.h b/Linux_x86/phDal4Nfc_uart.h
index 329f626..1a19486 100644
--- a/Linux_x86/phDal4Nfc_uart.h
+++ b/Linux_x86/phDal4Nfc_uart.h
@@ -40,4 +40,5 @@ void phDal4Nfc_uart_close(void);
NFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle);
int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead);
int phDal4Nfc_uart_write(uint8_t * pBuffer, int nNbBytesToWrite);
-
+int phDal4Nfc_uart_reset();
+int phDal4Nfc_uart_download();