// NVIC - Default ISR void fault_isr() { while ( 1 ) { // keep polling some communication while in fault // mode, so we don't completely die. if ( SIM_SCGC4 & SIM_SCGC4_USBOTG ) usb_isr(); if ( SIM_SCGC4 & SIM_SCGC4_UART0 ) uart0_status_isr(); if ( SIM_SCGC4 & SIM_SCGC4_UART1 ) uart1_status_isr(); if ( SIM_SCGC4 & SIM_SCGC4_UART2 ) uart2_status_isr(); } }
void isr(void) { unsigned int irqs; irqs = irq_pending() & irq_getmask(); if(irqs & IRQ_UART) uart_isr(); #ifdef FIXME if(irqs & IRQ_TMU) tmu_isr(); if(irqs & IRQ_USB) usb_isr(); #endif }
// see usb_hw_layer.h for documentation void usb_task(void) { #if defined(USB_ISR_POLLING) if (interrupt_active(INT_USB)) { usb_isr(); } #endif if (usb_attached()) { if (UCON_USBEN==0) { debug_usb(debug_putc, "\r\n\nUSB TASK: ATTACH"); usb_attach(); } } else { if (UCON_USBEN==1) { debug_usb(debug_putc, "\r\n\nUSB TASK: DE-ATTACH"); usb_detach(); } } if ((usb_state == USB_STATE_ATTACHED)&&(!UCON_SE0)) { UIR=0; UIE=0; #if !defined(USB_ISR_POLLING) enable_interrupts(INT_USB); enable_interrupts(GLOBAL); #endif UIE=__USB_UIF_IDLE | __USB_UIF_RESET; //enable IDLE and RESET USB ISR usb_state=USB_STATE_POWERED; debug_usb(debug_putc, "\r\n\nUSB TASK: POWERED"); } }
void usb_msdc_state(void) { INT32U plugcount = 0x2ff000; while(1) { //cmd loop usb_isr(); usb_std_service_udisk(0); usb_msdc_service(0); #if (MCU_VERSION == GPL32_B) if (USBRWError_Flag == 0xfefe) // B IC { break; } #endif //pollingExit: //if (!card_detection(4)) if (!storage_detection(4)) { DelOrUnplug = 1; break; } // check if usb is deleted by safe delete if(plugcount>0) plugcount--; else { if(DelOrUnplug == 1) break; else plugcount = 0x1000; } } }
void isr() { unsigned int irqs; cpustats_enter(); irqs = irq_pending() & irq_getmask(); if(irqs & IRQ_UARTRX) uart_isr_rx(); if(irqs & IRQ_UARTTX) uart_isr_tx(); if(irqs & IRQ_TIMER0) time_isr(); if(irqs & IRQ_AC97CRREQUEST) snd_isr_crrequest(); if(irqs & IRQ_AC97CRREPLY) snd_isr_crreply(); if(irqs & IRQ_AC97DMAR) snd_isr_dmar(); if(irqs & IRQ_AC97DMAW) snd_isr_dmaw(); if(irqs & IRQ_PFPU) pfpu_isr(); if(irqs & IRQ_TMU) tmu_isr(); if(irqs & IRQ_USB) usb_isr(); cpustats_leave(); }
//************************************************************************ // this function waits for space to be available in the transport // buffers and then prints the specified line to the CDCACM transport // console. //************************************************************************ void cdcacm_print(const byte *buffer, int length) { int a; int n; int m; int x; ASSERT(length); if (!cdcacm_attached || discard) { return; } // figure out how many buffers we need n = (length + sizeof (rx[0]) - 1) / sizeof (rx[0]) + 1; x = splx(7); // forever... m = 0; for (;;) { // compute the number of available buffers a = (rx_out + NRX - rx_in) % NRX; if (!a) { a = NRX; } // if we have as many as we need... if (a >= n) { // we're ready to go break; } #if ! INTERRUPT usb_isr(); #else splx(x); //delay(1); //if (m++ > 1000) { // discard = true; // return; //} x = splx(7); #endif } // while there is more data to send... do { // append to next rx_in(s) m = MIN(length, sizeof (rx[rx_in]) - rx_length[rx_in]); assert(rx_length[rx_in] + m <= sizeof (rx[rx_in])); memcpy(rx[rx_in] + rx_length[rx_in], buffer, m); rx_length[rx_in] += m; buffer += m; length -= m; // if this is the first buffer of the transfer or if the transfer will need more buffers... if (a == NRX || length) { // advance to the next buffer assert(length ? rx_length[rx_in] == sizeof (rx[rx_in]) : true); rx_in = (rx_in + 1) % NRX; assert(rx_in != rx_out); assert(!rx_length[rx_in]); } } while (length); // if this is the first buffer of the transfer... if (a == NRX) { // start the rx ball rolling assert(rx_out != rx_in); assert(rx_length[rx_out] > 0 && rx_length[rx_out] < PACKET_SIZE); usb_device_enqueue(bulk_in_ep, 1, rx[rx_out], rx_length[rx_out]); } splx(x); }
void main() { // mod, added to patch config bits patch_config(); output_high(LEDR); output_low(LEDG); usb_init(); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); set_timer0(0x8ad0); enable_interrupts(GLOBAL); enable_interrupts(INT_TIMER0); while(1) { #if defined (BOARD_AVRUSB12_32) //Mod here we check pin status to see if we must reset device if(!input(PIN_B7)) { delay_ms(25); //debounce if(!input(PIN_B7)) { //its a press output_bit(LEDG,1); delay_ms(500); //for long press detection, if(!input(PIN_B7)) { //its still a press after 1 sec PINRST_BTL(); //reset device } output_bit(LEDG,0); } } #endif usb_task(); usb_isr(); if(DelayCount) continue; if(Connect) { if(UADDR != HubAddress) { usb_set_address(HubAddress); } DevicePort = Connect; port_status[Connect - 1] = PORT_FULL; port_change[Connect - 1] = C_PORT_CONN; TxBuf[0] = 1 << Connect; if(Force0DTS) usb_put_packet(1, TxBuf, 1, 0); else usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE); Connect = 0; Force0DTS = 0; } if(Reset) { TxBuf[0] = 1 << Reset; usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE); Reset = 0; } if(Disconnect) { if(UADDR != HubAddress) usb_set_address(HubAddress); DevicePort = Disconnect; port_status[Disconnect - 1] = PORT_EMPTY; port_change[Disconnect - 1] = C_PORT_CONN; TxBuf[0] = 1 << Disconnect; usb_put_packet(1, TxBuf, 1, USB_DTS_TOGGLE); Disconnecting = Disconnect; Disconnect = 0; } if(WaitJig) { if(WaitJig == 1) { if(usb_kbhit(2)) { unsigned char c; Chirp(); c = usb_get_packet(2, TxBuf, 8); nJigs++; EP_BDxST_I(1) = 0x40; //Clear IN endpoint if(nJigs == 8) { nJigs = 0; WaitJig = 2; Delay10ms(50); } } } else { int n = 0; for(n = 0; n < 8; ++n) { TxBuf[n] = jig_response[8 * nJigs + n]; } if(usb_put_packet(1, TxBuf, 8, nJigs == 0 ? 0 : USB_DTS_TOGGLE)) { Delay10ms(1); nJigs++; Chirp(); if(nJigs == 8) { nJigs = 0; WaitJig = 0; Delay10ms(15); Disconnect = 3; } } } } if(Address != -1) { delay_ms(1); usb_set_address(Address); Address = -1; } } }