void usb_isr_rst(void) { UEIR = 0; UIR = 0; UEIE = 0x9F; UIE = STANDARD_INTS & ~__USB_UIF_ACTIVE; UADDR = 0; usb_disable_endpoints(); usb_token_reset(); UEP(0) = ENDPT_CONTROL | 0x10; while (UIR_TRN) { usb_clear_trn(); } UCON_PKTDIS = 0; //SIE token and packet processing enabled usb_init_ep0_setup(); usb_state = USB_STATE_DEFAULT; //put usb mcu into default state }
// see usb_hw_layer.h for documentation void usb_set_configured(unsigned int8 config) { unsigned int8 en; unsigned int16 addy; unsigned int8 new_uep; unsigned int16 len; unsigned int8 i; if (config == 0) { // if config=0 then set addressed state usb_state = USB_STATE_ADDRESS; usb_disable_endpoints(); } else { // else set configed state usb_state = USB_STATE_CONFIGURED; addy = (unsigned int16)USB_DATA_BUFFER_LOCATION+(2*USB_MAX_EP0_PACKET_LENGTH); for (en=1; en<USB_NUM_UEP; en++) { // enable and config endpoints based upon user configuration usb_disable_endpoint(en); new_uep = 0; if (usb_ep_rx_type[en] != USB_ENABLE_DISABLED) { new_uep = 0x04; len = usb_ep_rx_size[en]; EP_BDxCNT_O(en) = len; EP_BDxADR_O(en) = addy; addy += usb_ep_rx_size[en]; #if USB_IGNORE_RX_DTS i = 0x80; #else i = 0x88; #endif if (bit_test(len,8)) {bit_set(i,0);} if (bit_test(len,9)) {bit_set(i,1);} EP_BDxST_O(en) = i; } if (usb_ep_tx_type[en] != USB_ENABLE_DISABLED) { new_uep |= 0x02; EP_BDxADR_I(en) = addy; addy += usb_ep_tx_size[en]; EP_BDxST_I(en) = 0x40; } if (new_uep == 0x06) {new_uep = 0x0E;} if (usb_ep_tx_type[en] != USB_ENABLE_ISOCHRONOUS) {new_uep |= 0x10;} UEP(en) = new_uep; } } }