X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FUSB%2FCore%2Fusb_io.c;h=50320c65b115c3a77feb56ed56b0913e5f5623ca;hb=0e361ff8d9472885f770a370c0d477c229041572;hp=993bf0cccd85f9d3b0fa1fe2afb545e0c101dab8;hpb=7aa331d83b8dd23d3ca7530fa582cec528df274a;p=tpg%2Facess2.git diff --git a/Modules/USB/Core/usb_io.c b/Modules/USB/Core/usb_io.c index 993bf0cc..50320c65 100644 --- a/Modules/USB/Core/usb_io.c +++ b/Modules/USB/Core/usb_io.c @@ -10,7 +10,7 @@ #include #include "usb.h" #include "usb_lowlevel.h" -#include +#include typedef struct sAsyncOp tAsyncOp; @@ -25,9 +25,11 @@ struct sAsyncOp // === PROTOTYPES === void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data); void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Value, int Index, int Len, void *Data); +void USB_AsyncCallback(void *Ptr, void *Buf, int Length); +void USB_AsyncThread(void *unused); // === GLOBALS === -tSemaphore glUSB_AsyncQueue; +tWorkqueue gUSB_AsyncQueue; // === CODE === void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data) @@ -65,15 +67,52 @@ void USB_RecvData(tUSBInterface *Dev, int Endpoint, int Length, void *Data) void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, tUSB_DataCallback Callback) { - Log_Warning("USB", "TODO: Implement USB_RecvDataA"); + tAsyncOp *op; + tUSBHost *host; + + ENTER("pDev iEndpoint iLength pDataBuf", Dev, Endpoint, Length, DataBuf); + + op = malloc(sizeof(*op)); + op->Next = NULL; + op->Endpt = &Dev->Endpoints[Endpoint-1]; + op->Length = Length; + op->Data = DataBuf; + + // TODO: Handle transfers that are larger than one packet + + host = Dev->Dev->Host; + LOG("IN from %p %i:%i", host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum); + host->HostDef->SendIN( + host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum, + 0, USB_AsyncCallback, op, + DataBuf, Length + ); + + LEAVE('-'); + +// Log_Warning("USB", "TODO: Implement USB_RecvDataA"); +} + +void USB_AsyncCallback(void *Ptr, void *Buf, int Length) +{ + tAsyncOp *op = Ptr; + op->Length = Length; + LOG("adding %p to work queue", op); + Workqueue_AddWork(&gUSB_AsyncQueue, op); } void USB_AsyncThread(void *Unused) { for(;;) { - Semaphore_Wait(&glUSB_AsyncQueue, 1); - + tAsyncOp *op = Workqueue_GetWork(&gUSB_AsyncQueue); + tUSBInterface *iface = op->Endpt->Interface; + + LOG("op = %p", op); + + iface->Driver->Endpoints[op->Endpt->EndpointIdx].DataAvail( + iface, op->Endpt->EndpointIdx, + op->Length, op->Data); } }