- added missing timeout checks

- relocated timer resets in standalone mode
This commit is contained in:
tharexde 2021-02-09 23:22:46 +01:00
commit b20f532282
2 changed files with 31 additions and 17 deletions

View file

@ -133,6 +133,7 @@ void RunMod(void) {
rdv40_spiffs_lazy_mount(); rdv40_spiffs_lazy_mount();
StandAloneMode(); StandAloneMode();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
Dbprintf(_YELLOW_("Standalone mode THAREXDE started")); Dbprintf(_YELLOW_("Standalone mode THAREXDE started"));
for (;;) { for (;;) {
@ -204,10 +205,11 @@ void RunMod(void) {
for (int i = 0; i < EM4X50_NO_WORDS; i++) { for (int i = 0; i < EM4X50_NO_WORDS; i++) {
sprintf((char *)entry + strlen((char *)entry), "%08"PRIx32"\n", tag[i]); sprintf((char *)entry + strlen((char *)entry), "%08"PRIx32"\n", tag[i]);
} }
log_exists = exists_in_spiffs(LF_EM4X50_LOGFILE_SIM);
Dbprintf("log_exists = %i", log_exists);
//append(LF_EM4X50_LOGFILE_SIM, entry, strlen((char *)entry));
if (exists_in_spiffs(LF_EM4X50_LOGFILE_SIM)) {
rdv40_spiffs_remove(LF_EM4X50_LOGFILE_SIM, RDV40_SPIFFS_SAFETY_SAFE);
}
rdv40_spiffs_write(LF_EM4X50_LOGFILE_SIM, entry, strlen((char *)entry), RDV40_SPIFFS_SAFETY_SAFE);
} }
// stop if key (pm3 button or enter key) has been pressed // stop if key (pm3 button or enter key) has been pressed
@ -253,6 +255,7 @@ void RunMod(void) {
sprintf((char *)entry + strlen((char *)entry), "\n"); sprintf((char *)entry + strlen((char *)entry), "\n");
append(LF_EM4X50_LOGFILE_COLLECT, entry, strlen((char *)entry)); append(LF_EM4X50_LOGFILE_COLLECT, entry, strlen((char *)entry));
} }
}
// reset timer // reset timer
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // re-enable timer and wait for TC0 AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // re-enable timer and wait for TC0
@ -260,7 +263,6 @@ void RunMod(void) {
AT91C_BASE_TC0->TC_RA = 1; // clear carry bit on next clock cycle AT91C_BASE_TC0->TC_RA = 1; // clear carry bit on next clock cycle
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // reset and re-enable timer AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // reset and re-enable timer
} }
}
if (state == STATE_READ) { if (state == STATE_READ) {
DownloadLogInstructions(LF_EM4X50_LOGFILE_COLLECT); DownloadLogInstructions(LF_EM4X50_LOGFILE_COLLECT);

View file

@ -1222,11 +1222,19 @@ static int em4x50_sim_read_bit(void) {
while (cycles < EM4X50_T_TAG_FULL_PERIOD) { while (cycles < EM4X50_T_TAG_FULL_PERIOD) {
// wait until reader field disappears // wait until reader field disappears
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); while ((timeout--) && !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
if (timeout <= 0) {
return PM3_ETIMEOUT;
}
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
// now check until reader switches on carrier field // now check until reader switches on carrier field
tval = GetTicks(); tval = GetTicks();
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) { while ((timeout--) && (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
if (timeout <= 0) {
return PM3_ETIMEOUT;
}
// check if current cycle takes longer than "usual"" // check if current cycle takes longer than "usual""
if (GetTicks() - tval > EM4X50_T_ZERO_DETECTION * CYCLES2TICKS) { if (GetTicks() - tval > EM4X50_T_ZERO_DETECTION * CYCLES2TICKS) {
@ -1237,7 +1245,7 @@ static int em4x50_sim_read_bit(void) {
if (timeout <= 0) { if (timeout <= 0) {
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
// timeout = EM4X50_T_SIMULATION_TIMEOUT_READ; //timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
// now we have a reference "position", from here it will take // now we have a reference "position", from here it will take
// slightly less than 32 cycles until the end of the bit period // slightly less than 32 cycles until the end of the bit period
@ -1248,6 +1256,7 @@ static int em4x50_sim_read_bit(void) {
return 0; return 0;
} }
} }
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
// no gap detected, i.e. reader field is still up; // no gap detected, i.e. reader field is still up;
// continue with counting cycles // continue with counting cycles
@ -1431,11 +1440,14 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
// last word read protected // last word read protected
int lwrp = (reflect32(tag[EM4X50_PROTECTION]) >> 8) & 0xFF; int lwrp = (reflect32(tag[EM4X50_PROTECTION]) >> 8) & 0xFF;
int command = PM3_SUCCESS;
while ((BUTTON_PRESS() == false) && (data_available() == false)) { while ((BUTTON_PRESS() == false) && (data_available() == false)) {
WDT_HIT(); WDT_HIT();
int command = em4x50_sim_send_listen_window(tag); command = em4x50_sim_send_listen_window(tag);
if (command != PM3_SUCCESS) { if (command != PM3_SUCCESS) {
return command; return command;
} }