3 * - By John Hodge (thePowersGang)
12 #include "usb_lowlevel.h"
13 #include <workqueue.h>
14 #include "usb_async.h"
17 void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data);
18 void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Value, int Index, int Len, void *Data);
19 void USB_AsyncCallback(void *Ptr, void *Buf, size_t Length);
20 void USB_AsyncThread(void *unused);
23 tWorkqueue gUSB_AsyncQueue;
26 void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data)
28 USB_int_ReadDescriptor(Iface->Dev, 0, Type, Index, Length, Data);
31 void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Value, int Index, int Len, void *Data)
36 if(Endpoint < 0 || Endpoint >= Iface->nEndpoints)
39 // Get endpoint number
41 endpt = Iface->Endpoints[Endpoint-1].EndpointNum;
45 USB_int_Request(Iface->Dev->Host, Iface->Dev->Address, endpt, Type, Req, Value, Index, Len, Data);
49 void USB_SendData(tUSBInterface *Dev, int Endpoint, int Length, void *Data)
51 Log_Warning("USB", "TODO: Implement USB_SendData");
54 void USB_RecvData(tUSBInterface *Dev, int Endpoint, int Length, void *Data)
56 Log_Warning("USB", "TODO: Implement USB_RecvData");
59 void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, tUSB_DataCallback Callback)
64 ENTER("pDev iEndpoint iLength pDataBuf", Dev, Endpoint, Length, DataBuf);
66 op = malloc(sizeof(*op));
68 op->Endpt = &Dev->Endpoints[Endpoint-1];
72 // TODO: Handle transfers that are larger than one packet
75 host = Dev->Dev->Host;
76 LOG("IN from %p %i:%i", host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum);
77 host->HostDef->BulkIN(
78 host->Ptr, Dev->Dev->Address*16 + op->Endpt->EndpointNum,
79 0, USB_AsyncCallback, op,
85 // Log_Warning("USB", "TODO: Implement USB_RecvDataA");
88 void USB_AsyncCallback(void *Ptr, void *Buf, size_t Length)
92 LOG("adding %p to work queue", op);
93 Workqueue_AddWork(&gUSB_AsyncQueue, op);
96 void USB_AsyncThread(void *Unused)
98 Threads_SetName("USB Async IO Thread");
101 tAsyncOp *op = Workqueue_GetWork(&gUSB_AsyncQueue);
102 tUSBInterface *iface = op->Endpt->Interface;
106 iface->Driver->Endpoints[op->Endpt->EndpointIdx].DataAvail(
107 iface, op->Endpt->EndpointIdx,
108 op->Length, op->Data);