fix few minor bugs:

- timeout values handling in pn53x_transceive()
- check error code after filling it in pn53x_transceive()
- fix pn53x_check_communication() return code
- lower timeout default values
- fix arygon_abort() return code
This commit is contained in:
Romuald Conty 2012-01-04 20:02:51 +00:00
parent 52c72383f1
commit 254053b940
3 changed files with 19 additions and 16 deletions

View file

@ -113,10 +113,15 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
}
PNCMD_TRACE (pbtTx[0]);
if (timeout > 0)
if (timeout > 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeout values: %d", timeout);
if (timeout == -1)
} else if (timeout == 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No timeout");
} else if (timeout == -1) {
timeout = CHIP_DATA (pnd)->timeout_command;
} else {
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Invalid timeout value: %d", timeout);
}
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof(abtRx);
@ -144,9 +149,6 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
return NFC_ECHIP;
}
if (CHIP_DATA(pnd)->last_status_byte)
return NFC_ECHIP;
if ((CHIP_DATA(pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically wakeup on external RF field
CHIP_DATA(pnd)->power_mode = NORMAL; // When TgInitAsTarget reply that means an external RF have waken up the chip
}
@ -194,6 +196,10 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
CHIP_DATA(pnd)->last_status_byte = 0;
}
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Last command status: %s", pn53x_strerror(pnd));
if (CHIP_DATA(pnd)->last_status_byte)
return NFC_ECHIP;
return ((0 == CHIP_DATA(pnd)->last_status_byte) ? NFC_SUCCESS : NFC_ECHIP);
}
@ -880,13 +886,13 @@ pn53x_check_communication (struct nfc_device *pnd)
size_t szRx = sizeof (abtRx);
int res = 0;
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 1000)) < 0)
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 500)) < 0)
return res;
if (((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx)))) == 0)
return NFC_ECHIP;
return NFC_SUCCESS;
return NFC_EIO;
}
int
@ -2709,8 +2715,8 @@ pn53x_data_new (struct nfc_device *pnd, const struct pn53x_io *io)
CHIP_DATA (pnd)->wb_trigged = false;
memset (CHIP_DATA (pnd)->wb_mask, 0x00, PN53X_CACHE_REGISTER_SIZE);
// Set default command timeout (500 ms)
CHIP_DATA (pnd)->timeout_command = 500;
// Set default command timeout (250 ms)
CHIP_DATA (pnd)->timeout_command = 250;
// Set default ATR timeout (103 ms)
CHIP_DATA (pnd)->timeout_atr = 103;

View file

@ -362,7 +362,7 @@ arygon_abort (nfc_device *pnd)
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), 0);
// Using Arygon device we can't send ACK frame to abort the running command
return (pn53x_check_communication (pnd) == 0) ? 0 : -1;
return pn53x_check_communication (pnd);
}
int
@ -519,7 +519,7 @@ arygon_reset_tama (nfc_device *pnd)
size_t szRx = sizeof(abtRx);
int res;
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), 1000);
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), 500);
// 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)

View file

@ -115,9 +115,6 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
// Check communication using "Diagnose" command, with "Communication test" (0x00)
int res = pn53x_check_communication (pnd);
if(res < 0) {
nfc_perror (pnd, "pn53x_check_communication");
}
pn53x_data_free (pnd);
nfc_device_free (pnd);
uart_close (sp);
@ -301,7 +298,7 @@ pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i
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, 1000) < 0) {
if (pn53x_SAMConfiguration (pnd, 0x01, 500) < 0) {
return false;
}
}