3 * - By John Hodge (thePowersGang)
12 #include "usb_async.h"
15 extern tUSBHost *gUSB_Hosts;
18 void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint);
23 void USB_int_PollCallback(void *Ptr, void *Data, size_t Length)
26 tUSBEndpoint *ep = Ptr;
28 op = malloc(sizeof(*op));
33 op->Data = ep->InputData;
35 LOG("op %p, endpoint %p (0x%x)", op, ep,
36 ep->Interface->Dev->Address * 16 + ep->EndpointNum);
38 Workqueue_AddWork(&gUSB_AsyncQueue, op);
41 void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint)
45 ENTER("pIface iEndpoint", Iface, Endpoint);
48 if(Endpoint <= 0 || Endpoint > Iface->nEndpoints) {
52 endpt = &Iface->Endpoints[Endpoint-1];
53 LOG("endpt(%p)->PollingPeriod = %i", endpt, endpt->PollingPeriod);
54 if(endpt->PollingPeriod > 256 || endpt->PollingPeriod <= 0) {
55 LOG("Invalid polling period");
60 // TODO: Check that this endpoint isn't already on the queue
62 endpt->InputData = malloc(endpt->MaxPacketSize);
63 LOG("Polling 0x%x at %i ms", Iface->Dev->Address * 16 + endpt->EndpointNum, endpt->PollingPeriod);
64 Iface->Dev->Host->HostDef->InterruptIN(
65 Iface->Dev->Host->Ptr,
66 Iface->Dev->Address * 16 + endpt->EndpointNum,
68 USB_int_PollCallback, endpt,
69 endpt->InputData, endpt->MaxPacketSize
75 * \brief USB polling thread
77 int USB_PollThread(void *unused)
79 Threads_SetName("USB Polling Thread");
83 for( tUSBHost *host = gUSB_Hosts; host; host = host->Next )
85 host->HostDef->CheckPorts(host->Ptr);