From: John Hodge Date: Thu, 23 Feb 2012 16:03:59 +0000 (+0800) Subject: Modules/USB - Documention/Debugging, and fixed an API use X-Git-Tag: rel0.15~756 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=06f200335c3bcbd68c6df92589d8b17b73ac3679;p=tpg%2Facess2.git Modules/USB - Documention/Debugging, and fixed an API use --- diff --git a/KernelLand/Modules/USB/Core/include/usb_host.h b/KernelLand/Modules/USB/Core/include/usb_host.h index e2748da9..eda42cf9 100644 --- a/KernelLand/Modules/USB/Core/include/usb_host.h +++ b/KernelLand/Modules/USB/Core/include/usb_host.h @@ -26,6 +26,10 @@ struct sUSBHostDef tUSBHostOp SendOUT; tUSBHostOp SendSETUP; + /** + * \brief Check if an operation has completed + * \note Only valid to call if CB passed was ERRPTR + */ int (*IsOpComplete)(void *Ptr, void *OpPtr); void (*CheckPorts)(void *Ptr); diff --git a/KernelLand/Modules/USB/Core/usb_devinit.c b/KernelLand/Modules/USB/Core/usb_devinit.c index 4b18b30a..06efd217 100644 --- a/KernelLand/Modules/USB/Core/usb_devinit.c +++ b/KernelLand/Modules/USB/Core/usb_devinit.c @@ -5,7 +5,7 @@ * usb_devinit.c * - USB Device Initialisation */ -#define DEBUG 0 +#define DEBUG 1 #include #include @@ -72,7 +72,8 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG(" .SerialNumberStr = Str %i", desc.SerialNumberStr); LOG(" .NumConfigurations = %i", desc.SerialNumberStr); LOG("}"); - + + #if DEBUG if( desc.ManufacturerStr ) { char *tmp = USB_int_GetDeviceString(dev, 0, desc.ManufacturerStr); @@ -91,6 +92,7 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG("SerialNumbertStr = '%s'", tmp); free(tmp); } + #endif } // TODO: Support alternate configurations @@ -142,6 +144,10 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) size_t iface_base_ofs; iface = (void*)(full_buf + ptr_ofs); + if( iface->Length == 0 ) { + Log_Warning("USB", "Bad USB descriptor (length = 0)"); + break ; + } ptr_ofs += iface->Length; if( ptr_ofs > total_length ) { // Sanity fail @@ -161,11 +167,13 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG(" .InterfaceClass = 0x%x", iface->InterfaceClass); LOG(" .InterfaceSubClass = 0x%x", iface->InterfaceSubClass); LOG(" .InterfaceProcol = 0x%x", iface->InterfaceProtocol); + #if DEBUG if( iface->InterfaceStr ) { char *tmp = USB_int_GetDeviceString(dev, 0, iface->InterfaceStr); LOG(" .InterfaceStr = %i '%s'", iface->InterfaceStr, tmp); free(tmp); } + #endif LOG("}"); dev_if = malloc(sizeof(tUSBInterface) + iface->NumEndpoints*sizeof(dev_if->Endpoints[0])); diff --git a/KernelLand/Modules/USB/Core/usb_lowlevel.c b/KernelLand/Modules/USB/Core/usb_lowlevel.c index 1eba637f..23822971 100644 --- a/KernelLand/Modules/USB/Core/usb_lowlevel.c +++ b/KernelLand/Modules/USB/Core/usb_lowlevel.c @@ -26,12 +26,17 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in // TODO: Sanity check (and check that Type is valid) struct sDeviceRequest req; int dest = Addr * 16 + EndPt; // TODO: Validate + + ENTER("pHost xdest iType iReq iVal iIndx iLen pData", + Host, dest, Type, Req, Val, Indx, Len, Data); + req.ReqType = Type; req.Request = Req; req.Value = LittleEndian16( Val ); req.Index = LittleEndian16( Indx ); req.Length = LittleEndian16( Len ); - + + LOG("SETUP"); hdl = Host->HostDef->SendSETUP(Host->Ptr, dest, 0, NULL, NULL, &req, sizeof(req)); // TODO: Data toggle? @@ -40,9 +45,12 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in { void *hdl2; + LOG("IN"); hdl = Host->HostDef->SendIN(Host->Ptr, dest, 0, NULL, NULL, Data, Len); - hdl2 = Host->HostDef->SendOUT(Host->Ptr, dest, 0, NULL, NULL, NULL, 0); + LOG("OUT (Done)"); + hdl2 = Host->HostDef->SendOUT(Host->Ptr, dest, 0, INVLPTR, NULL, NULL, 0); + LOG("Wait..."); while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 ) Time_Delay(1); } @@ -50,16 +58,20 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in { void *hdl2; + LOG("OUT"); if( Len > 0 ) hdl = Host->HostDef->SendOUT(Host->Ptr, dest, 0, NULL, NULL, Data, Len); else hdl = NULL; + LOG("IN (Status)"); // Status phase (DataToggle=1) - hdl2 = Host->HostDef->SendIN(Host->Ptr, dest, 1, NULL, NULL, NULL, 0); + hdl2 = Host->HostDef->SendIN(Host->Ptr, dest, 1, INVLPTR, NULL, NULL, 0); + LOG("Wait..."); while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 ) Time_Delay(1); } + LEAVE('p', hdl); return hdl; } @@ -77,6 +89,9 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i void *final; int dest = Dev->Address*16 + Endpoint; + ENTER("pDev xdest iType iIndex iLength pDest", + Dev, dest, Type, Index, Length, Dest); + req.ReqType = 0x80; req.ReqType |= ((Type >> 8) & 0x3) << 5; // Bits 5/6 req.ReqType |= (Type >> 12) & 3; // Destination (Device, Interface, Endpoint, Other); @@ -85,7 +100,8 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i req.Value = LittleEndian16( ((Type & 0xFF) << 8) | (Index & 0xFF) ); req.Index = LittleEndian16( 0 ); // TODO: Language ID / Interface req.Length = LittleEndian16( Length ); - + + LOG("SETUP"); Dev->Host->HostDef->SendSETUP( Dev->Host->Ptr, dest, 0, NULL, NULL, @@ -95,6 +111,7 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i bToggle = 1; while( Length > ciMaxPacketSize ) { + LOG("IN (%i rem)", Length - ciMaxPacketSize); Dev->Host->HostDef->SendIN( Dev->Host->Ptr, dest, bToggle, NULL, NULL, @@ -104,15 +121,18 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i Length -= ciMaxPacketSize; } + LOG("IN (final)"); final = Dev->Host->HostDef->SendIN( Dev->Host->Ptr, dest, bToggle, INVLPTR, NULL, Dest, Length ); + LOG("Waiting"); while( Dev->Host->HostDef->IsOpComplete(Dev->Host->Ptr, final) == 0 ) - Threads_Yield(); + Threads_Yield(); // BAD BAD BAD + LEAVE('i', 0); return 0; }