timeout in waiting loops 4x50

This commit is contained in:
iceman1001 2020-09-05 12:50:30 +02:00
commit 7904d962aa

View file

@ -313,22 +313,36 @@ static int get_next_bit(void) {
static uint32_t get_pulse_length(void) { static uint32_t get_pulse_length(void) {
int32_t timeout = (T0 * 3 * EM4X50_T_TAG_FULL_PERIOD);
// iterates pulse length (low -> high -> low) // iterates pulse length (low -> high -> low)
uint8_t sample = 0; volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR; while (sample > gLow || (timeout--)) {
while (sample > gLow)
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR; sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
}
if (timeout == 0)
return 0;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG; AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
timeout = (T0 * 3 * EM4X50_T_TAG_FULL_PERIOD);
while (sample < gHigh) while (sample < gHigh || (timeout--)) {
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR; sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
}
while (sample > gLow) if (timeout == 0)
return 0;
timeout = (T0 * 3 * EM4X50_T_TAG_FULL_PERIOD);
while (sample > gLow || (timeout--)) {
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR; sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
}
if (timeout == 0)
return 0;
return (uint32_t)AT91C_BASE_TC1->TC_CV; return (uint32_t)AT91C_BASE_TC1->TC_CV;
} }
@ -413,13 +427,13 @@ static void em4x50_send_word(const uint8_t bytes[4]) {
em4x50_send_bit(0); em4x50_send_bit(0);
} }
static bool find_single_listen_window(int16_t timeout) { static bool find_single_listen_window(void) {
// find single listen window // find single listen window
int cnt_pulses = 0; int cnt_pulses = 0;
while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW && timeout--) { while (cnt_pulses < EM4X50_T_WAITING_FOR_SNGLLIW) {
// identification of listen window is done via evaluation of // identification of listen window is done via evaluation of
// pulse lengths // pulse lengths
@ -432,16 +446,14 @@ static bool find_single_listen_window(int16_t timeout) {
} }
} else { } else {
cnt_pulses++; cnt_pulses++;
} }
} }
return false; return false;
} }
static bool find_double_listen_window(bool bcommand, int16_t timeout) { static bool find_double_listen_window(bool bcommand) {
// find two successive listen windows that indicate the beginning of // find two successive listen windows that indicate the beginning of
// data transmission // data transmission
@ -451,7 +463,7 @@ static bool find_double_listen_window(bool bcommand, int16_t timeout) {
int cnt_pulses = 0; int cnt_pulses = 0;
while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW && timeout--) { while (cnt_pulses < EM4X50_T_WAITING_FOR_DBLLIW) {
// identification of listen window is done via evaluation of // identification of listen window is done via evaluation of
// pulse lengths // pulse lengths
@ -508,7 +520,7 @@ static bool find_em4x50_tag(void) {
// function is used to check wether a tag on the proxmark is an // function is used to check wether a tag on the proxmark is an
// EM4x50 tag or not -> speed up "lf search" process // EM4x50 tag or not -> speed up "lf search" process
return (find_single_listen_window(EM4X50_COMMAND_TIMEOUT)); return (find_single_listen_window());
} }
@ -520,7 +532,7 @@ static bool request_receive_mode(void) {
bool bcommand = true; bool bcommand = true;
return find_double_listen_window(bcommand, EM4X50_COMMAND_TIMEOUT); return find_double_listen_window(bcommand);
} }
static bool check_ack(bool bliw) { static bool check_ack(bool bliw) {
@ -726,7 +738,7 @@ static bool standard_read(int *now) {
uint8_t bits[EM4X50_TAG_WORD] = {0}; uint8_t bits[EM4X50_TAG_WORD] = {0};
// start with the identification of two succsessive listening windows // start with the identification of two succsessive listening windows
if (find_double_listen_window(false, EM4X50_COMMAND_TIMEOUT)) { if (find_double_listen_window(false)) {
// read and save words until following double listen window is detected // read and save words until following double listen window is detected
while (get_word_from_bitstream(bits) == EM4X50_TAG_WORD) while (get_word_from_bitstream(bits) == EM4X50_TAG_WORD)