diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 26eb0b7..7937b27 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1109,7 +1109,7 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons return true; } -void __pn53x_init_timer(nfc_device_t * pnd) +void __pn53x_init_timer(nfc_device_t * pnd, const uint32_t max_cycles) { // The prescaler will dictate what will be the precision and // the largest delay to measure before saturation. Some examples: @@ -1117,7 +1117,11 @@ void __pn53x_init_timer(nfc_device_t * pnd) // prescaler = 1 => precision: ~221ns timer saturates at ~15ms // prescaler = 2 => precision: ~369ns timer saturates at ~25ms // prescaler = 10 => precision: ~1.5us timer saturates at ~100ms - CHIP_DATA (pnd)->timer_prescaler = 0; + if (max_cycles > 0xFFFF) { + CHIP_DATA (pnd)->timer_prescaler = ((max_cycles/0xFFFF)-1)/2; + } else { + CHIP_DATA (pnd)->timer_prescaler = 0; + } uint16_t reloadval = 0xFFFF; // Initialize timer pn53x_write_register (pnd, PN53X_REG_CIU_TMode, 0xFF, SYMBOL_TAUTO | ((CHIP_DATA (pnd)->timer_prescaler >> 8) & SYMBOL_TPRESCALERHI)); @@ -1213,7 +1217,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, return false; } - __pn53x_init_timer(pnd); + __pn53x_init_timer(pnd, *cycles); // Once timer is started, we cannot use Tama commands anymore. // E.g. on SCL3711 timer settings are reset by 0x42 InCommunicateThru command to: @@ -1308,7 +1312,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx return false; } - __pn53x_init_timer(pnd); + __pn53x_init_timer(pnd, *cycles); // Once timer is started, we cannot use Tama commands anymore. // E.g. on SCL3711 timer settings are reset by 0x42 InCommunicateThru command to: diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 0d116b1..94523fb 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -560,6 +560,12 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s * - It only supports mode with \a NDO_EASY_FRAMING option disabled. * - Overall communication with the host is heavier and slower. * + * Timer control: + * By default timer can count up to 65535 cycles, so about 4.8ms, with a precision of about 73ns. + * - If you're ok with the defaults, set *cycles = 0 before calling this function. + * - If you need to count more cycles, set *cycles to the maximum you expect but don't forget + * you'll loose in precision and it'll take more time before timeout, so don't abuse! + * * @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false. * @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value). */ @@ -579,6 +585,12 @@ nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, * - It only supports mode with \a NDO_EASY_FRAMING option disabled and CRC must be handled manually. * - Overall communication with the host is heavier and slower. * + * Timer control: + * By default timer can count up to 65535 cycles, so about 4.8ms, with a precision of about 73ns. + * - If you're ok with the defaults, set *cycles = 0 before calling this function. + * - If you need to count more cycles, set *cycles to the maximum you expect but don't forget + * you'll loose in precision and it'll take more time before timeout, so don't abuse! + * * @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).