X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FUSB%2FCore%2Fusb.c;h=b3195804c129892969048d4ea29e7c87e1ce11f2;hb=4c717bb526a0a7b1aa44ed7fc4f07a6b7da5d2f9;hp=0b4bc638f3e4c7f939c6d33aff4f799b31d81cf9;hpb=662713ac7494f05339cee056a3d9f72e2357c492;p=tpg%2Facess2.git diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c index 0b4bc638..b3195804 100644 --- a/Modules/USB/Core/usb.c +++ b/Modules/USB/Core/usb.c @@ -1,27 +1,27 @@ /* - * Acess 2 USB Stack - * USB Packet Control + * Acess2 USB Stack + * - By John Hodge (thePowersGang) + * + * usb.c + * - USB Structure */ #define DEBUG 1 #include #include #include #include "usb.h" -#include "usb_proto.h" // === IMPORTS === extern tUSBHost *gUSB_Hosts; +extern tUSBDriver gUSBHub_Driver; // === STRUCTURES === // === PROTOTYPES === tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts); -void USB_DeviceConnected(tUSBHub *Hub, int Port); -void USB_DeviceDisconnected(tUSBHub *Hub, int Port); -void *USB_GetDeviceDataPtr(tUSBDevice *Dev); -void USB_SetDeviceDataPtr(tUSBDevice *Dev, void *Ptr); - int USB_int_AllocateAddress(tUSBHost *Host); - int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address); + +// === GLOBALS === +tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver; // === CODE === tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) @@ -37,15 +37,17 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) host->Ptr = ControllerPtr; memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap)); - host->RootHubDev.Next = NULL; host->RootHubDev.ParentHub = NULL; host->RootHubDev.Host = host; host->RootHubDev.Address = 0; - host->RootHubDev.Driver = NULL; - host->RootHubDev.Data = NULL; - host->RootHub.Device = NULL; - host->RootHub.CheckPorts = NULL; +// host->RootHubIf.Next = NULL; + host->RootHubIf.Dev = &host->RootHubDev; + host->RootHubIf.Driver = NULL; + host->RootHubIf.Data = NULL; + host->RootHubIf.nEndpoints = 0; + + host->RootHub.Interface = &host->RootHubIf; host->RootHub.nPorts = nPorts; memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts); @@ -53,108 +55,54 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) host->Next = gUSB_Hosts; gUSB_Hosts = host; - // Initialise? - HostDef->CheckPorts(ControllerPtr); - return &host->RootHub; } -void USB_DeviceConnected(tUSBHub *Hub, int Port) -{ - tUSBDevice *dev; - if( Port >= Hub->nPorts ) return ; - if( Hub->Devices[Port] ) return ; - - ENTER("pHub iPort", Hub, Port); - - // 0. Perform port init? (done in hub?) - - // Create structure - dev = malloc(sizeof(tUSBDevice)); - dev->Next = NULL; - dev->ParentHub = Hub; - dev->Host = Hub->Device->Host; - dev->Address = 0; - dev->Driver = 0; - dev->Data = 0; - - // 1. Assign an address - dev->Address = USB_int_AllocateAddress(dev->Host); - if(dev->Address == 0) { - Log_Error("USB", "No addresses avaliable on host %p", dev->Host); - free(dev); - LEAVE('-'); - return ; - } - USB_int_SendSetupSetAddress(dev->Host, dev->Address); - LOG("Assigned address %i", dev->Address); - - // 2. Get device information - - // Done. - LEAVE('-'); -} - -void USB_DeviceDisconnected(tUSBHub *Hub, int Port) +// --- Drivers --- +void USB_RegisterDriver(tUSBDriver *Driver) { - + Log_Warning("USB", "TODO: Implement USB_RegisterDriver"); } -void *USB_GetDeviceDataPtr(tUSBDevice *Dev) { return Dev->Data; } -void USB_SetDeviceDataPtr(tUSBDevice *Dev, void *Ptr) { Dev->Data = Ptr; } - -int USB_int_AllocateAddress(tUSBHost *Host) +tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode) { - int i; - for( i = 1; i < 128; i ++ ) + ENTER("xClassCode", ClassCode); + for( tUSBDriver *ret = gpUSB_InterfaceDrivers; ret; ret = ret->Next ) { - if(Host->AddressBitmap[i/8] & (1 << i)) - continue ; - return i; + LOG(" 0x%x & 0x%x == 0x%x?", ClassCode, ret->Match.Class.ClassMask, ret->Match.Class.ClassCode); + if( (ClassCode & ret->Match.Class.ClassMask) == ret->Match.Class.ClassCode ) + { + LOG("Found '%s'", ret->Name); + LEAVE('p', ret); + return ret; + } } - return 0; + LEAVE('n'); + return NULL; } -int USB_int_SendSetupSetAddress(tUSBHost *Host, int Address) +// --- Hub Registration --- +// NOTE: Doesn't do much nowdays +tUSBHub *USB_RegisterHub(tUSBInterface *Device, int PortCount) { - struct sDeviceRequest req; - req.ReqType = 0; // bmRequestType - req.Request = 5; // SET_ADDRESS - req.Value = Address & 0x7F; // wValue - req.Index = 0; // wIndex - req.Length = 0; // wLength + tUSBHub *ret; - // Addr 0:0, Data Toggle = 0, no interrupt - return Host->HostDef->SendSETUP(Host->Ptr, 0, 0, 0, FALSE, &req, sizeof(req)) == NULL; + ret = malloc(sizeof(tUSBHub) + sizeof(ret->Devices[0])*PortCount); + ret->Interface = Device; + ret->nPorts = PortCount; + memset(ret->Devices, 0, sizeof(ret->Devices[0])*PortCount); + return ret; } -int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, int Length, void *Dest) +void USB_RemoveHub(tUSBHub *Hub) { - struct sDeviceRequest req; - const int ciMaxPacketSize = 0x400; - req.ReqType = 0x80; - req.Request = 6; // GET_DESCRIPTOR - req.Value = ((Type & 0xFF) << 8) | (Index & 0xFF); - req.Index = 0; // TODO: Language ID - req.Length = Length; - - Dev->Host->HostDef->SendSETUP( - Dev->Host->Ptr, Dev->Address, Endpoint, - 0, FALSE, - &req, sizeof(req) - ); - - while( Length > ciMaxPacketSize ) + for( int i = 0; i < Hub->nPorts; i ++ ) { - Dev->Host->HostDef->SendIN( - Dev->Host->Ptr, Dev->Address, Endpoint, - 1, FALSE, - Dest, ciMaxPacketSize - ); - Length -= ciMaxPacketSize; + if( Hub->Devices[i] ) + { + USB_DeviceDisconnected( Hub, i ); + } } - - // TODO: Complete and get completion - - return 0; + free(Hub); } +