drivers/arygon,pn532_uart,pn53x_usb: all PN53x commands are now cancelable

This commit is contained in:
Romuald Conty
2011-09-29 14:53:52 +00:00
parent 49ab6a7f31
commit 8f7834c625
7 changed files with 54 additions and 73 deletions
+21 -20
View File
@@ -124,6 +124,13 @@ arygon_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDev
// Alloc and init chip's data
pn53x_data_new (pnd, &arygon_tama_io);
#ifndef WIN32
// pipe-based abort mecanism
pipe (DRIVER_DATA (pnd)->iAbortFds);
#else
DRIVER_DATA (pnd)->abort_flag = false;
#endif
bool res = arygon_reset_tama (pnd);
pn53x_data_free (pnd);
nfc_device_free (pnd);
@@ -193,12 +200,6 @@ arygon_connect (const nfc_device_desc_t * pndd)
CHIP_DATA (pnd)->timer_correction = 46;
pnd->driver = &arygon_driver;
// Check communication using "Reset TAMA" command
if (!arygon_reset_tama(pnd)) {
nfc_device_free (pnd);
return NULL;
}
#ifndef WIN32
// pipe-based abort mecanism
pipe (DRIVER_DATA (pnd)->iAbortFds);
@@ -206,6 +207,12 @@ arygon_connect (const nfc_device_desc_t * pndd)
DRIVER_DATA (pnd)->abort_flag = false;
#endif
// Check communication using "Reset TAMA" command
if (!arygon_reset_tama(pnd)) {
nfc_device_free (pnd);
return NULL;
}
char arygon_firmware_version[10];
arygon_firmware (pnd, arygon_firmware_version);
char *pcName;
@@ -304,21 +311,11 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
size_t len;
void * abort_p = NULL;
switch (CHIP_DATA (pnd)->ui8LastCommand) {
case InAutoPoll:
case InDataExchange:
case InJumpForDEP:
case TgGetData:
case TgInitAsTarget:
#ifndef WIN32
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
#else
abort_p = &(DRIVER_DATA (pnd)->abort_flag);
abort_p = &(DRIVER_DATA (pnd)->abort_flag);
#endif
break;
default:
break;
}
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p, timeout);
@@ -461,11 +458,15 @@ arygon_reset_tama (nfc_device_t * pnd)
size_t szRx = sizeof(abtRx);
int res;
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), NULL);
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), &tv);
// Two reply are possible from ARYGON device: arygon_error_none (ie. in case the byte is well-sent)
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, NULL);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, &tv);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No reply to 'reset TAMA' command.");
return false;
+20 -20
View File
@@ -105,6 +105,13 @@ pn532_uart_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * ps
// This device starts in LowVBat power mode
CHIP_DATA (pnd)->power_mode = LOWVBAT;
#ifndef WIN32
// pipe-based abort mecanism
pipe (DRIVER_DATA (pnd)->iAbortFds);
#else
DRIVER_DATA (pnd)->abort_flag = false;
#endif
// Check communication using "Diagnose" command, with "Communication test" (0x00)
bool res = pn53x_check_communication (pnd);
if(!res) {
@@ -176,13 +183,6 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
CHIP_DATA(pnd)->timer_correction = 48;
pnd->driver = &pn532_uart_driver;
// Check communication using "Diagnose" command, with "Communication test" (0x00)
if (!pn53x_check_communication (pnd)) {
nfc_perror (pnd, "pn53x_check_communication");
pn532_uart_disconnect(pnd);
return NULL;
}
#ifndef WIN32
// pipe-based abort mecanism
pipe (DRIVER_DATA (pnd)->iAbortFds);
@@ -190,6 +190,13 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
DRIVER_DATA (pnd)->abort_flag = false;
#endif
// Check communication using "Diagnose" command, with "Communication test" (0x00)
if (!pn53x_check_communication (pnd)) {
nfc_perror (pnd, "pn53x_check_communication");
pn532_uart_disconnect(pnd);
return NULL;
}
pn53x_init(pnd);
return pnd;
}
@@ -234,7 +241,10 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData
return false;
}
// According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
if (!pn53x_SAMConfiguration (pnd, 0x01)) {
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
if (!pn53x_SAMConfiguration (pnd, 0x01, &tv)) {
return false;
}
}
@@ -288,21 +298,11 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
size_t len;
void * abort_p = NULL;
switch (CHIP_DATA (pnd)->ui8LastCommand) {
case InAutoPoll:
case InDataExchange:
case InJumpForDEP:
case TgGetData:
case TgInitAsTarget:
#ifndef WIN32
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
#else
abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
#endif
break;
default:
break;
}
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout);
+1 -13
View File
@@ -489,18 +489,6 @@ pn53x_usb_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen,
{
size_t len;
off_t offset = 0;
bool delayed_reply = false;
switch (CHIP_DATA (pnd)->ui8LastCommand) {
case InDataExchange:
case TgGetData:
case InJumpForDEP:
case TgInitAsTarget:
delayed_reply = true;
break;
default:
break;
}
byte_t abtRxBuf[PN53X_USB_BUFFER_LEN];
int res;
@@ -537,7 +525,7 @@ read:
}
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), &usb_timeout);
if (delayed_reply && (res == -USB_TIMEDOUT)) {
if (res == -USB_TIMEDOUT) {
if (DRIVER_DATA (pnd)->abort_flag) {
DRIVER_DATA (pnd)->abort_flag = false;
pn53x_usb_ack (pnd);