X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_io.c;h=de6f6f1169279a0764106725d3882eceaccd5b59;hb=f7ec06bee2b80613d80c314bf864c69209d09829;hp=a1bf50b1c691fcf290bee35150fc6dddb8a7f7cd;hpb=d8bf9f747a87c3c1d23461c155ef90b7fc148a21;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_io.c b/KernelLand/Modules/USB/Core/usb_io.c index a1bf50b1..de6f6f11 100644 --- a/KernelLand/Modules/USB/Core/usb_io.c +++ b/KernelLand/Modules/USB/Core/usb_io.c @@ -11,11 +11,14 @@ #include "usb.h" #include "usb_lowlevel.h" #include +#include #include "usb_async.h" // === 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_SendData(tUSBInterface *Dev, int Endpoint, size_t Length, const void *Data); +void USB_WakeCallback(void *Ptr, void *Buf, size_t Length); void USB_AsyncCallback(void *Ptr, void *Buf, size_t Length); void USB_AsyncThread(void *unused); @@ -42,24 +45,63 @@ void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Valu else endpt = 0; - USB_int_Request(Iface->Dev->Host, Iface->Dev->Address, endpt, Type, Req, Value, Index, Len, Data); + USB_int_Request(Iface->Dev, endpt, Type, Req, Value, Index, Len, Data); } -void USB_SendData(tUSBInterface *Dev, int Endpoint, int Length, void *Data) +void USB_SendData(tUSBInterface *Dev, int Endpoint, size_t Length, const void *Data) { - Log_Warning("USB", "TODO: Implement USB_SendData"); + tUSBHost *host; + tUSBEndpoint *ep; + void *dest_hdl; + ENTER("pDev iEndpoint iLength pData", Dev, Endpoint, Length, Data); + + host = Dev->Dev->Host; + ep = &Dev->Endpoints[Endpoint-1]; + dest_hdl = Dev->Dev->EndpointHandles[ep->EndpointNum]; + LOG("dest_hdl = %p", dest_hdl); + if( !dest_hdl ) { + Log_Notice("USB", "_SendData on uninitialised enpoint (%p#%i)", Dev->Dev, ep->EndpointNum); + LEAVE('-'); + return; + } + + Threads_ClearEvent(THREAD_EVENT_SHORTWAIT); + host->HostDef->SendBulk(host->Ptr, dest_hdl, USB_WakeCallback, Proc_GetCurThread(), 1, (void*)Data, Length); + Threads_WaitEvents(THREAD_EVENT_SHORTWAIT); + + LEAVE('-'); } -void USB_RecvData(tUSBInterface *Dev, int Endpoint, int Length, void *Data) +void USB_RecvData(tUSBInterface *Dev, int Endpoint, size_t Length, void *Data) { - Log_Warning("USB", "TODO: Implement USB_RecvData"); + tUSBHost *host; + tUSBEndpoint *ep; + void *dest_hdl; + ENTER("pDev iEndpoint iLength pData", Dev, Endpoint, Length, Data); + + host = Dev->Dev->Host; + ep = &Dev->Endpoints[Endpoint-1]; + dest_hdl = Dev->Dev->EndpointHandles[ep->EndpointNum]; + LOG("dest_hdl = %p", dest_hdl); + if( !dest_hdl ) { + Log_Notice("USB", "_RecvData on uninitialised enpoint (%p#%i)", Dev->Dev, ep->EndpointNum); + LEAVE('-'); + return; + } + + Threads_ClearEvent(THREAD_EVENT_SHORTWAIT); + host->HostDef->SendBulk(host->Ptr, dest_hdl, USB_WakeCallback, Proc_GetCurThread(), 0, Data, Length); + Threads_WaitEvents(THREAD_EVENT_SHORTWAIT); + + LEAVE('-'); } -void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, tUSB_DataCallback Callback) +void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, size_t Length, void *DataBuf) { tAsyncOp *op; tUSBHost *host; + void *dest_hdl; ENTER("pDev iEndpoint iLength pDataBuf", Dev, Endpoint, Length, DataBuf); @@ -69,22 +111,27 @@ void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, op->Length = Length; op->Data = DataBuf; - // TODO: Handle transfers that are larger than one packet - // TODO: Data toggle - host = Dev->Dev->Host; + dest_hdl = Dev->Dev->EndpointHandles[op->Endpt->EndpointNum]; + if( !dest_hdl ) { + Log_Notice("USB", "_SendData on uninitialised enpoint (%p#%i)", Dev->Dev, op->Endpt->EndpointNum); + LEAVE('-'); + return; + } + LOG("IN from %p %i:%i", host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum); - host->HostDef->BulkIN( - host->Ptr, Dev->Dev->Address*16 + op->Endpt->EndpointNum, - 0, USB_AsyncCallback, op, - DataBuf, Length - ); + host->HostDef->SendBulk(host->Ptr, dest_hdl, USB_AsyncCallback, op, 0, DataBuf, Length); LEAVE('-'); // Log_Warning("USB", "TODO: Implement USB_RecvDataA"); } +void USB_WakeCallback(void *Ptr, void *Buf, size_t Length) +{ + Threads_PostEvent(Ptr, THREAD_EVENT_SHORTWAIT); +} + void USB_AsyncCallback(void *Ptr, void *Buf, size_t Length) { tAsyncOp *op = Ptr;