Browse Source

Put QH into schedule when creating pipe

main
PaulStoffregen 7 years ago
parent
commit
f4d60b7594
2 changed files with 10 additions and 47 deletions
  1. +1
    -2
      host.h
  2. +9
    -45
      k66_usbhost.ino

+ 1
- 2
host.h View File

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];
}; };



+ 9
- 45
k66_usbhost.ino View File

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) {
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;
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
{ {
Serial.println("queue_Transfer"); Serial.println("queue_Transfer");
Pipe_t *pipe = transfer->pipe; Pipe_t *pipe = transfer->pipe;

if (!pipe->active) {
if (pipe->type == 0 || pipe->type == 2) {
// control or bulk: add to async queue
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
}
Transfer_t *last = (Transfer_t *)(pipe->qh.next);
if ((uint32_t)last & 1) {
pipe->qh.next = (uint32_t)transfer;
Serial.println(" first on QH");
} else { } else {
Transfer_t *last = (Transfer_t *)(pipe->qh.next);
if ((uint32_t)last & 1) {
pipe->qh.next = (uint32_t)transfer;
Serial.println(" first on QH");
} 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");
}
while ((last->qtd.next & 1) == 0) last = (Transfer_t *)(last->qtd.next);
// TODO: what happens if qTD is completed before we write to it?
last->qtd.next = (uint32_t)transfer;
Serial.println(" added to qTD list");
} }
} }



Loading…
Cancel
Save