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);
};
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);
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;
}
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);
* \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;
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");
}
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);
}