| uint32_t stat = USBHS_USBSTS; | uint32_t stat = USBHS_USBSTS; | ||||
| USBHS_USBSTS = stat; // clear pending interrupts | USBHS_USBSTS = stat; // clear pending interrupts | ||||
| //stat &= USBHS_USBINTR; // mask away unwanted interrupts | //stat &= USBHS_USBINTR; // mask away unwanted interrupts | ||||
| #if 1 | |||||
| println(); | println(); | ||||
| println("ISR: ", stat, HEX); | println("ISR: ", stat, HEX); | ||||
| //if (stat & USBHS_USBSTS_UI) println(" USB Interrupt"); | //if (stat & USBHS_USBSTS_UI) println(" USB Interrupt"); | ||||
| if (stat & USBHS_USBSTS_UPI) println(" USB Periodic"); | if (stat & USBHS_USBSTS_UPI) println(" USB Periodic"); | ||||
| if (stat & USBHS_USBSTS_TI0) println(" Timer0"); | if (stat & USBHS_USBSTS_TI0) println(" Timer0"); | ||||
| if (stat & USBHS_USBSTS_TI1) println(" Timer1"); | if (stat & USBHS_USBSTS_TI1) println(" Timer1"); | ||||
| #endif | |||||
| if (stat & USBHS_USBSTS_UAI) { // completed qTD(s) from the async schedule | if (stat & USBHS_USBSTS_UAI) { // completed qTD(s) from the async schedule | ||||
| println("Async Followup"); | println("Async Followup"); | ||||
| } | } | ||||
| } | } | ||||
| if (stat & USBHS_USBSTS_TI0) { // timer 0 - used for built-in port events | if (stat & USBHS_USBSTS_TI0) { // timer 0 - used for built-in port events | ||||
| println("timer0"); | |||||
| //println("timer0"); | |||||
| if (port_state == PORT_STATE_DEBOUNCE) { | if (port_state == PORT_STATE_DEBOUNCE) { | ||||
| port_state = PORT_STATE_RESET; | port_state = PORT_STATE_RESET; | ||||
| USBHS_PORTSC1 |= USBHS_PORTSC_PR; // begin reset sequence | USBHS_PORTSC1 |= USBHS_PORTSC_PR; // begin reset sequence | ||||
| } | } | ||||
| } | } | ||||
| if (stat & USBHS_USBSTS_TI1) { // timer 1 - used for USBDriverTimer | if (stat & USBHS_USBSTS_TI1) { // timer 1 - used for USBDriverTimer | ||||
| println("timer1"); | |||||
| //println("timer1"); | |||||
| USBDriverTimer *timer = active_timers; | USBDriverTimer *timer = active_timers; | ||||
| if (timer) { | if (timer) { | ||||
| USBDriverTimer *next = timer->next; | USBDriverTimer *next = timer->next; | ||||
| return; | return; | ||||
| } | } | ||||
| uint32_t remain = USBHS_GPTIMER1CTL & 0xFFFFFF; | uint32_t remain = USBHS_GPTIMER1CTL & 0xFFFFFF; | ||||
| Serial.print("remain = "); | |||||
| Serial.println(remain); | |||||
| //Serial.print("remain = "); | |||||
| //Serial.println(remain); | |||||
| if (microseconds < remain) { | if (microseconds < remain) { | ||||
| // this timer event is before any on the schedule | // this timer event is before any on the schedule | ||||
| __disable_irq(); | __disable_irq(); | ||||
| maxlen = (maxlen * 76459) >> 16; // worst case bit stuffing | maxlen = (maxlen * 76459) >> 16; // worst case bit stuffing | ||||
| if (pipe->device->speed == 2) { | if (pipe->device->speed == 2) { | ||||
| // high speed 480 Mbit/sec | // high speed 480 Mbit/sec | ||||
| println(" ep interval = ", interval); | |||||
| if (interval > 15) interval = 15; | if (interval > 15) interval = 15; | ||||
| interval = 1 << (interval - 1); | interval = 1 << (interval - 1); | ||||
| if (interval > PERIODIC_LIST_SIZE*8) interval = PERIODIC_LIST_SIZE*8; | if (interval > PERIODIC_LIST_SIZE*8) interval = PERIODIC_LIST_SIZE*8; | ||||
| println(" interval = ", interval); | |||||
| uint32_t pinterval = interval >> 3; | |||||
| pipe->periodic_interval = (pinterval > 0) ? pinterval : 1; | |||||
| uint32_t stime = (55 + 32 + maxlen) >> 5; // time units: 32 bytes or 533 ns | uint32_t stime = (55 + 32 + maxlen) >> 5; // time units: 32 bytes or 533 ns | ||||
| uint32_t best_offset = 0xFFFFFFFF; | uint32_t best_offset = 0xFFFFFFFF; | ||||
| uint32_t best_bandwidth = 0xFFFFFFFF; | uint32_t best_bandwidth = 0xFFFFFFFF; | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| #if 0 | |||||
| #if 1 | |||||
| println("Periodic Schedule:"); | println("Periodic Schedule:"); | ||||
| for (uint32_t i=0; i < PERIODIC_LIST_SIZE; i++) { | for (uint32_t i=0; i < PERIODIC_LIST_SIZE; i++) { | ||||
| if (i < 10) print(" "); | if (i < 10) print(" "); |