Interrupt-driven devices

While my laptop’s off at the doctors getting an operation to save its life, my hands are tied development-wise. So while I can’t work on MyUSB, I thought I’d at least answer a reasonably common question about MyUSB.

To retain some familiarity to those coming from Atmel’s honking-great big USB library, MyUSB is built using a very similar structure (but no code was re-used, no plagiarism accusations please). This means that when in device mode, the control requests made by the host to endpoint 0 of the device are polled, rather than interrupt driven. I made this choice for two reasons: one being to remain compatible with the behavior of Atmel’s library, and two because it is likely that having the lengthy processing interrupt driven will more than likely be detrimental to the end user, unless they are aware of it and specifically code around it.

However, that does not mean that MyUSB cannot be used in interrupt driven device (only, for now) mode. By the use of the following method, it should be possible to change over the library to interrupt driven control requests, with no changes to the library itself:

1) Don’t call the USB_USBTask task

2) Hook the USB_Reset event in your code. Inside the event, add the code:

UEIENX |= (1 << RXSTPE);

which will enable the control received interrupt for the control endpoint.

3) Add the endpoint interrupt handler to your program:

ISR(ENDPOINT_PIPE_vect)
{
   if (Endpoint_HasEndpointInterrupted(
    ENDPOINT_CONTROLEP))
   {
      Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);

      if (UEINTX & (1 << RXSTPI))
         USB_Device_ProcessControlPacket();

      UEINTX = 0;
   }

 

   // Other endpoint interrupt code here

}

 

 

Those three steps combined should change the interrupt processing over to fully interrupt driven. Other endpoints can also be interrupt driven (and processed in the same ISR) — see the documentation and example projects.

 

Comments: 1

Leave a reply »

 
 
 

This feature isn’t in LUFA anymore.

 

Leave a Reply

 
(will not be published)
 
 
Comment
 
 

 

Vital Stats

  • 35 Years Old
  • Australian
  • Lover of embedded systems
  • Firmware engineer
  • Self-Proclaimed Geek

Latest Blog Posts

RSS