X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_lowlevel.c;h=6b38e65e61f24603d851abacfe760ff2c3bb844d;hb=adaa3a0feeecdda90df3e010898a37f1ffa83197;hp=23822971af89b1e5efbb2cb5f095ff83aa3d1303;hpb=06f200335c3bcbd68c6df92589d8b17b73ac3679;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_lowlevel.c b/KernelLand/Modules/USB/Core/usb_lowlevel.c index 23822971..6b38e65e 100644 --- a/KernelLand/Modules/USB/Core/usb_lowlevel.c +++ b/KernelLand/Modules/USB/Core/usb_lowlevel.c @@ -5,15 +5,17 @@ * usb_lowlevel.c * - Low Level IO */ -#define DEBUG 1 +#define DEBUG 0 #include #include "usb.h" #include "usb_proto.h" #include "usb_lowlevel.h" #include +#include // === PROTOTYPES === void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, int Val, int Indx, int Len, void *Data); +void USB_int_WakeThread(void *Thread, void *Data, size_t Length); int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address); int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest); char *USB_int_GetDeviceString(tUSBDevice *Dev, int Endpoint, int Index); @@ -26,6 +28,7 @@ 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 + tThread *thisthread = Proc_GetCurThread(); ENTER("pHost xdest iType iReq iVal iIndx iLen pData", Host, dest, Type, Req, Val, Indx, Len, Data); @@ -36,45 +39,51 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in req.Index = LittleEndian16( Indx ); req.Length = LittleEndian16( Len ); + Threads_ClearEvent(THREAD_EVENT_SHORTWAIT); + LOG("SETUP"); - hdl = Host->HostDef->SendSETUP(Host->Ptr, dest, 0, NULL, NULL, &req, sizeof(req)); + hdl = Host->HostDef->ControlSETUP(Host->Ptr, dest, 0, &req, sizeof(req)); // TODO: Data toggle? // TODO: Multi-packet transfers - if( Type & 0x80 ) + if( Len > 0 ) { - void *hdl2; - - LOG("IN"); - hdl = Host->HostDef->SendIN(Host->Ptr, dest, 0, NULL, NULL, Data, Len); - - 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); + if( Type & 0x80 ) + { + LOG("IN"); + hdl = Host->HostDef->ControlIN(Host->Ptr, dest, 1, NULL, NULL, Data, Len); + + LOG("OUT (Status)"); + hdl = Host->HostDef->ControlOUT(Host->Ptr, dest, 1, USB_int_WakeThread, thisthread, NULL, 0); + } + else + { + LOG("OUT"); + Host->HostDef->ControlOUT(Host->Ptr, dest, 1, NULL, NULL, Data, Len); + + // Status phase (DataToggle=1) + LOG("IN (Status)"); + hdl = Host->HostDef->ControlIN(Host->Ptr, dest, 1, USB_int_WakeThread, thisthread, NULL, 0); + } } else { - void *hdl2; - - LOG("OUT"); - if( Len > 0 ) - hdl = Host->HostDef->SendOUT(Host->Ptr, dest, 0, NULL, NULL, Data, Len); - else - hdl = NULL; - + // Zero length, IN status LOG("IN (Status)"); - // Status phase (DataToggle=1) - 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); + hdl = Host->HostDef->ControlIN(Host->Ptr, dest, 1, USB_int_WakeThread, thisthread, NULL, 0); } + LOG("Wait..."); + Threads_WaitEvents(THREAD_EVENT_SHORTWAIT); + LEAVE('p', hdl); return hdl; } +void USB_int_WakeThread(void *Thread, void *Data, size_t Length) +{ + Threads_PostEvent(Thread, THREAD_EVENT_SHORTWAIT); +} + int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address) { USB_int_Request(Host, 0, 0, 0x00, 5, Address & 0x7F, 0, 0, NULL); @@ -102,17 +111,13 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i req.Length = LittleEndian16( Length ); LOG("SETUP"); - Dev->Host->HostDef->SendSETUP( - Dev->Host->Ptr, dest, - 0, NULL, NULL, - &req, sizeof(req) - ); + Dev->Host->HostDef->ControlSETUP(Dev->Host->Ptr, dest, 0, &req, sizeof(req)); bToggle = 1; while( Length > ciMaxPacketSize ) { LOG("IN (%i rem)", Length - ciMaxPacketSize); - Dev->Host->HostDef->SendIN( + Dev->Host->HostDef->ControlIN( Dev->Host->Ptr, dest, bToggle, NULL, NULL, Dest, ciMaxPacketSize @@ -122,15 +127,18 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i } LOG("IN (final)"); - final = Dev->Host->HostDef->SendIN( - Dev->Host->Ptr, dest, - bToggle, INVLPTR, NULL, - Dest, Length + Dev->Host->HostDef->ControlIN( Dev->Host->Ptr, dest, bToggle, NULL, NULL, Dest, Length ); + + Threads_ClearEvent(THREAD_EVENT_SHORTWAIT); + LOG("OUT (Status)"); + final = Dev->Host->HostDef->ControlOUT( + Dev->Host->Ptr, dest, 1, + USB_int_WakeThread, Proc_GetCurThread(), + NULL, 0 ); LOG("Waiting"); - while( Dev->Host->HostDef->IsOpComplete(Dev->Host->Ptr, final) == 0 ) - Threads_Yield(); // BAD BAD BAD + Threads_WaitEvents(THREAD_EVENT_SHORTWAIT); LEAVE('i', 0); return 0; @@ -144,7 +152,9 @@ char *USB_int_GetDeviceString(tUSBDevice *Dev, int Endpoint, int Index) if(Index == 0) return strdup(""); + str.Length = 0; USB_int_ReadDescriptor(Dev, Endpoint, 3, Index, sizeof(str), &str); + if(str.Length == 0) return NULL; if(str.Length < 2) { Log_Error("USB", "String %p:%i:%i:%i descriptor is undersized (%i)", Dev->Host, Dev->Address, Endpoint, Index, str.Length);