Skip to content

Commit

Permalink
Adapt *transmit_bytes_timed API to be closer to *transmit_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Nov 12, 2012
1 parent 6c7c0a6 commit fda8d60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern "C" {
NFC_EXPORT int nfc_initiator_deselect_target(nfc_device *pnd);
NFC_EXPORT int nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout);
NFC_EXPORT int nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
NFC_EXPORT int nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_transceive_bits_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt);

Expand Down
19 changes: 13 additions & 6 deletions libnfc/chips/pn53x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ pn53x_initiator_transceive_bits_timed(struct nfc_device *pnd, const uint8_t *pbt
}

int
pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles)
{
uint16_t i;
uint8_t sz;
Expand Down Expand Up @@ -1602,7 +1602,7 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb
}

// Recv data
size_t szRx = 0;
size_t szRxLen = 0;
// we've to watch for coming data until we decide to timeout.
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
// responses coming very late anyway.
Expand Down Expand Up @@ -1632,10 +1632,17 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb
if ((res = pn53x_transceive(pnd, abtReadRegisterCmd, BUFFER_SIZE(abtReadRegisterCmd), abtRes, szRes, -1)) < 0) {
return res;
}
for (i = 0; i < sz; i++) {
pbtRx[i + szRx] = abtRes[i + off];
if (pbtRx != NULL) {
if ((szRxLen + sz) > szRx) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Buffer size is too short: %zuo available(s), %zuo needed", szRx, szRxLen + sz);
return NFC_EOVFLOW;
}
// Copy the received bytes
for (i = 0; i < sz; i++) {
pbtRx[i + szRxLen] = abtRes[i + off];
}
}
szRx += (size_t)(sz & SYMBOL_FIFO_LEVEL);
szRxLen += (size_t)(sz & SYMBOL_FIFO_LEVEL);
sz = abtRes[sz + off];
if (sz == 0)
break;
Expand All @@ -1653,7 +1660,7 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb
} else {
*cycles = __pn53x_get_timer(pnd, pbtTx[szTx - 1]);
}
return szRx;
return szRxLen;
}

int
Expand Down
2 changes: 1 addition & 1 deletion libnfc/chips/pn53x.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ int pn53x_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *p
int pn53x_initiator_transceive_bits_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
int pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
uint8_t *pbtRx, uint32_t *cycles);
uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
int pn53x_initiator_deselect_target(struct nfc_device *pnd);
int pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target nt);

Expand Down
2 changes: 1 addition & 1 deletion libnfc/nfc-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct nfc_driver {
int (*initiator_deselect_target)(struct nfc_device *pnd);
int (*initiator_transceive_bytes)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout);
int (*initiator_transceive_bits)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles);
int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
int (*initiator_transceive_bits_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
int (*initiator_target_is_present)(struct nfc_device *pnd, const nfc_target nt);

Expand Down
4 changes: 2 additions & 2 deletions libnfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
*/
int
nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles)
{
HAL(initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles);
HAL(initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, szRx, cycles);
}

/** @ingroup initiator
Expand Down

0 comments on commit fda8d60

Please sign in to comment.