git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Modules/USB - A little work on HID code
[tpg/acess2.git]
/
Modules
/
USB
/
Core
/
usb_poll.c
diff --git
a/Modules/USB/Core/usb_poll.c
b/Modules/USB/Core/usb_poll.c
index
a4e8d44
..
ec03036
100644
(file)
--- a/
Modules/USB/Core/usb_poll.c
+++ b/
Modules/USB/Core/usb_poll.c
@@
-13,6
+13,9
@@
#define POLL_MAX 256 // Max period that can be nominated
#define POLL_SLOTS ((int)(POLL_MAX/POLL_ATOM))
#define POLL_MAX 256 // Max period that can be nominated
#define POLL_SLOTS ((int)(POLL_MAX/POLL_ATOM))
+// === IMPORTS ===
+extern tUSBHost *gUSB_Hosts;
+
// === PROTOTYPES ===
void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint);
// === PROTOTYPES ===
void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint);
@@
-26,19
+29,26
@@
void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint)
tUSBEndpoint *endpt;
// Some sanity checks
tUSBEndpoint *endpt;
// Some sanity checks
- if(Endpoint <= 0 || Endpoint >
= Iface->nEndpoints)
return ;
+ if(Endpoint <= 0 || Endpoint >
Iface->nEndpoints)
return ;
endpt = &Iface->Endpoints[Endpoint-1];
if(endpt->PollingPeriod > POLL_MAX || endpt->PollingPeriod <= 0)
return ;
// TODO: Check that this endpoint isn't already on the queue
endpt = &Iface->Endpoints[Endpoint-1];
if(endpt->PollingPeriod > POLL_MAX || endpt->PollingPeriod <= 0)
return ;
// TODO: Check that this endpoint isn't already on the queue
+ 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;
// Add to poll queue
// Determine polling period in atoms
endpt->PollingAtoms = (endpt->PollingPeriod + POLL_ATOM-1) / POLL_ATOM;
if(endpt->PollingAtoms > POLL_SLOTS) endpt->PollingAtoms = POLL_SLOTS;
// Add to poll queue
- endpt->Next = gUSB_PollQueues[endpt->PollingAtoms];
- gUSB_PollQueues[endpt->PollingAtoms] = endpt;
+ // TODO: Locking
+ {
+ int idx = giUSB_PollPosition + 1;
+ if(idx >= POLL_SLOTS) idx -= POLL_SLOTS;
+ endpt->Next = gUSB_PollQueues[idx];
+ gUSB_PollQueues[idx] = endpt;
+ }
}
/**
}
/**
@@
-46,17
+56,29
@@
void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint)
*/
int USB_PollThread(void *unused)
{
*/
int USB_PollThread(void *unused)
{
+ Threads_SetName("USB Polling Thread");
for(;;)
{
tUSBEndpoint *ep, *prev;
for(;;)
{
tUSBEndpoint *ep, *prev;
+ if(giUSB_PollPosition == 0)
+ {
+ // Check hosts
+ for( tUSBHost *host = gUSB_Hosts; host; host = host->Next )
+ {
+ host->HostDef->CheckPorts(host->Ptr);
+ }
+ }
+
// A little evil for neater code
prev = (void*)( (tVAddr)&gUSB_PollQueues[giUSB_PollPosition] - offsetof(tUSBEndpoint, Next) );
// Process queue
// 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;
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)
// Check for invalid entries
if(period_in_atoms < 0 || period_in_atoms > POLL_ATOM)
@@
-78,6
+100,12
@@
int USB_PollThread(void *unused)
// TODO: Check the endpoint
// TODO: Async checking?
// - Send the read request on all of them then wait for the first to complete
// 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
// Call callback
// Reschedule
@@
-90,6
+118,7
@@
int USB_PollThread(void *unused)
ep->Next = *newqueue;
*newqueue = ep;
ep->Next = *newqueue;
*newqueue = ep;
+ ep = prev;
}
}
giUSB_PollPosition ++;
}
}
giUSB_PollPosition ++;
UCC
git Repository :: git.ucc.asn.au