diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 4f7840a3d..47e86673d 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -884,9 +884,17 @@ void RAMFUNC SniffIClass(void) { // contains LOW nibble = tag data // so two bytes are needed in order to get 1byte of either reader or tag data. (ie 2 sample bytes) // since reader data is manchester encoded, we need 2bytes of data in order to get one demoded byte. (ie: 4 sample bytes) - while (!BUTTON_PRESS()) { + uint16_t checked = 0; + for (;;) { WDT_HIT(); + if ( checked == 1000 ) { + if (BUTTON_PRESS() || data_available() ) break; + checked = 0; + } else { + checked++; + } + previous_data <<= 8; previous_data |= *data; @@ -996,8 +1004,17 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; (void)b; - while (!BUTTON_PRESS()) { + uint16_t checked = 0; + for (;;) { + WDT_HIT(); + + if ( checked == 1000 ) { + if( BUTTON_PRESS() || data_available() ) return false; + checked = 0; + } else { + checked++; + } // keep tx buffer in a defined state anyway. if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) @@ -1645,8 +1662,15 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) { AT91C_BASE_SSC->SSC_THR = 0x00; - while (!BUTTON_PRESS()) { + uint16_t checked = 0; + for (;;) { + if ( checked == 1000 ) { + if ( BUTTON_PRESS() || data_available()) return 0; + checked = 0; + } else { + checked++; + } // Prevent rx holding register from overflowing if ((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)) { b = AT91C_BASE_SSC->SSC_RHR; @@ -1812,9 +1836,18 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; (void)b; - - while (!BUTTON_PRESS()) { + + uint16_t checked = 0; + + for (;;) { WDT_HIT(); + + if ( checked == 1000 ) { + if (BUTTON_PRESS() || data_available()) return false; + checked = 0; + } else { + checked++; + } // keep tx buffer in a defined state anyway. if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { @@ -2006,6 +2039,7 @@ void ReaderIClass(uint8_t arg0) { setupIclassReader(); + uint16_t checked = 0; bool userCancelled = BUTTON_PRESS() || data_available(); while (!userCancelled) { @@ -2105,7 +2139,13 @@ void ReaderIClass(uint8_t arg0) { } } LED_B_OFF(); - userCancelled = BUTTON_PRESS() || data_available(); + + if ( checked == 1000 ) { + userCancelled = BUTTON_PRESS() || data_available(); + checked = 0; + } else { + checked++; + } } if (userCancelled) { @@ -2299,11 +2339,17 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { setupIclassReader(); + uint16_t checked = 0; int read_status = 0; uint8_t startup_limit = 10; while (read_status != 2) { - if (BUTTON_PRESS() && !data_available()) goto out; + if ( checked == 1000 ) { + if (BUTTON_PRESS() || !data_available()) goto out; + checked = 0; + } else { + checked++; + } read_status = handshakeIclassTag_ext(card_data, use_credit_key); if (startup_limit-- == 0) { @@ -2318,7 +2364,12 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { for (i = 0; i < keyCount; i++) { // Allow button press / usb cmd to interrupt device - if (BUTTON_PRESS() && !data_available()) break; + if ( checked == 1000 ) { + if (BUTTON_PRESS() || !data_available()) goto out; + checked = 0; + } else { + checked++; + } WDT_HIT(); LED_B_ON();