mirror of
https://github.com/gdsports/USBHost_t36
synced 2025-02-16 06:50:14 -05:00
Put QH into schedule when creating pipe
This commit is contained in:
parent
92404ec121
commit
f4d60b7594
3
host.h
3
host.h
@ -49,10 +49,9 @@ struct Pipe_struct {
|
|||||||
Device_t *device;
|
Device_t *device;
|
||||||
uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt
|
uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt
|
||||||
uint8_t direction; // 0=out, 1=in
|
uint8_t direction; // 0=out, 1=in
|
||||||
uint8_t active;
|
|
||||||
//uint8_t endpoint; // 0 to 15
|
//uint8_t endpoint; // 0 to 15
|
||||||
//uint8_t data01; // next packet DATA0 or DATA1
|
//uint8_t data01; // next packet DATA0 or DATA1
|
||||||
uint8_t unusedbyte[1];
|
uint8_t unusedbyte[2];
|
||||||
uint32_t unused[2];
|
uint32_t unused[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -324,7 +324,6 @@ Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t dire
|
|||||||
pipe->qh.buffer[2] = 0;
|
pipe->qh.buffer[2] = 0;
|
||||||
pipe->qh.buffer[3] = 0;
|
pipe->qh.buffer[3] = 0;
|
||||||
pipe->qh.buffer[4] = 0;
|
pipe->qh.buffer[4] = 0;
|
||||||
pipe->active = 0;
|
|
||||||
pipe->direction = direction;
|
pipe->direction = direction;
|
||||||
pipe->type = type;
|
pipe->type = type;
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
@ -340,7 +339,7 @@ Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t dire
|
|||||||
dtc, dev->speed, endpoint, 0, dev->address);
|
dtc, dev->speed, endpoint, 0, dev->address);
|
||||||
pipe->qh.capabilities[1] = QH_capabilities2(1, dev->hub_port,
|
pipe->qh.capabilities[1] = QH_capabilities2(1, dev->hub_port,
|
||||||
dev->hub_address, 0, 0);
|
dev->hub_address, 0, 0);
|
||||||
#if 0
|
#if 1
|
||||||
if (type == 0 || type == 2) {
|
if (type == 0 || type == 2) {
|
||||||
// control or bulk: add to async queue
|
// control or bulk: add to async queue
|
||||||
Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR;
|
Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR;
|
||||||
@ -356,7 +355,6 @@ Pipe_t * new_Pipe(Device_t *dev, uint32_t type, uint32_t endpoint, uint32_t dire
|
|||||||
list->qh.horizontal_link = (uint32_t)&(pipe->qh) | 2;
|
list->qh.horizontal_link = (uint32_t)&(pipe->qh) | 2;
|
||||||
Serial.println(" added to async list");
|
Serial.println(" added to async list");
|
||||||
}
|
}
|
||||||
pipe->active = 1;
|
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
// interrupt: add to periodic schedule
|
// interrupt: add to periodic schedule
|
||||||
// TODO: link it into the periodic table
|
// TODO: link it into the periodic table
|
||||||
@ -446,49 +444,15 @@ void queue_Transfer(Transfer_t *transfer)
|
|||||||
{
|
{
|
||||||
Serial.println("queue_Transfer");
|
Serial.println("queue_Transfer");
|
||||||
Pipe_t *pipe = transfer->pipe;
|
Pipe_t *pipe = transfer->pipe;
|
||||||
|
Transfer_t *last = (Transfer_t *)(pipe->qh.next);
|
||||||
if (!pipe->active) {
|
if ((uint32_t)last & 1) {
|
||||||
if (pipe->type == 0 || pipe->type == 2) {
|
pipe->qh.next = (uint32_t)transfer;
|
||||||
// control or bulk: add to async queue
|
Serial.println(" first on QH");
|
||||||
pipe->qh.next = (uint32_t)transfer;
|
|
||||||
Pipe_t *list = (Pipe_t *)USBHS_ASYNCLISTADDR;
|
|
||||||
if (list == NULL) {
|
|
||||||
Serial.println(" first in async list, with qTD");
|
|
||||||
pipe->qh.capabilities[0] |= 0x8000; // H bit
|
|
||||||
pipe->qh.horizontal_link = (uint32_t)(&(pipe->qh)) | 2; // 2=QH
|
|
||||||
USBHS_ASYNCLISTADDR = (uint32_t)pipe;
|
|
||||||
print(pipe);
|
|
||||||
Serial.println(USBHS_USBSTS & USBHS_USBSTS_AS, HEX);
|
|
||||||
Serial.println(USBHS_USBCMD & USBHS_USBCMD_ASE, HEX);
|
|
||||||
//USBHS_USBCMD |= USBHS_USBCMD_IAA;
|
|
||||||
USBHS_USBCMD |= USBHS_USBCMD_ASE; // enable async schedule
|
|
||||||
uint32_t count=0;
|
|
||||||
while (!(USBHS_USBSTS & USBHS_USBSTS_AS)) count++;
|
|
||||||
Serial.print(" waited ");
|
|
||||||
Serial.println(count);
|
|
||||||
Serial.println(USBHS_USBCMD & USBHS_USBCMD_ASE, HEX);
|
|
||||||
Serial.println(USBHS_USBSTS & USBHS_USBSTS_AS, HEX);
|
|
||||||
} else {
|
|
||||||
// EHCI 1.0: section 4.8.1, page 72
|
|
||||||
pipe->qh.horizontal_link = list->qh.horizontal_link;
|
|
||||||
list->qh.horizontal_link = (uint32_t)&(pipe->qh) | 2;
|
|
||||||
Serial.println(" added to async list, with qTD");
|
|
||||||
}
|
|
||||||
pipe->active = 1;
|
|
||||||
} else if (pipe->type == 3) {
|
|
||||||
// interrupt: add to periodic schedule
|
|
||||||
// TODO: link it into the periodic table
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Transfer_t *last = (Transfer_t *)(pipe->qh.next);
|
while ((last->qtd.next & 1) == 0) last = (Transfer_t *)(last->qtd.next);
|
||||||
if ((uint32_t)last & 1) {
|
// TODO: what happens if qTD is completed before we write to it?
|
||||||
pipe->qh.next = (uint32_t)transfer;
|
last->qtd.next = (uint32_t)transfer;
|
||||||
Serial.println(" first on QH");
|
Serial.println(" added to qTD list");
|
||||||
} else {
|
|
||||||
while ((last->qtd.next & 1) == 0) last = (Transfer_t *)(last->qtd.next);
|
|
||||||
last->qtd.next = (uint32_t)transfer;
|
|
||||||
Serial.println(" added to qTD list");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user