// ---------------------------------------------------------------------- // Poll USB driver: // - check for incoming USB packets // - refill an empty transmit buffer // - check for USB bus reset // ---------------------------------------------------------------------- extern void usb_poll ( void ) { byte_t i; // check for incoming USB packets if ( usb_rx_len != 0 ) { usb_receive( usb_rx_buf + USB_BUFSIZE - usb_rx_off + 1, usb_rx_len - 3 ); usb_tx_len = 0; // abort pending transmission usb_rx_len = 0; // accept next packet } // refill an empty transmit buffer, when the transmitter is active if ( usb_tx_len == 0 ) { if ( usb_tx_state != TX_STATE_IDLE ) { usb_transmit(); } else { // change the USB address at the end of a transfer usb_address = new_address; } } // check for USB bus reset for ( i = 10; i > 0 && ! (USB_IN & USB_MASK_DMINUS); i-- ) { } if ( i == 0 ) { // SE0 for more than 2.5uS is a reset new_address = 0; } }
// ---------------------------------------------------------------------- // Poll USB driver: // - check for incoming USB packets // - refill an empty transmit buffer // - check for USB bus reset // ---------------------------------------------------------------------- extern void usb_poll ( void ) { byte_t i; // check for incoming USB packets if ( usb_rx_len != 0 ) { usb_receive( usb_rx_buf + USB_BUFSIZE - usb_rx_off + 1, usb_rx_len - 3 ); usb_tx_len = 0; // abort pending transmission usb_rx_len = 0; // accept next packet } // refill an empty transmit buffer, when the transmitter is active if ( usb_tx_len == 0 && usb_tx_state != TX_STATE_IDLE ) { usb_transmit(); } // check for USB bus reset for ( i = 10; i > 0 && ! (USB_IN & USB_MASK_DMINUS); i-- ) { } if ( i == 0 ) { // SE0 for more than 2.5uS is a reset usb_new_address = 0; usb_address = 0; #ifdef USBTINY_USB_OK_LED CLR(USBTINY_USB_OK_LED); // LED off #endif } }