Contiki 2.5
usb-interrupt.c
1 #include <AT91SAM7S64.h>
2 #include <interrupt-utils.h>
3 #include <usb-interrupt.h>
4 #include <usb-api.h>
5 #include <stdio.h>
6 
7 static void
8 usb_int_safe (void) __attribute__((noinline));
9 
10 static void
11 usb_int_safe (void)
12 {
13  unsigned int int_status;
14  /* putchar('*'); */
15  int_status = *AT91C_UDP_ISR & *AT91C_UDP_IMR;
16 
17  if (int_status & (AT91C_UDP_EP0 | AT91C_UDP_EP1 | AT91C_UDP_EP2
18  | AT91C_UDP_EP3)) {
19  unsigned int ep_index;
20  /* Handle enabled interrupts */
21  for (ep_index = 0; ep_index < 4; ep_index++) {
22  if (int_status & (1<<ep_index)) {
23  usb_arch_transfer_complete(ep_index);
24  }
25  }
26  } else if (int_status & AT91C_UDP_ENDBUSRES) {
27  *AT91C_UDP_ICR = AT91C_UDP_ENDBUSRES;
28  usb_arch_reset_int();
29  } else if (int_status & AT91C_UDP_RXSUSP) {
30  /* puts("Suspend"); */
31  *AT91C_UDP_ICR = AT91C_UDP_RXSUSP;
32  usb_arch_suspend_int();
33  } else if (int_status & AT91C_UDP_RXRSM) {
34  /* puts("Resume"); */
35  *AT91C_UDP_ICR = AT91C_UDP_RXRSM;
36  usb_arch_resume_int();
37  } else if (int_status & AT91C_UDP_SOFINT) {
38  /* puts("SOF"); */
39  *AT91C_UDP_ICR = AT91C_UDP_SOFINT;
40  } else if (int_status & AT91C_UDP_WAKEUP) {
41  /* puts("Wakeup"); */
42  *AT91C_UDP_ICR = AT91C_UDP_WAKEUP;
43  } else {
44  puts("Other USB interrupt");
45  }
46  /* dbg_putchar('<'); */
47 
48 }
49 
50 void NACKEDFUNC
51 usb_int (void)
52 {
53  ISR_STORE();
54  ISR_ENABLE_NEST();
55  usb_int_safe();
56  ISR_DISABLE_NEST();
57  *AT91C_AIC_EOICR = 0;
58  ISR_RESTORE();
59 }