Usermode/libc++ - Implement map::insert and map::erase
[tpg/acess2.git] / KernelLand / Modules / USB / Core / usb_io.c
index 992269a..de6f6f1 100644 (file)
@@ -45,7 +45,7 @@ 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);
 }
 
 
@@ -53,22 +53,21 @@ void USB_SendData(tUSBInterface *Dev, int Endpoint, size_t Length, const void *D
 {
        tUSBHost *host;
        tUSBEndpoint    *ep;
+       void    *dest_hdl;
        ENTER("pDev iEndpoint iLength pData", Dev, Endpoint, Length, Data);
 
-       ep = &Dev->Endpoints[Endpoint-1];
        host = Dev->Dev->Host;
-
-       if( Length > ep->MaxPacketSize ) {
-               Log_Warning("USB", "Max packet size exceeded (%i > %i)", ep->MaxPacketSize);
+       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->BulkOUT(
-               host->Ptr, Dev->Dev->Address*16 + Dev->Endpoints[Endpoint-1].EndpointNum,
-               0, USB_WakeCallback, Proc_GetCurThread(),
-               (void*)Data, Length
-               );
+       host->HostDef->SendBulk(host->Ptr, dest_hdl, USB_WakeCallback, Proc_GetCurThread(), 1, (void*)Data, Length);
        Threads_WaitEvents(THREAD_EVENT_SHORTWAIT);
        
        LEAVE('-');
@@ -78,31 +77,31 @@ void USB_RecvData(tUSBInterface *Dev, int Endpoint, size_t Length, void *Data)
 {
        tUSBHost *host;
        tUSBEndpoint    *ep;
+       void    *dest_hdl;
        ENTER("pDev iEndpoint iLength pData", Dev, Endpoint, Length, Data);
 
-       ep = &Dev->Endpoints[Endpoint-1];
        host = Dev->Dev->Host;
-
-       if( Length > ep->MaxPacketSize ) {
-               Log_Warning("USB", "Max packet size exceeded (%i > %i)", ep->MaxPacketSize);
+       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->BulkIN(
-               host->Ptr, Dev->Dev->Address*16 + Dev->Endpoints[Endpoint-1].EndpointNum,
-               0, USB_WakeCallback, Proc_GetCurThread(),
-               Data, Length
-               );
+       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); 
 
@@ -112,16 +111,16 @@ 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('-');
 

UCC git Repository :: git.ucc.asn.au