replace usb_poll_validate_length() by data_available() that supports USART too

This commit is contained in:
Philippe Teuwen 2019-06-03 00:01:08 +02:00
parent d7614684f8
commit 3b12ba2e93
21 changed files with 50 additions and 41 deletions

View file

@ -39,7 +39,7 @@ void RunMod() {
for (;;) {
WDT_HIT();
// exit from Standalone Mode, send a usbcommand.
if (usb_poll_validate_length()) return;
if (data_available()) return;
SpinDelay(300);
@ -57,7 +57,7 @@ void RunMod() {
for (;;) {
// exit from Standalone Mode, send a usbcommand.
if (usb_poll_validate_length()) return;
if (data_available()) return;
if (BUTTON_PRESS()) {
if (cardRead[selected]) {
@ -204,7 +204,7 @@ void RunMod() {
DbpString("Playing");
for (; ;) {
// exit from Standalone Mode, send a usbcommand.
if (usb_poll_validate_length()) return;
if (data_available()) return;
int button_action = BUTTON_HELD(1000);
if (button_action == 0) { // No button action, proceed with sim

View file

@ -48,7 +48,7 @@ void RunMod() {
WDT_HIT();
// exit from SamyRun, send a usbcommand.
if (usb_poll_validate_length()) break;
if (data_available()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);

View file

@ -24,7 +24,7 @@ void RunMod() {
WDT_HIT();
// exit from IceRun, send a usbcommand.
if (usb_poll_validate_length()) break;
if (data_available()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);

View file

@ -33,7 +33,7 @@ void RunMod() {
WDT_HIT();
// exit from SamyRun, send a usbcommand.
if (usb_poll_validate_length()) break;
if (data_available()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);

View file

@ -32,7 +32,7 @@ void RunMod() {
WDT_HIT();
// exit from SamyRun, send a usbcommand.
if (usb_poll_validate_length()) break;
if (data_available()) break;
// Was our button held down or pressed?
int button_pressed = BUTTON_HELD(1000);

View file

@ -34,7 +34,7 @@ void RunMod(void) {
WDT_HIT();
// exit from standalone mode, just send a usbcommand
if (usb_poll_validate_length()) break;
if (data_available()) break;
// do your standalone stuff..
}

View file

@ -731,7 +731,7 @@ void felica_dump_lite_s() {
uint16_t cnt = 0, cntfails = 0;
uint8_t *dest = BigBuf_get_addr();
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();

View file

@ -46,7 +46,7 @@ void HfSniff(int samplesToSkip, int triggersToSkip) {
SpinDelay(100);
uint16_t r = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {

View file

@ -751,7 +751,7 @@ void SniffHitag(void) {
bSkip = true;
tag_sof = 4;
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
// Watchdog hit
WDT_HIT();
@ -978,7 +978,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
// synchronized startup procedure
while (AT91C_BASE_TC0->TC_CV > 0) {}; // wait until TC0 returned to zero
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
// Watchdog hit
WDT_HIT();
@ -1203,7 +1203,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
}
uint8_t attempt_count = 0;
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!bStop && !BUTTON_PRESS() && !data_available()) {
WDT_HIT();
@ -1464,7 +1464,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
return;
}
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!bStop && !BUTTON_PRESS() && !data_available()) {
WDT_HIT();

View file

@ -1022,7 +1022,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
// synchronized startup procedure
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
@ -1228,7 +1228,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
// Reset the received frame, frame count and timing info
t_wait = 200;
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!bStop && !BUTTON_PRESS() && !data_available()) {
WDT_HIT();
@ -1558,7 +1558,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
reset_sof = 1;
t_wait = 200;
while (!bStop && !BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!bStop && !BUTTON_PRESS() && !data_available()) {
WDT_HIT();

View file

@ -1993,7 +1993,7 @@ void ReaderIClass(uint8_t arg0) {
setupIclassReader();
bool userCancelled = BUTTON_PRESS() || usb_poll_validate_length();
bool userCancelled = BUTTON_PRESS() || data_available();
while (!userCancelled) {
WDT_HIT();
@ -2092,7 +2092,7 @@ void ReaderIClass(uint8_t arg0) {
}
}
LED_B_OFF();
userCancelled = BUTTON_PRESS() || usb_poll_validate_length();
userCancelled = BUTTON_PRESS() || data_available();
}
if (userCancelled) {
@ -2290,7 +2290,7 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
uint8_t startup_limit = 10;
while (read_status != 2) {
if (BUTTON_PRESS() && !usb_poll_validate_length()) goto out;
if (BUTTON_PRESS() && !data_available()) goto out;
read_status = handshakeIclassTag_ext(card_data, use_credit_key);
if (startup_limit-- == 0) {
@ -2305,7 +2305,7 @@ 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() && !usb_poll_validate_length()) break;
if (BUTTON_PRESS() && !data_available()) break;
WDT_HIT();
LED_B_ON();

View file

@ -762,7 +762,7 @@ static bool GetIso14443aCommandFromReader(uint8_t *received, uint8_t *par, int *
for (;;) {
if ( check == 1000 ) {
if ( BUTTON_PRESS() || usb_poll_validate_length() )
if ( BUTTON_PRESS() || data_available() )
return false;
check = 0;
}
@ -1722,7 +1722,7 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *par) {
WDT_HIT();
if ( check == 1000 ) {
if (BUTTON_PRESS() || usb_poll_validate_length())
if (BUTTON_PRESS() || data_available())
return 1;
check = 0;
}
@ -2923,7 +2923,7 @@ void DetectNACKbug() {
WDT_HIT();
// Test if the action was cancelled
if (BUTTON_PRESS() || usb_poll_validate_length()) {
if (BUTTON_PRESS() || data_available()) {
status = PM3_EOPABORTED;
break;
}

View file

@ -619,7 +619,7 @@ void SimulateIso14443bTag(uint32_t pupi) {
memcpy(encodedOK, ToSend, ToSendMax);
// Simulation loop
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
// find reader field

View file

@ -891,7 +891,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid) {
uint8_t cmd[CMD_INV_RESP] = {0};
BuildInventoryResponse(cmd, uid);
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
// Listen to reader

View file

@ -459,7 +459,7 @@ void LegicRfSimulate(uint8_t cardtype) {
LED_A_ON();
DbpString("Starting Legic emulator, press button to end");
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
// wait for carrier, restart after timeout

View file

@ -607,7 +607,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycl
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
WDT_HIT();
if ( check == 1000) {
if (usb_poll_validate_length() || BUTTON_PRESS())
if (data_available() || BUTTON_PRESS())
goto OUT;
check = 0;
}
@ -627,7 +627,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycl
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
WDT_HIT();
if (check == 1000) {
if (usb_poll_validate_length() || BUTTON_PRESS())
if (data_available() || BUTTON_PRESS())
goto OUT;
check = 0;
}
@ -1011,7 +1011,7 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
//clear read buffer
BigBuf_Clear_keep_EM();
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (ledcontrol) LED_A_ON();
@ -1105,7 +1105,7 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
LFSetupFPGAForADC(95, true);
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (ledcontrol) LED_A_ON();
@ -1197,7 +1197,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
LFSetupFPGAForADC(95, true);
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (ledcontrol) LED_A_ON();
@ -1263,7 +1263,7 @@ void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
// Configure to go in 125Khz listen mode
LFSetupFPGAForADC(95, true);
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (ledcontrol) LED_A_ON();
@ -1603,7 +1603,7 @@ void T55xx_ChkPwds() {
uint32_t pwd = 0, curr = 0, prev = 0;
for (uint16_t i = 0; i < pwdCount; ++i) {
if (BUTTON_PRESS() && !usb_poll_validate_length()) {
if (BUTTON_PRESS() && !data_available()) {
goto OUT;
}

View file

@ -137,7 +137,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
uint32_t sample_total_saved = 0;
uint32_t cancel_counter = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length()) {
while (!BUTTON_PRESS() && !data_available()) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
@ -283,7 +283,7 @@ void doT55x7Acquisition(size_t sample_size) {
bool highFound = false;
bool lowFound = false;
while (!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt < 1000 && (i < bufsize)) {
while (!BUTTON_PRESS() && !data_available() && skipCnt < 1000 && (i < bufsize)) {
WDT_HIT();
@ -348,7 +348,7 @@ void doCotagAcquisition(size_t sample_size) {
uint16_t i = 0;
uint16_t noise_counter = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (i < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
while (!BUTTON_PRESS() && !data_available() && (i < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
@ -398,7 +398,7 @@ uint32_t doCotagAcquisitionManchester() {
uint8_t curr = 0, prev = 0;
uint16_t noise_counter = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
while (!BUTTON_PRESS() && !data_available() && (sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {

View file

@ -1328,7 +1328,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
//if ( i % 100 == 0) Dbprintf("ChkKeys_fast: sector %d | checking %d | %d found | s_point %d", s, i, foundkeys, s_point);
// Allow button press / usb cmd to interrupt device
if (BUTTON_PRESS() && !usb_poll_validate_length()) {
if (BUTTON_PRESS() && !data_available()) {
goto OUT;
}
@ -1420,7 +1420,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
for (uint16_t i = 0; i < keyCount; i++) {
// Allow button press / usb cmd to interrupt device
if (BUTTON_PRESS() && !usb_poll_validate_length()) break;
if (BUTTON_PRESS() && !data_available()) break;
// found all keys?
if (foundkeys == allkeys)

View file

@ -502,7 +502,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) {
bool finished = false;
bool button_pushed = BUTTON_PRESS();
while (!button_pushed && !finished && !usb_poll_validate_length()) {
while (!button_pushed && !finished && !data_available()) {
WDT_HIT();
// find reader field

View file

@ -300,3 +300,11 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
strncat(dst, v->buildtime, len - strlen(dst) - 1);
strncat(dst, "\n", len - strlen(dst) - 1);
}
bool data_available(void) {
#ifdef WITH_FPC_USART_HOST
return usb_poll_validate_length() || (usart_rxdata_available() > 0);
#else
return usb_poll_validate_length();
#endif
}

View file

@ -92,5 +92,6 @@ void SpinUp(uint32_t speed);
int BUTTON_CLICKED(int ms);
int BUTTON_HELD(int ms);
void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information);
bool data_available(void);
#endif