mirror of
https://github.com/gdsports/USBHost_t36
synced 2024-11-25 02:22:17 -05:00
FTDI transmit, improve performance for fast output
This commit is contained in:
parent
5575f9fcae
commit
9840e82db8
@ -747,7 +747,8 @@ private:
|
|||||||
|
|
||||||
class USBSerial: public USBDriver, public Stream {
|
class USBSerial: public USBDriver, public Stream {
|
||||||
public:
|
public:
|
||||||
enum { BUFFER_SIZE = 390 }; // must hold at least 6 max size packets, plus 2 extra bytes
|
// FIXME: need different USBSerial, with bigger buffers for 480 Mbit & faster speed
|
||||||
|
enum { BUFFER_SIZE = 648 }; // must hold at least 6 max size packets, plus 2 extra bytes
|
||||||
USBSerial(USBHost &host) : txtimer(this) { init(); }
|
USBSerial(USBHost &host) : txtimer(this) { init(); }
|
||||||
void begin(uint32_t baud, uint32_t format=0);
|
void begin(uint32_t baud, uint32_t format=0);
|
||||||
void end(void);
|
void end(void);
|
||||||
|
2
ehci.cpp
2
ehci.cpp
@ -393,7 +393,7 @@ void USBHost::isr()
|
|||||||
|
|
||||||
void USBDriverTimer::start(uint32_t microseconds)
|
void USBDriverTimer::start(uint32_t microseconds)
|
||||||
{
|
{
|
||||||
#ifdef USBHOST_PRINT_DEBUG
|
#if defined(USBHOST_PRINT_DEBUG) && 0
|
||||||
Serial.print("start_timer, us = ");
|
Serial.print("start_timer, us = ");
|
||||||
Serial.print(microseconds);
|
Serial.print(microseconds);
|
||||||
Serial.print(", driver = ");
|
Serial.print(", driver = ");
|
||||||
|
45
serial.cpp
45
serial.cpp
@ -287,13 +287,50 @@ void USBSerial::rx_queue_packets(uint32_t head, uint32_t tail)
|
|||||||
|
|
||||||
void USBSerial::tx_data(const Transfer_t *transfer)
|
void USBSerial::tx_data(const Transfer_t *transfer)
|
||||||
{
|
{
|
||||||
if (transfer->buffer == tx1) {
|
uint32_t mask;
|
||||||
|
uint8_t *p = (uint8_t *)transfer->buffer;
|
||||||
|
if (p == tx1) {
|
||||||
println("tx1:");
|
println("tx1:");
|
||||||
txstate &= 0xFE;
|
mask = 1;
|
||||||
} else if (transfer->buffer == tx2) {
|
//txstate &= 0xFE;
|
||||||
|
} else if (p == tx2) {
|
||||||
println("tx2:");
|
println("tx2:");
|
||||||
txstate &= 0xFD;
|
mask = 2;
|
||||||
|
//txstate &= 0xFD;
|
||||||
|
} else {
|
||||||
|
return; // should never happen
|
||||||
}
|
}
|
||||||
|
// check how much more data remains in the transmit buffer
|
||||||
|
uint32_t head = txhead;
|
||||||
|
uint32_t tail = txtail;
|
||||||
|
uint32_t count;
|
||||||
|
if (head >= tail) {
|
||||||
|
count = head - tail;
|
||||||
|
} else {
|
||||||
|
count = txsize + head - tail;
|
||||||
|
}
|
||||||
|
uint32_t packetsize = tx2 - tx1;
|
||||||
|
if (count < packetsize) {
|
||||||
|
// not enough data in buffer to fill a full packet
|
||||||
|
txstate &= ~mask;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// immediately transmit another full packet, if we have enough data
|
||||||
|
println("TX:moar data!!!!");
|
||||||
|
if (++tail >= txsize) tail = 0;
|
||||||
|
uint32_t n = txsize - tail;
|
||||||
|
if (n > packetsize) n = packetsize;
|
||||||
|
memcpy(p, txbuf + tail, n);
|
||||||
|
if (n >= packetsize) {
|
||||||
|
tail += n - 1;
|
||||||
|
if (tail >= txsize) tail = 0;
|
||||||
|
} else {
|
||||||
|
uint32_t len = packetsize - n;
|
||||||
|
memcpy(p + n, txbuf, len);
|
||||||
|
tail = len - 1;
|
||||||
|
}
|
||||||
|
txtail = tail;
|
||||||
|
queue_Data_Transfer(txpipe, p, packetsize, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user