support crc auto-handling in ...transceive_bytes_timed

This commit is contained in:
Philippe Teuwen 2011-04-04 22:23:38 +00:00
parent 8d70321d80
commit 7f2b300dde
2 changed files with 14 additions and 11 deletions

View file

@ -1195,15 +1195,14 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx,
unsigned int i;
uint8_t sz;
// We can not just send bytes without parity while the PN53X expects we handled them
// Sorry, no arbitrary parity bits support for now
if (!pnd->bPar)
return false;
// Sorry, no easy framing support
// TODO: to be changed once we'll provide easy framing support from libnfc itself...
if (pnd->bEasyFraming)
return false;
// Sorry, no CRC support
// TODO: to be changed once we'll provide easy CRC support from libnfc itself...
// TODO but it probably doesn't make sense for (szTxBits % 8 != 0) ...
if (pnd->bCrc)
return false;
@ -1293,10 +1292,6 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx
// TODO: to be changed once we'll provide easy framing support from libnfc itself...
if (pnd->bEasyFraming)
return false;
// Sorry, no CRC support
// TODO: to be changed once we'll provide easy CRC support from libnfc itself...
if (pnd->bCrc)
return false;
__pn53x_init_timer(pnd);
@ -1321,8 +1316,17 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx
}
// Recv corrected timer value
*cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]);
if (pnd->bCrc) {
// We've to compute CRC ourselves to know last byte actually sent
uint8_t * pbtTxRaw;
pbtTxRaw = (uint8_t *) malloc(szTx+2);
memcpy (pbtTxRaw, pbtTx, szTx);
iso14443a_crc_append (pbtTxRaw, szTx);
*cycles = __pn53x_get_timer (pnd, pbtTxRaw[szTx +1]);
free(pbtTxRaw);
} else {
*cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]);
}
return true;
}

View file

@ -541,11 +541,10 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s
*
* This function is similar to nfc_initiator_transceive_bytes() with the following differences:
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
* - It only supports mode with \a NDO_EASY_FRAMING option disabled and CRC must be handled manually.
* - It only supports mode with \a NDO_EASY_FRAMING option disabled.
* - Overall communication with the host is heavier and slower.
*
* @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false.
* @warning The configuration option \a NDO_HANDLE_CRC must be set to \c false.
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
*/
bool