Browse Source

CLeanup of RX buffer/queue management.

main
MatthewBergman 4 years ago
parent
commit
0d0d0a6116
2 changed files with 11 additions and 23 deletions
  1. +2
    -3
      USBHost_t36.h
  2. +9
    -20
      adk.cpp

+ 2
- 3
USBHost_t36.h View File

//#define USBHOST_PRINT_DEBUG //#define USBHOST_PRINT_DEBUG
//#define USBHDBGSerial Serial1 //#define USBHDBGSerial Serial1



#ifndef USBHDBGSerial #ifndef USBHDBGSerial
#define USBHDBGSerial Serial #define USBHDBGSerial Serial
#endif #endif
Pipe_t *txpipe; Pipe_t *txpipe;
enum { MAX_PACKET_SIZE = 512 }; enum { MAX_PACKET_SIZE = 512 };
enum { RX_QUEUE_SIZE = 1024 }; // must be more than MAX_PACKET_SIZE enum { RX_QUEUE_SIZE = 1024 }; // must be more than MAX_PACKET_SIZE
uint32_t rx_buffer[MAX_PACKET_SIZE/4];
uint32_t tx_buffer[MAX_PACKET_SIZE/4];
uint8_t rx_buffer[MAX_PACKET_SIZE];
uint8_t tx_buffer[MAX_PACKET_SIZE];
uint16_t rx_size; uint16_t rx_size;
uint16_t tx_size; uint16_t tx_size;
uint8_t rx_queue[RX_QUEUE_SIZE]; uint8_t rx_queue[RX_QUEUE_SIZE];

+ 9
- 20
adk.cpp View File

print_hexbytes(transfer->buffer, len); print_hexbytes(transfer->buffer, len);
uint32_t head = rx_head; uint32_t head = rx_head;
uint32_t tail = rx_tail;
for (uint32_t i=0; i < len; i++)
uint8_t *p = (const uint8_t *)transfer->buffer;
if (p != NULL && len != 0)
{ {
uint32_t msg = rx_buffer[i];
if (msg)
do
{ {
if (++head >= RX_QUEUE_SIZE) if (++head >= RX_QUEUE_SIZE)
head = 0; head = 0;
rx_queue[head] = msg;
if (++head >= RX_QUEUE_SIZE)
head = 0;
rx_queue[head] = msg >> 8;
if (++head >= RX_QUEUE_SIZE)
head = 0;
rx_queue[head] = msg >> 16;
if (++head >= RX_QUEUE_SIZE)
head = 0;
rx_queue[head] = msg >> 24;
}
rx_queue[head] = *p++;
} while (--len);
} }
rx_head = head; rx_head = head;
rx_packet_queued = false; rx_packet_queued = false;
rx_queue_packets(head, tail);
rx_queue_packets(rx_head, rx_tail);
} }


void ADK::rx_queue_packets(uint32_t head, uint32_t tail) void ADK::rx_queue_packets(uint32_t head, uint32_t tail)
{ {
// enough space to accept another full packet // enough space to accept another full packet
println("queue another receive packet"); println("queue another receive packet");
queue_Data_Transfer(rxpipe, rx_buffer, rx_size, this); queue_Data_Transfer(rxpipe, rx_buffer, rx_size, this);
rx_packet_queued = true; rx_packet_queued = true;
} else { } else {
{ {
memcpy(tx_buffer, buf, len); memcpy(tx_buffer, buf, len);
__disable_irq(); __disable_irq();
queue_Data_Transfer(txpipe, tx_buffer, len, this);
queue_Data_Transfer(txpipe, tx_buffer, len, this);
__enable_irq(); __enable_irq();
return len; return len;

Loading…
Cancel
Save