From: John Hodge Date: Fri, 25 Nov 2011 10:19:11 +0000 (+0800) Subject: Modules/USB - Working on UHCI callbacks X-Git-Tag: rel0.14~70 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=cbf85c64a5745b1f08f5c0a5ebda5d9a8d726871;p=tpg%2Facess2.git Modules/USB - Working on UHCI callbacks --- diff --git a/Modules/USB/Core/include/usb_host.h b/Modules/USB/Core/include/usb_host.h index 7dc79243..4efe0f7a 100644 --- a/Modules/USB/Core/include/usb_host.h +++ b/Modules/USB/Core/include/usb_host.h @@ -13,15 +13,21 @@ typedef struct sUSBHostDef tUSBHostDef; +typedef void (*tUSBHostCb)(void *DataPtr); + +typedef void *(*tUSBHostOp)(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb bIOC, void *Data, size_t Length); + /** * \brief Defines a USB Host Controller type */ struct sUSBHostDef { - void *(*SendIN)(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); - void *(*SendOUT)(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); - void *(*SendSETUP)(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); - + tUSBHostOp SendIN; + tUSBHostOp SendOUT; + tUSBHostOp SendSETUP; + + int (*IsOpComplete)(void *Ptr, void *OpPtr); + void (*CheckPorts)(void *Ptr); }; diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c index 0b4bc638..272ff6c8 100644 --- a/Modules/USB/Core/usb.c +++ b/Modules/USB/Core/usb.c @@ -130,8 +130,11 @@ int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address) int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest) { - struct sDeviceRequest req; const int ciMaxPacketSize = 0x400; + struct sDeviceRequest req; + int bToggle = 0; + void *final; + req.ReqType = 0x80; req.Request = 6; // GET_DESCRIPTOR req.Value = ((Type & 0xFF) << 8) | (Index & 0xFF); @@ -140,21 +143,30 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i Dev->Host->HostDef->SendSETUP( Dev->Host->Ptr, Dev->Address, Endpoint, - 0, FALSE, + 0, NULL, &req, sizeof(req) ); + bToggle = 1; while( Length > ciMaxPacketSize ) { Dev->Host->HostDef->SendIN( Dev->Host->Ptr, Dev->Address, Endpoint, - 1, FALSE, + bToggle, NULL, Dest, ciMaxPacketSize ); + bToggle = !bToggle; Length -= ciMaxPacketSize; } - // TODO: Complete and get completion + final = Dev->Host->HostDef->SendIN( + Dev->Host->Ptr, Dev->Address, Endpoint, + bToggle, INVLPTR, + Dest, Length + ); + + while( Dev->Host->HostDef->IsOpComplete(Dev->Host->Ptr, final) == 0 ) + Time_Delay(1); return 0; } diff --git a/Modules/USB/UHCI/uhci.c b/Modules/USB/UHCI/uhci.c index 0f725230..83059ad2 100644 --- a/Modules/USB/UHCI/uhci.c +++ b/Modules/USB/UHCI/uhci.c @@ -20,10 +20,10 @@ void UHCI_Cleanup(); tUHCI_TD *UHCI_int_AllocateTD(tUHCI_Controller *Cont); void UHCI_int_AppendTD(tUHCI_Controller *Cont, tUHCI_TD *TD); -void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int bTgl, int bIOC, void *Data, size_t Length); -void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); -void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); -void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length); +void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int bTgl, tUSBHostCb Cb, void *Data, size_t Length); +void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length); +void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length); +void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length); void UHCI_Hub_Poll(tUSBHub *Hub, tUSBDevice *Dev); int UHCI_Int_InitHost(tUHCI_Controller *Host); void UHCI_CheckPortUpdate(tUHCI_Controller *Host); @@ -122,7 +122,7 @@ void UHCI_int_AppendTD(tUHCI_Controller *Cont, tUHCI_TD *TD) * \param Addr Function Address * 16 + Endpoint * \param bTgl Data toggle value */ -void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int bTgl, int bIOC, void *Data, size_t Length) +void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int bTgl, tUSBHostCb Cb, void *Data, size_t Length) { tUHCI_TD *td; @@ -149,8 +149,13 @@ void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int td->BufferPointer = MM_GetPhysAddr( (tVAddr)Data ); } - if( bIOC ) { + // Interrupt on completion + if( Cb ) { td->Control |= (1 << 24); + td->Avaliable[0] = (tVAddr)Cb; // NOTE: if ERRPTR then the TD is kept allocated until checked + #if BITS > 32 + td->Avaliable[1] = (tVAddr)Cb >> 32; + #endif Log_Warning("UHCI", "TODO: Support IOC... somehow"); } @@ -159,24 +164,24 @@ void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int return td; } -void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length) +void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x69, DataTgl, bIOC, Data, Length); + return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x69, DataTgl, Cb, Data, Length); } -void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length) +void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0xE1, DataTgl, bIOC, Data, Length); + return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0xE1, DataTgl, Cb, Data, Length); } -void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, int bIOC, void *Data, size_t Length) +void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *Data, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x2D, DataTgl, bIOC, Data, Length); + return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x2D, DataTgl, Cb, Data, Length); } void UHCI_Hub_Poll(tUSBHub *Hub, tUSBDevice *Dev) { - tUHCI_Controller *cont = USB_GetDeviceDataPtr(Dev); + tUHCI_Controller *cont = USB_GetDeviceDataPtr(Dev); UHCI_CheckPortUpdate(cont); }