Move prescaler to CHIP_DATA struct & remove some compilation warnings
This commit is contained in:
parent
ab54a37678
commit
b98afced69
2 changed files with 14 additions and 17 deletions
|
@ -882,8 +882,6 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
||||||
// Some work to do before getting the UID...
|
// Some work to do before getting the UID...
|
||||||
byte_t abtReqt[]="\x10";
|
byte_t abtReqt[]="\x10";
|
||||||
size_t szReqtLen = 1;
|
size_t szReqtLen = 1;
|
||||||
byte_t abtRx[2];
|
|
||||||
size_t szRxLen = 2;
|
|
||||||
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later
|
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later
|
||||||
if (!pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData) || szTargetsData != 2) {
|
if (!pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData) || szTargetsData != 2) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -897,8 +895,6 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
|
||||||
return false;
|
return false;
|
||||||
byte_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4)
|
byte_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4)
|
||||||
size_t szReadLen = 1;
|
size_t szReadLen = 1;
|
||||||
byte_t abtRx[2];
|
|
||||||
size_t szRxLen = 2;
|
|
||||||
if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData) || szTargetsData != 2) {
|
if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData) || szTargetsData != 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1113,20 +1109,19 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For _timer() functions, the prescaler will dictate what will
|
void __pn53x_init_timer(nfc_device_t * pnd)
|
||||||
// be the precision and the largest delay to measure before saturation
|
{
|
||||||
|
// The prescaler will dictate what will be the precision and
|
||||||
|
// the largest delay to measure before saturation. Some examples:
|
||||||
// prescaler = 0 => precision: ~73ns timer saturates at ~5ms
|
// prescaler = 0 => precision: ~73ns timer saturates at ~5ms
|
||||||
// prescaler = 1 => precision: ~221ns timer saturates at ~15ms
|
// prescaler = 1 => precision: ~221ns timer saturates at ~15ms
|
||||||
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
|
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
|
||||||
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
|
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
|
||||||
static uint16_t __timer_prescaler = 0;
|
CHIP_DATA (pnd)->timer_prescaler = 0;
|
||||||
|
|
||||||
void __pn53x_init_timer(nfc_device_t * pnd)
|
|
||||||
{
|
|
||||||
uint16_t reloadval = 0xFFFF;
|
uint16_t reloadval = 0xFFFF;
|
||||||
// Initialize timer
|
// Initialize timer
|
||||||
pn53x_write_register (pnd, PN53X_REG_CIU_TMode, 0xFF, SYMBOL_TAUTO | ((__timer_prescaler >> 8) & SYMBOL_TPRESCALERHI));
|
pn53x_write_register (pnd, PN53X_REG_CIU_TMode, 0xFF, SYMBOL_TAUTO | ((CHIP_DATA (pnd)->timer_prescaler >> 8) & SYMBOL_TPRESCALERHI));
|
||||||
pn53x_write_register (pnd, PN53X_REG_CIU_TPrescaler, 0xFF, (__timer_prescaler & SYMBOL_TPRESCALERLO));
|
pn53x_write_register (pnd, PN53X_REG_CIU_TPrescaler, 0xFF, (CHIP_DATA (pnd)->timer_prescaler & SYMBOL_TPRESCALERLO));
|
||||||
pn53x_write_register (pnd, PN53X_REG_CIU_TReloadVal_hi, 0xFF, (reloadval >> 8) & 0xFF);
|
pn53x_write_register (pnd, PN53X_REG_CIU_TReloadVal_hi, 0xFF, (reloadval >> 8) & 0xFF);
|
||||||
pn53x_write_register (pnd, PN53X_REG_CIU_TReloadVal_lo, 0xFF, reloadval & 0xFF);
|
pn53x_write_register (pnd, PN53X_REG_CIU_TReloadVal_lo, 0xFF, reloadval & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -1165,7 +1160,7 @@ uint32_t __pn53x_get_timer(nfc_device_t * pnd, const uint8_t last_cmd_byte)
|
||||||
} else {
|
} else {
|
||||||
u16cycles = 0xFFFF - counter;
|
u16cycles = 0xFFFF - counter;
|
||||||
u32cycles = u16cycles;
|
u32cycles = u16cycles;
|
||||||
u32cycles *= (__timer_prescaler * 2 + 1);
|
u32cycles *= (CHIP_DATA (pnd)->timer_prescaler * 2 + 1);
|
||||||
u32cycles++;
|
u32cycles++;
|
||||||
// Correction depending on PN53x Rx detection handling:
|
// Correction depending on PN53x Rx detection handling:
|
||||||
// timer stops after 5 (or 2 for PN531) bits are received
|
// timer stops after 5 (or 2 for PN531) bits are received
|
||||||
|
@ -1198,7 +1193,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx,
|
||||||
// TODO Do something with these bytes...
|
// TODO Do something with these bytes...
|
||||||
(void) pbtTxPar;
|
(void) pbtTxPar;
|
||||||
(void) pbtRxPar;
|
(void) pbtRxPar;
|
||||||
unsigned int i;
|
uint16_t i;
|
||||||
uint8_t sz;
|
uint8_t sz;
|
||||||
|
|
||||||
// Sorry, no arbitrary parity bits support for now
|
// Sorry, no arbitrary parity bits support for now
|
||||||
|
@ -1253,7 +1248,7 @@ pn53x_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx,
|
||||||
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
|
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
|
||||||
// responses coming very late anyway.
|
// responses coming very late anyway.
|
||||||
// Ideally we should implement a real timer here too but looping a few times is good enough.
|
// Ideally we should implement a real timer here too but looping a few times is good enough.
|
||||||
for (i=0; i<(3 *(__timer_prescaler * 2 + 1)); i++) {
|
for (i=0; i<(3 *(CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
|
||||||
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
|
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
|
||||||
if (sz > 0)
|
if (sz > 0)
|
||||||
break;
|
break;
|
||||||
|
@ -1298,7 +1293,7 @@ bool
|
||||||
pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
|
pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
|
||||||
size_t * pszRx, uint32_t * cycles)
|
size_t * pszRx, uint32_t * cycles)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
uint16_t i;
|
||||||
uint8_t sz;
|
uint8_t sz;
|
||||||
|
|
||||||
// We can not just send bytes without parity while the PN53X expects we handled them
|
// We can not just send bytes without parity while the PN53X expects we handled them
|
||||||
|
@ -1348,7 +1343,7 @@ pn53x_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx
|
||||||
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
|
// our PN53x timer saturates after 4.8ms so this function shouldn't be used for
|
||||||
// responses coming very late anyway.
|
// responses coming very late anyway.
|
||||||
// Ideally we should implement a real timer here too but looping a few times is good enough.
|
// Ideally we should implement a real timer here too but looping a few times is good enough.
|
||||||
for (i=0; i<(3 *(__timer_prescaler * 2 + 1)); i++) {
|
for (i=0; i<(3 *(CHIP_DATA (pnd)->timer_prescaler * 2 + 1)); i++) {
|
||||||
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
|
pn53x_read_register (pnd, PN53X_REG_CIU_FIFOLevel, &sz);
|
||||||
if (sz > 0)
|
if (sz > 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -159,6 +159,8 @@ struct pn53x_data {
|
||||||
uint8_t ui8LastCommand;
|
uint8_t ui8LastCommand;
|
||||||
/** Interframe timer correction */
|
/** Interframe timer correction */
|
||||||
int16_t timer_correction;
|
int16_t timer_correction;
|
||||||
|
/** Timer prescaler */
|
||||||
|
uint16_t timer_prescaler;
|
||||||
/** WriteBack cache */
|
/** WriteBack cache */
|
||||||
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
|
||||||
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];
|
||||||
|
|
Loading…
Reference in a new issue