Modules/USB - Documention/Debugging, and fixed an API use
authorJohn Hodge <[email protected]>
Thu, 23 Feb 2012 16:03:59 +0000 (00:03 +0800)
committerJohn Hodge <[email protected]>
Thu, 23 Feb 2012 16:03:59 +0000 (00:03 +0800)
KernelLand/Modules/USB/Core/include/usb_host.h
KernelLand/Modules/USB/Core/usb_devinit.c
KernelLand/Modules/USB/Core/usb_lowlevel.c

index e2748da..eda42cf 100644 (file)
@@ -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);
index 4b18b30..06efd21 100644 (file)
@@ -5,7 +5,7 @@
  * usb_devinit.c
  * - USB Device Initialisation
  */
-#define DEBUG  0
+#define DEBUG  1
 
 #include <acess.h>
 #include <vfs.h>
@@ -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]));
index 1eba637..2382297 100644 (file)
@@ -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;
 }
 

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