Bläddra i källkod

Improve MIDI transmit speed

main
PaulStoffregen 3 år sedan
förälder
incheckning
cd4c277209
3 ändrade filer med 29 tillägg och 15 borttagningar
  1. +4
    -2
      USBHost_t36.h
  2. +1
    -1
      ehci.cpp
  3. +24
    -12
      midi.cpp

+ 4
- 2
USBHost_t36.h Visa fil

@@ -499,7 +499,7 @@ public:
uint32_t started_micros; // testing only
private:
USBDriver *driver;
USBHIDInput *hidinput;
USBHIDInput *hidinput;
uint32_t usec;
USBDriverTimer *next;
USBDriverTimer *prev;
@@ -1060,7 +1060,7 @@ public:
};
MIDIDeviceBase(USBHost &host, uint32_t *rx, uint32_t *tx1, uint32_t *tx2,
uint16_t bufsize, uint32_t *rqueue, uint16_t qsize) :
rx_buffer(rx), tx_buffer1(tx1), tx_buffer2(tx2),
txtimer(this), rx_buffer(rx), tx_buffer1(tx1), tx_buffer2(tx2),
rx_queue(rqueue), max_packet_size(bufsize), rx_queue_size(qsize) {
init();
}
@@ -1301,6 +1301,7 @@ public:
protected:
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len);
virtual void disconnect();
virtual void timer_event(USBDriverTimer *timer);
static void rx_callback(const Transfer_t *transfer);
static void tx_callback(const Transfer_t *transfer);
void rx_data(const Transfer_t *transfer);
@@ -1313,6 +1314,7 @@ protected:
private:
Pipe_t *rxpipe;
Pipe_t *txpipe;
USBDriverTimer txtimer;
//enum { MAX_PACKET_SIZE = 64 };
//enum { RX_QUEUE_SIZE = 80 }; // must be more than MAX_PACKET_SIZE/4
//uint32_t rx_buffer[MAX_PACKET_SIZE/4];

+ 1
- 1
ehci.cpp Visa fil

@@ -239,7 +239,7 @@ void USBHost::begin()
USBHS_PERIODICLISTBASE = (uint32_t)periodictable;
USBHS_FRINDEX = 0;
USBHS_ASYNCLISTADDR = 0;
USBHS_USBCMD = USBHS_USBCMD_ITC(8) | USBHS_USBCMD_RS |
USBHS_USBCMD = USBHS_USBCMD_ITC(0) | USBHS_USBCMD_RS |
USBHS_USBCMD_ASP(3) | USBHS_USBCMD_ASPE | USBHS_USBCMD_PSE |
#if PERIODIC_LIST_SIZE == 8
USBHS_USBCMD_FS2 | USBHS_USBCMD_FS(3);

+ 24
- 12
midi.cpp Visa fil

@@ -294,40 +294,52 @@ void MIDIDeviceBase::write_packed(uint32_t data)
if (!txpipe) return;
uint32_t tx_max = tx_size / 4;
while (1) {
__disable_irq();
uint32_t tx1 = tx1_count;
uint32_t tx2 = tx2_count;
if (tx1 < tx_max && (tx2 == 0 || tx2 >= tx_max)) {
// use tx_buffer1
tx_buffer1[tx1++] = data;
tx1_count = tx1;
__disable_irq();
txtimer.stop();
if (tx1 >= tx_max) {
queue_Data_Transfer(txpipe, tx_buffer1, tx_max*4, this);
} else {
// TODO: start a timer, rather than sending the buffer
// before it's full, to make best use of bandwidth
tx1_count = tx_max;
queue_Data_Transfer(txpipe, tx_buffer1, tx_max*4, this);
txtimer.start(tx_max >= 128 ? 200 : 1500);
}
__enable_irq();
__enable_irq();
return;
}
if (tx2 < tx_max) {
// use tx_buffer2
tx_buffer2[tx2++] = data;
tx2_count = tx2;
__disable_irq();
txtimer.stop();
if (tx2 >= tx_max) {
queue_Data_Transfer(txpipe, tx_buffer2, tx_max*4, this);
} else {
// TODO: start a timer, rather than sending the buffer
// before it's full, to make best use of bandwidth
tx2_count = tx_max;
queue_Data_Transfer(txpipe, tx_buffer2, tx_max*4, this);
txtimer.start(tx_max >= 128 ? 200 : 1500);
}
__enable_irq();
__enable_irq();
return;
}
__enable_irq();
// TODO: call yield() ??
}
}

void MIDIDeviceBase::timer_event(USBDriverTimer *timer)
{
const uint32_t tx_max = tx_size / 4;
uint32_t tx1 = tx1_count;
if (tx1 > 0) {
tx1_count = tx_max;
queue_Data_Transfer(txpipe, tx_buffer1, tx1*4, this);
}
uint32_t tx2 = tx2_count;
if (tx2 > 0) {
tx2_count = tx_max;
queue_Data_Transfer(txpipe, tx_buffer2, tx2*4, this);
}
}


Laddar…
Avbryt
Spara