Move prescaler to CHIP_DATA struct & remove some compilation warnings

This commit is contained in:
Philippe Teuwen 2011-05-11 23:22:52 +00:00
parent ab54a37678
commit b98afced69
2 changed files with 14 additions and 17 deletions

View file

@ -882,8 +882,6 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
// Some work to do before getting the UID...
byte_t abtReqt[]="\x10";
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
if (!pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData) || szTargetsData != 2) {
return false;
@ -897,8 +895,6 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
return false;
byte_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4)
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) {
return false;
}
@ -1113,20 +1109,19 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
return true;
}
// For _timer() functions, the prescaler will dictate what will
// be the precision and the largest delay to measure before saturation
void __pn53x_init_timer(nfc_device_t * pnd)
{
// 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 = 1 => precision: ~221ns timer saturates at ~15ms
// prescaler = 2 => precision: ~369ns timer saturates at ~25ms
// prescaler = 10 => precision: ~1.5us timer saturates at ~100ms
static uint16_t __timer_prescaler = 0;
void __pn53x_init_timer(nfc_device_t * pnd)
{
CHIP_DATA (pnd)->timer_prescaler = 0;
uint16_t reloadval = 0xFFFF;
// 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_TPrescaler, 0xFF, (__timer_prescaler & SYMBOL_TPRESCALERLO));
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, (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_lo, 0xFF, reloadval & 0xFF);
}
@ -1165,7 +1160,7 @@ uint32_t __pn53x_get_timer(nfc_device_t * pnd, const uint8_t last_cmd_byte)
} else {
u16cycles = 0xFFFF - counter;
u32cycles = u16cycles;
u32cycles *= (__timer_prescaler * 2 + 1);
u32cycles *= (CHIP_DATA (pnd)->timer_prescaler * 2 + 1);
u32cycles++;
// Correction depending on PN53x Rx detection handling:
// 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...
(void) pbtTxPar;
(void) pbtRxPar;
unsigned int i;
uint16_t i;
uint8_t sz;
// 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
// responses coming very late anyway.
// 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);
if (sz > 0)
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,
size_t * pszRx, uint32_t * cycles)
{
unsigned int i;
uint16_t i;
uint8_t sz;
// 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
// responses coming very late anyway.
// 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);
if (sz > 0)
break;

View file

@ -159,6 +159,8 @@ struct pn53x_data {
uint8_t ui8LastCommand;
/** Interframe timer correction */
int16_t timer_correction;
/** Timer prescaler */
uint16_t timer_prescaler;
/** WriteBack cache */
uint8_t wb_data[PN53X_CACHE_REGISTER_SIZE];
uint8_t wb_mask[PN53X_CACHE_REGISTER_SIZE];