This commit is contained in:
iceman1001 2023-12-14 00:37:06 +01:00
parent 0c3d487c15
commit 79213b169a

View file

@ -669,15 +669,17 @@ uint32_t usb_read(uint8_t *data, size_t len) {
uint32_t time_out = 0; uint32_t time_out = 0;
while (len) { while (len) {
if (!usb_check()) break; if (!usb_check())
break;
if (pUdp->UDP_CSR[AT91C_EP_OUT] & bank) { if (pUdp->UDP_CSR[AT91C_EP_OUT] & bank) {
packetSize = ((pUdp->UDP_CSR[AT91C_EP_OUT] & AT91C_UDP_RXBYTECNT) >> 16); packetSize = ((pUdp->UDP_CSR[AT91C_EP_OUT] & AT91C_UDP_RXBYTECNT) >> 16);
packetSize = MIN(packetSize, len); packetSize = MIN(packetSize, len);
len -= packetSize; len -= packetSize;
while (packetSize--) while (packetSize--) {
data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT]; data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
}
// flip bank // flip bank
UDP_CLEAR_EP_FLAGS(AT91C_EP_OUT, bank) UDP_CLEAR_EP_FLAGS(AT91C_EP_OUT, bank)
@ -687,7 +689,9 @@ uint32_t usb_read(uint8_t *data, size_t len) {
else else
bank = AT91C_UDP_RX_DATA_BK0; bank = AT91C_UDP_RX_DATA_BK0;
} }
if (time_out++ == 0x1fff) break;
if (time_out++ == 0x1fff)
break;
} }
btReceiveBank = bank; btReceiveBank = bank;
@ -700,7 +704,8 @@ static size_t usb_read_ng_buflen = 0;
uint32_t usb_read_ng(uint8_t *data, size_t len) { uint32_t usb_read_ng(uint8_t *data, size_t len) {
if (len == 0) return 0; if (len == 0)
return 0;
uint8_t bank = btReceiveBank; uint8_t bank = btReceiveBank;
uint32_t packetSize, nbBytesRcv = 0; uint32_t packetSize, nbBytesRcv = 0;
@ -708,24 +713,30 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
// take first from local buffer // take first from local buffer
if (len <= usb_read_ng_buflen) { if (len <= usb_read_ng_buflen) {
for (uint32_t i = 0; i < len; i++)
for (uint32_t i = 0; i < len; i++) {
data[nbBytesRcv++] = usb_read_ng_buffer[usb_read_ng_bufoff + i]; data[nbBytesRcv++] = usb_read_ng_buffer[usb_read_ng_bufoff + i];
}
usb_read_ng_buflen -= len; usb_read_ng_buflen -= len;
if (usb_read_ng_buflen == 0) if (usb_read_ng_buflen == 0)
usb_read_ng_bufoff = 0; usb_read_ng_bufoff = 0;
else else
usb_read_ng_bufoff += len; usb_read_ng_bufoff += len;
return nbBytesRcv; return nbBytesRcv;
} else { } else {
for (uint32_t i = 0; i < usb_read_ng_buflen; i++) for (uint32_t i = 0; i < usb_read_ng_buflen; i++) {
data[nbBytesRcv++] = usb_read_ng_buffer[usb_read_ng_bufoff + i]; data[nbBytesRcv++] = usb_read_ng_buffer[usb_read_ng_bufoff + i];
}
len -= usb_read_ng_buflen; len -= usb_read_ng_buflen;
usb_read_ng_buflen = 0; usb_read_ng_buflen = 0;
usb_read_ng_bufoff = 0; usb_read_ng_bufoff = 0;
} }
while (len) { while (len) {
if (!usb_check()) break; if (!usb_check())
break;
if ((pUdp->UDP_CSR[AT91C_EP_OUT] & bank)) { if ((pUdp->UDP_CSR[AT91C_EP_OUT] & bank)) {
@ -733,11 +744,13 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
packetSize = MIN(available, len); packetSize = MIN(available, len);
available -= packetSize; available -= packetSize;
len -= packetSize; len -= packetSize;
while (packetSize--) while (packetSize--) {
data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT]; data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
}
// fill the local buffer with the remaining bytes // fill the local buffer with the remaining bytes
for (uint32_t i = 0; i < available; i++) for (uint32_t i = 0; i < available; i++) {
usb_read_ng_buffer[i] = pUdp->UDP_FDR[AT91C_EP_OUT]; usb_read_ng_buffer[i] = pUdp->UDP_FDR[AT91C_EP_OUT];
}
usb_read_ng_buflen = available; usb_read_ng_buflen = available;
// flip bank // flip bank
UDP_CLEAR_EP_FLAGS(AT91C_EP_OUT, bank) UDP_CLEAR_EP_FLAGS(AT91C_EP_OUT, bank)
@ -746,7 +759,8 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
else else
bank = AT91C_UDP_RX_DATA_BK0; bank = AT91C_UDP_RX_DATA_BK0;
} }
if (time_out++ == 0x1fff) break; if (time_out++ == 0x1fff)
break;
} }
btReceiveBank = bank; btReceiveBank = bank;