-// 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);