From 4001b11d9c54c107af8803c9239102ed53b896dc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 25 Aug 2026 19:30:43 +0200 Subject: [PATCH] Cleaning some lf_finalize <> StartTicks <> StopTicks --- armsrc/em4x50.c | 36 +++++++++++++++++++++++++----------- armsrc/em4x70.c | 20 +++++++++++++------- armsrc/lfzx.c | 13 ++++--------- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 0aa9fb78d..11727856a 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -716,7 +716,8 @@ void em4x50_login(const uint32_t *password, bool ledcontrol) { } if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_LOGIN, status, NULL, 0); } @@ -736,7 +737,8 @@ void em4x50_brute(const em4x50_data_t *etd, bool ledcontrol) { } if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_BRUTE, bsuccess ? PM3_SUCCESS : PM3_EFAILED, (uint8_t *)(&pwd), sizeof(pwd)); } @@ -798,7 +800,8 @@ void em4x50_chk(const char *filename, bool ledcontrol) { #endif if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_CHK, status, (uint8_t *)&pwd, sizeof(pwd)); } @@ -909,7 +912,8 @@ void em4x50_read(const em4x50_data_t *etd, bool ledcontrol) { if (ledcontrol) LEDsoff(); Gpio_SSC_DOUT_Low(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_READ, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES); } @@ -939,7 +943,8 @@ void em4x50_info(const em4x50_data_t *etd, bool ledcontrol) { } if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_INFO, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES); } @@ -962,7 +967,8 @@ void em4x50_reader(bool ledcontrol) { if (ledcontrol) LEDsoff(); Gpio_SSC_DOUT_Low(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_READER, now, (uint8_t *)words, 4 * now); } @@ -1085,7 +1091,9 @@ void em4x50_write(const em4x50_data_t *etd, bool ledcontrol) { // write word to given address status = write(etd->word, etd->addresses); if (status == PM3_ETEAROFF) { - lf_finalize(ledcontrol); + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); return; } @@ -1116,7 +1124,8 @@ void em4x50_write(const em4x50_data_t *etd, bool ledcontrol) { } if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_WRITE, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES); } @@ -1139,14 +1148,17 @@ void em4x50_writepwd(const em4x50_data_t *etd, bool ledcontrol) { status = write_password(etd->password1, etd->password2); if (status == PM3_ETEAROFF) { - lf_finalize(ledcontrol); + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); return; } } } if (ledcontrol) LEDsoff(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_WRITEPWD, status, NULL, 0); } @@ -1869,6 +1881,8 @@ void em4x50_sim(const uint32_t *password, bool ledcontrol) { } BigBuf_free(); - lf_finalize(ledcontrol); + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + StopTicks(); reply_ng(CMD_LF_EM4X50_SIM, command, NULL, 0); } diff --git a/armsrc/em4x70.c b/armsrc/em4x70.c index bb20a9950..eb72d9b28 100644 --- a/armsrc/em4x70.c +++ b/armsrc/em4x70.c @@ -1472,8 +1472,8 @@ void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) { success_with_UM2 = em4x70_read_um2(); } + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); int status = success ? PM3_SUCCESS : PM3_ESOFT; size_t data_size = success && success_with_UM2 ? 32 : @@ -1514,8 +1514,9 @@ void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) { } } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_WRITE, status, g_tag.data, sizeof(g_tag.data)); } @@ -1547,8 +1548,9 @@ void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) { } } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_UNLOCK, status, g_tag.data, sizeof(g_tag.data)); } @@ -1577,8 +1579,9 @@ void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) { status = authenticate(etd->rnd, etd->frnd, response); } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_AUTH, status, response, sizeof(response)); } @@ -1605,8 +1608,9 @@ void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) { status = bruteforce(etd->address, etd->rnd, etd->frnd, etd->start_key, response); } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_BRUTE, status, response, sizeof(response)); } @@ -1654,8 +1658,9 @@ void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) { } } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_SETPIN, status, g_tag.data, sizeof(g_tag.data)); } @@ -1701,7 +1706,8 @@ void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol) { } } + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); StopTicks(); - lf_finalize(ledcontrol); reply_ng(CMD_LF_EM4X70_SETKEY, status, g_tag.data, sizeof(g_tag.data)); } diff --git a/armsrc/lfzx.c b/armsrc/lfzx.c index 0f69d4a82..9f3f0a9c2 100644 --- a/armsrc/lfzx.c +++ b/armsrc/lfzx.c @@ -99,7 +99,7 @@ static void zx8211_setup_read(void) { FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_ADC_READER_FIELD); // 50ms for the resonant antenna to settle. - WaitMS(50); + SpinDelay(50); // Now set up the SSC to get the ADC samples that are now streaming at us. FpgaSetupSsc(FPGA_MAJOR_MODE_LF_READER); @@ -109,9 +109,6 @@ static void zx8211_setup_read(void) { // Connect the A/D to the peak-detected low-frequency path. SetAdcMuxFor(ADC_MUXSEL_LOPKD); - // Start the timer - StartTicks(); - // Watchdog hit WDT_HIT(); } @@ -179,9 +176,7 @@ int zx8211_read(zx8211_data_t *zxd, bool ledcontrol) { //uint32_t cs = CRC8Hitag1(uint8_t *buff, size_t size); if (ledcontrol) LEDsoff(); - - StopTicks(); - lf_finalize(ledcontrol); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); reply_ng(CMD_LF_ZX_READ, PM3_SUCCESS, NULL, 0); return PM3_SUCCESS; @@ -190,8 +185,8 @@ int zx8211_read(zx8211_data_t *zxd, bool ledcontrol) { int zx8211_write(zx8211_data_t *zxd, bool ledcontrol) { zx8211_setup_read(); - StopTicks(); - lf_finalize(ledcontrol); + if (ledcontrol) LEDsoff(); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); //reply_ng(CMD_LF_ZX_WRITE, status, tag.data, sizeof(tag.data)); return PM3_SUCCESS; }