mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
style, receive_ng_internal, when receiving NG frames we have an extra buffer. Somehow it seems to the be cause of issues with long emrtd dumps
This commit is contained in:
parent
2d6cd1a875
commit
a5594d5f3c
3 changed files with 177 additions and 84 deletions
|
@ -89,10 +89,11 @@ static void usart_fill_rxfifo(void) {
|
|||
|
||||
if (pUS1->US_RNCR == 0) { // One buffer got filled, backup buffer being used
|
||||
|
||||
if (us_rxfifo_low > us_rxfifo_high)
|
||||
if (us_rxfifo_low > us_rxfifo_high) {
|
||||
rxfifo_free = us_rxfifo_low - us_rxfifo_high;
|
||||
else
|
||||
} else {
|
||||
rxfifo_free = sizeof(us_rxfifo) - us_rxfifo_high + us_rxfifo_low;
|
||||
}
|
||||
|
||||
uint16_t available = USART_BUFFLEN - usart_cur_inbuf_off;
|
||||
|
||||
|
@ -100,8 +101,9 @@ static void usart_fill_rxfifo(void) {
|
|||
|
||||
for (uint16_t i = 0; i < available; i++) {
|
||||
us_rxfifo[us_rxfifo_high++] = usart_cur_inbuf[usart_cur_inbuf_off + i];
|
||||
if (us_rxfifo_high == sizeof(us_rxfifo))
|
||||
if (us_rxfifo_high == sizeof(us_rxfifo)) {
|
||||
us_rxfifo_high = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Give next buffer
|
||||
|
@ -109,10 +111,11 @@ static void usart_fill_rxfifo(void) {
|
|||
pUS1->US_RNCR = USART_BUFFLEN;
|
||||
|
||||
// Swap current buff
|
||||
if (usart_cur_inbuf == us_in_a)
|
||||
if (usart_cur_inbuf == us_in_a) {
|
||||
usart_cur_inbuf = us_in_b;
|
||||
else
|
||||
} else {
|
||||
usart_cur_inbuf = us_in_a;
|
||||
}
|
||||
|
||||
usart_cur_inbuf_off = 0;
|
||||
} else {
|
||||
|
@ -133,15 +136,17 @@ static void usart_fill_rxfifo(void) {
|
|||
|
||||
if (pUS1->US_RCR < USART_BUFFLEN - usart_cur_inbuf_off) { // Current buffer partially filled
|
||||
|
||||
if (us_rxfifo_low > us_rxfifo_high)
|
||||
if (us_rxfifo_low > us_rxfifo_high) {
|
||||
rxfifo_free = (us_rxfifo_low - us_rxfifo_high);
|
||||
else
|
||||
} else {
|
||||
rxfifo_free = (sizeof(us_rxfifo) - us_rxfifo_high + us_rxfifo_low);
|
||||
}
|
||||
|
||||
uint16_t available = (USART_BUFFLEN - pUS1->US_RCR - usart_cur_inbuf_off);
|
||||
|
||||
if (available > rxfifo_free)
|
||||
if (available > rxfifo_free) {
|
||||
available = rxfifo_free;
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < available; i++) {
|
||||
us_rxfifo[us_rxfifo_high++] = usart_cur_inbuf[usart_cur_inbuf_off + i];
|
||||
|
@ -155,14 +160,19 @@ static void usart_fill_rxfifo(void) {
|
|||
|
||||
uint16_t usart_rxdata_available(void) {
|
||||
usart_fill_rxfifo();
|
||||
if (us_rxfifo_low <= us_rxfifo_high)
|
||||
if (us_rxfifo_low <= us_rxfifo_high) {
|
||||
return (us_rxfifo_high - us_rxfifo_low);
|
||||
else
|
||||
} else {
|
||||
return (sizeof(us_rxfifo) - us_rxfifo_low + us_rxfifo_high);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t usart_read_ng(uint8_t *data, size_t len) {
|
||||
if (len == 0) return 0;
|
||||
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t bytes_rcv = 0;
|
||||
uint32_t try = 0;
|
||||
// uint32_t highest_observed_try = 0;
|
||||
|
@ -187,17 +197,20 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
|
|||
// highest_observed_try = MAX(highest_observed_try, try);
|
||||
try = 0;
|
||||
}
|
||||
|
||||
len -= packetSize;
|
||||
|
||||
while (packetSize--) {
|
||||
if (us_rxfifo_low == sizeof(us_rxfifo)) {
|
||||
us_rxfifo_low = 0;
|
||||
}
|
||||
data[bytes_rcv++] = us_rxfifo[us_rxfifo_low++];
|
||||
}
|
||||
|
||||
if (try++ == maxtry) {
|
||||
// Dbprintf_usb("Dbg USART TIMEOUT");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// highest_observed_try = MAX(highest_observed_try, try);
|
||||
// Dbprintf_usb("Dbg USART max observed try %i", highest_observed_try);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue