Kernel/USB - Still broken, reworking host controller API to give driver more information
[tpg/acess2.git] / KernelLand / Modules / USB / Core / usb_poll.c
index 6285a11..d1cbaa9 100644 (file)
@@ -21,10 +21,15 @@ extern tUSBHost     *gUSB_Hosts;
 void   USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint);
 
 // === GLOBALS ===
-tUSBEndpoint   *gUSB_PollQueues[POLL_MAX/POLL_ATOM];
- int   giUSB_PollPosition;     // Index into gUSB_PollQueues
 
 // === CODE ===
+void USB_int_PollCallback(void *Ptr, void *Data, size_t Length)
+{
+       tUSBEndpoint    *ep = Ptr;
+       
+       ep->Interface->Driver->Endpoints[ep->EndpointIdx].DataAvail(ep->Interface, ep->EndpointIdx, Length, Data);
+}
+
 void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint)
 {
        tUSBEndpoint    *endpt;
@@ -44,18 +49,14 @@ void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint)
 
        endpt->InputData = malloc(endpt->MaxPacketSize);
 
-       // Determine polling period in atoms
-       endpt->PollingAtoms = (endpt->PollingPeriod + POLL_ATOM-1) / POLL_ATOM;
-       if(endpt->PollingAtoms > POLL_SLOTS)    endpt->PollingAtoms = POLL_SLOTS;
-       LOG("endpt(%p)->PollingAtoms = %i", endpt, endpt->PollingAtoms);
-       // Add to poll queue
-       // TODO: Locking
-       {
-                int    idx = giUSB_PollPosition + 1;
-               if(idx >= POLL_SLOTS)   idx -= POLL_SLOTS;
-               endpt->Next = gUSB_PollQueues[idx];
-               gUSB_PollQueues[idx] = endpt;
-       }
+       Iface->Dev->Host->HostDef->InterruptIN(
+               Iface->Dev->Host->Ptr,
+               Iface->Dev->Address * 16 + endpt->EndpointNum,
+               endpt->PollingPeriod,
+               USB_int_PollCallback, endpt,
+               endpt->InputData, endpt->MaxPacketSize
+               );
+       LEAVE('-');
 }
 
 /**
@@ -66,74 +67,12 @@ int USB_PollThread(void *unused)
        Threads_SetName("USB Polling Thread");
        for(;;)
        {
-               tUSBEndpoint    *ep, *prev;
-
-               if(giUSB_PollPosition == 0)
+               // Check hosts
+               for( tUSBHost *host = gUSB_Hosts; host; host = host->Next )
                {
-                       // Check hosts
-                       for( tUSBHost *host = gUSB_Hosts; host; host = host->Next )
-                       {
-                               host->HostDef->CheckPorts(host->Ptr);
-                       }
+                       host->HostDef->CheckPorts(host->Ptr);
                }
 
-//             Log_Debug("USBPoll", "giUSB_PollPosition = %i", giUSB_PollPosition);
-
-               // A little evil for neater code
-               prev = (void*)( (tVAddr)&gUSB_PollQueues[giUSB_PollPosition] - offsetof(tUSBEndpoint, Next) );
-
-               // Process queue
-//             LOG("giUSB_PollPosition = %i", giUSB_PollPosition);
-               for( ep = gUSB_PollQueues[giUSB_PollPosition]; ep; prev = ep, ep = ep->Next )
-               {
-                        int    period_in_atoms = ep->PollingAtoms;
-                       LOG("%i: ep = %p", giUSB_PollPosition, ep);
-
-                       // Check for invalid entries
-                       if(period_in_atoms < 0 || period_in_atoms > POLL_ATOM)
-                       {
-                               Log_Warning("USB", "Endpoint on polling queue with invalid period");
-                               continue ;
-                       }
-                       // Check for entries to delete
-                       if(period_in_atoms == 0)
-                       {
-                               // Remove
-                               prev->Next = ep->Next;
-                               ep->PollingAtoms = -1;  // Mark as removed
-                               ep = prev;      // Make sure prev is kept valid
-                               continue ;
-                       }
-
-                       // Read data
-                       // TODO: Check the endpoint
-                       // TODO: Async checking?
-                       // - Send the read request on all of them then wait for the first to complete
-                       USB_RecvDataA(
-                               ep->Interface, ep->EndpointIdx+1,
-                               ep->MaxPacketSize, ep->InputData,
-                               ep->Interface->Driver->Endpoints[ep->EndpointIdx].DataAvail
-                               );
-                               
-                       // Call callback
-
-                       // Reschedule
-                       if( period_in_atoms != POLL_SLOTS )
-                       {
-                                int    newqueue_id = (giUSB_PollPosition + period_in_atoms) % POLL_SLOTS;
-                               tUSBEndpoint    **newqueue = &gUSB_PollQueues[newqueue_id];
-                               
-                               prev->Next = ep->Next;
-                               
-                               ep->Next = *newqueue;
-                               *newqueue = ep;
-                               ep = prev;
-                       }
-               }
-               giUSB_PollPosition ++;
-               if(giUSB_PollPosition == POLL_SLOTS)
-                       giUSB_PollPosition = 0;
-               // TODO: Check for a longer delay
                Time_Delay(POLL_ATOM);
        }
 }

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