Use GetTickCountDelta everywhere

This commit is contained in:
Philippe Teuwen 2019-05-23 00:39:50 +02:00
parent 86ee0658cf
commit 522297896c
3 changed files with 28 additions and 23 deletions

View file

@ -105,8 +105,8 @@ void ReadLastTagFromFlash() {
}
Flash_CheckBusy(BUSY_TIMEOUT);
uint32_t end_time;
uint32_t start_time = end_time = GetTickCount();
uint32_t start_time = GetTickCount();
uint32_t delta_time = 0;
for (size_t i = 0; i < len; i += size) {
len = MIN((len - i), size);
@ -121,7 +121,7 @@ void ReadLastTagFromFlash() {
return;
}
}
end_time = GetTickCount();
delta_time = GetTickCountDelta(start_time);
DbprintfEx(FLAG_NEWLINE, "[OK] Last tag recovered from FLASHMEM set to emulator");
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE, "%s[IN]%s %s%dms%s for TAG_FLASH_READ", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);
@ -155,8 +155,8 @@ void WriteTagToFlash(uint8_t index, size_t size) {
Flash_WriteEnable();
Flash_Erase4k(0, 0);
uint32_t end_time;
uint32_t start_time = end_time = GetTickCount();
uint32_t start_time = GetTickCount();
uint32_t delta_time = 0;
while (bytes_remaining > 0) {
Flash_CheckBusy(BUSY_TIMEOUT);
@ -184,7 +184,7 @@ void WriteTagToFlash(uint8_t index, size_t size) {
LED_C_INV();
LED_D_INV();
}
end_time = GetTickCount();
delta_time = GetTickCountDelta(start_time);
DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH ! [0-to offset %u]", bytes_sent);
cjSetCursLeft();
@ -393,8 +393,8 @@ failtag:
cjSetCursRight();
DbprintfEx(FLAG_NEWLINE, "--------+--------------------+-------");
uint32_t end_time;
uint32_t start_time = end_time = GetTickCount();
uint32_t start_time = GetTickCount();
uint32_t delta_time = 0;
//---------------------------------------------------------------------------
// WE SHOULD FIND A WAY TO GET UID TO AVOID THIS "TESTRUN"
@ -736,7 +736,7 @@ failtag:
}
}
end_time = GetTickCount();
delta_time = GetTickCountDelta(start_time);
cjSetCursLeft();
DbprintfEx(FLAG_NEWLINE, "%s>>%s Time for VIGIK break :%s%dms%s", _GREEN_, _WHITE_, _YELLOW_, end_time - start_time, _WHITE_);

View file

@ -382,23 +382,22 @@ void printConnSpeed(void) {
#define CONN_SPEED_TEST_MIN_TIME 500 // in milliseconds
uint8_t *test_data = BigBuf_get_addr();
uint32_t end_time;
uint32_t start_time = end_time = GetTickCount();
uint32_t start_time = GetTickCount();
uint32_t delta_time = 0;
uint32_t bytes_transferred = 0;
LED_B_ON();
while (end_time < start_time + CONN_SPEED_TEST_MIN_TIME) {
while (delta_time < CONN_SPEED_TEST_MIN_TIME) {
reply_ng(CMD_DOWNLOADED_BIGBUF, PM3_SUCCESS, test_data, PM3_CMD_DATA_SIZE);
end_time = GetTickCount();
bytes_transferred += PM3_CMD_DATA_SIZE;
delta_time = GetTickCountDelta(start_time);
}
LED_B_OFF();
Dbprintf(" Time elapsed............%dms", end_time - start_time);
Dbprintf(" Time elapsed............%dms", delta_time);
Dbprintf(" Bytes transferred.......%d", bytes_transferred);
Dbprintf(" Transfer Speed PM3 -> Client = " _YELLOW_("%d") " bytes/s", 1000 * bytes_transferred / (end_time - start_time));
Dbprintf(" Transfer Speed PM3 -> Client = " _YELLOW_("%d") " bytes/s", 1000 * bytes_transferred / delta_time);
}
/**

View file

@ -1623,7 +1623,7 @@ void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *p
int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *par) {
*len = 0;
uint32_t timer = 0, vtime;
uint32_t timer = 0;
int analogCnt = 0;
int analogAVG = 0;
@ -1662,11 +1662,17 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *par) {
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
if (analogCnt >= 32) {
if ((MAX_ADC_HF_VOLTAGE_RDV40 * (analogAVG / analogCnt) >> 10) < MF_MINFIELDV) {
vtime = GetTickCount();
if (!timer) timer = vtime;
// 50ms no field --> card to idle state
if (vtime - timer > 50) return 2;
} else if (timer) timer = 0;
if (timer == 0) {
timer = GetTickCount();
} else {
// 50ms no field --> card to idle state
if (GetTickCountDelta(timer) > 50) {
return 2;
}
}
} else {
timer = 0;
}
analogCnt = 0;
analogAVG = 0;
}
@ -2041,7 +2047,7 @@ static int GetATQA(uint8_t *resp, uint8_t *resp_par) {
ReaderTransmitBitsPar(wupa, 7, NULL, NULL);
// Receive the ATQA
len = ReaderReceive(resp, resp_par);
} while (len == 0 && GetTickCount() <= start_time + WUPA_RETRY_TIMEOUT);
} while (len == 0 && GetTickCountDelta(start_time) <= WUPA_RETRY_TIMEOUT);
iso14a_set_timeout(save_iso14a_timeout);
return len;