1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-05 07:03:07 +02:00

atusb/fw/: changed USB stack to use interrupts instead of polling

Note: this change surprisingly _increases_ the DFU wait in the boot
loader. Not yet sure why.

- boot.c (main): move the interrupt vectors to the boot loader
  section
- atusb.c (main): move the interrupt vectors to the application
  section
- boot.c (main): enable global interrupts while looping (disable
  them before jumping to the application)
- board_app.c (__timer_read, timer_read): removed wrapped since
  we're now always called with interrupts disabled
- usb/atu2.c (ep_init): enable endpoint interrupts
- usb/atu2.c (usb_init): enable device interrupts
- usb/atu2.c (usb_poll, USB_GEN_vect, USB_COM_vect): moved poll
  loop code into separate handlers for device and endpoint
  interrupts
- boot.c (main), atusb.c (main): removed call to usb_poll
This commit is contained in:
Werner Almesberger 2011-06-11 11:06:18 -03:00
parent f9681e5b4f
commit d03beb2257
5 changed files with 30 additions and 20 deletions

View File

@ -37,8 +37,11 @@ int main(void)
ep0_init();
timer_init();
/* move interrupt vectors to 0 */
MCUCR = 1 << IVCE;
MCUCR = 0;
sei();
while (1)
usb_poll();
while (1);
}

View File

@ -51,7 +51,7 @@ ISR(TIMER1_OVF_vect)
}
static uint64_t __timer_read(void)
uint64_t timer_read(void)
{
uint32_t high;
uint8_t low, mid;
@ -75,17 +75,6 @@ static uint64_t __timer_read(void)
}
uint64_t timer_read(void)
{
uint64_t res;
cli();
res = __timer_read();
sei();
return res;
}
void timer_init(void)
{
/* configure timer 1 as a free-running CLK counter */

View File

@ -14,6 +14,7 @@
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define F_CPU 8000000UL
@ -50,10 +51,15 @@ int main(void)
usb_init();
dfu_init();
/* move interrupt vectors to the boot loader */
MCUCR = 1 << IVCE;
MCUCR = 1 << IVSEL;
sei();
led(1);
while (loop != MS_TO_LOOPS(2000)) {
usb_poll();
if (dfu.state == dfuIDLE && pgm_read_byte(zero) != 0xff)
loop++;
else
@ -62,6 +68,8 @@ int main(void)
led(0);
cli();
usb_reset();
run_payload();

View File

@ -24,6 +24,7 @@
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "usb.h"
#include "../board.h"
@ -177,14 +178,17 @@ static void ep_init(void)
while (!(UESTA0X & (1 << CFGOK)));
UEIENX =
(1 << RXSTPE) | (1 << RXOUTE) | (1 << STALLEDE) | (1 << TXINE);
eps[0].state = EP_IDLE;
eps[0].size = 64;
}
void usb_poll(void)
ISR(USB_GEN_vect)
{
uint8_t flags, i;
uint8_t flags;
flags = UDINT;
if (flags & (1 << EORSTI)) {
@ -193,11 +197,17 @@ void usb_poll(void)
ep_init();
UDINT = ~(1 << EORSTI);
}
}
ISR(USB_COM_vect)
{
uint8_t flags, i;
flags = UEINT;
for (i = 0; i != NUM_EPS; i++)
if (1 || flags & (1 << i))
if (flags & (1 << i))
handle_ep(i);
/* @@@ USB bus reset */
}
@ -223,6 +233,7 @@ void usb_init(void)
USBCON &= ~(1 << FRZCLK); /* thaw the clock */
UDCON &= ~(1 << DETACH); /* attach the pull-up */
UDIEN = 1 << EORSTE; /* enable device interrupts */
// UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */
ep_init();

View File

@ -152,6 +152,5 @@ int handle_setup(const struct setup_request *setup);
int set_addr(uint8_t addr);
void usb_reset(void);
void usb_init(void);
void usb_poll(void);
#endif /* !USB_H */