int main(void) { struct usb_bus *busses; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); struct usb_bus *bus; int c, i, a; /* ... */ for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; int val; usb_dev_handle *junk; for (dev = bus->devices; dev; dev = dev->next) { char buf[1024]; junk = usb_open ( dev ); usb_get_string_simple(junk,2,buf,1023); if(strncmp(buf,"FT232R",6)==0){ // printf( "reset %p %d (%s)\n", dev, val, buf ); if ( junk == NULL ){ printf("Can't open %p (%s)\n", dev, buf ); } else { val = usb_reset(junk); printf( "reset %p %d (%s)\n", dev, val, buf ); } } usb_close(junk); } } }
static int l_usb_reset(lua_State *L) { struct usb_dev_handle * dev_handle = lua_touserdata(L, 1); int ret = usb_reset(dev_handle); return (proccess_return_code(L, ret)); }
/* USB (low priority) interrupt */ void usb_lp_isr(void) { u16 mask; u16 status; int ep_id; u16 trans; /* Interrupt mask */ mask = usbdevfs_get_interrupt_mask(USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR | USBDEVFS_RESET | USBDEVFS_SOF); if (!mask) return; /* Interrupt status */ status = usbdevfs_get_interrupt_status(USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR | USBDEVFS_RESET | USBDEVFS_SOF | USBDEVFS_DIR | USBDEVFS_EP_ID); if (!(status & (USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR | USBDEVFS_RESET | USBDEVFS_SOF))) return; /* Start of frame */ if (mask & status & USBDEVFS_SOF) { sof(); /* Clear interrupt. */ usbdevfs_clear_interrupt(USBDEVFS_SOF); } /* Correct transfer */ if (mask & status & USBDEVFS_CORRECT_TRANSFER) { ep_id = status & USBDEVFS_EP_ID; trans = usbdevfs_get_ep_status(ep_id, USBDEVFS_RX | USBDEVFS_TX | USBDEVFS_SETUP); /* Rx (OUT/SETUP transaction) */ if ((status & USBDEVFS_DIR) && (trans & USBDEVFS_RX)) rx_packet(ep_id, trans & USBDEVFS_SETUP); /* Tx (IN transaction) */ if (!(status & USBDEVFS_DIR) && (trans & USBDEVFS_TX)) tx_packet(ep_id); } /* Error */ if (mask & status & USBDEVFS_ERROR) { usb_error++; /* Clear interrupt. */ usbdevfs_clear_interrupt(USBDEVFS_ERROR); } /* USB RESET */ if (mask & status & USBDEVFS_RESET) { usb_reset(); /* Clear interrupt. */ usbdevfs_clear_interrupt(USBDEVFS_RESET); } }
static void usb_resetdet(void) { /* TODO: Same as normal reset, right? I think we only get this if we're * suspended (sleeping) and the host resets us. Try it and see. */ print_later("usb_resetdet()", 0, 0, 0, 0, 0); usb_reset(); }
int main( int argc, char **argv) { usb_dev_handle *lvr_winusb; if ((lvr_winusb = setup_libusb_access()) == NULL) { exit(-1); } //printf("Testing control transfer: "); //test_control_transfer(lvr_winusb); //printf("Testing interrupt transfer: "); //test_interrupt_transfer(lvr_winusb); //printf("Testing bulk transfer: "); //test_bulk_transfer(lvr_winusb); usb_release_interface(lvr_winusb, 0); usb_reset(lvr_winusb); usb_close(lvr_winusb); return 0; }
static void usb_int_safe (void) { unsigned int int_status; /* putchar('*'); */ int_status = *AT91C_UDP_ISR & *AT91C_UDP_IMR; if (int_status & (AT91C_UDP_EP1 | AT91C_UDP_EP2 | AT91C_UDP_EP3)) { usb_epx_int(); } else if (int_status & AT91C_UDP_ENDBUSRES) { usb_reset(); *AT91C_UDP_ICR = AT91C_UDP_ENDBUSRES; } else if (int_status & AT91C_UDP_RXSUSP) { /* puts("Suspend"); */ *AT91C_UDP_ICR = AT91C_UDP_RXSUSP; } else if (int_status & AT91C_UDP_RXRSM) { /* puts("Resume"); */ *AT91C_UDP_ICR = AT91C_UDP_RXRSM; } else if (int_status & AT91C_UDP_SOFINT) { /* puts("SOF"); */ *AT91C_UDP_ICR = AT91C_UDP_SOFINT; } else if (int_status & AT91C_UDP_WAKEUP) { /* puts("Wakeup"); */ *AT91C_UDP_ICR = AT91C_UDP_WAKEUP; } else if (int_status & AT91C_UDP_EP0) { usb_ep0_int(); } else { puts("Other USB interrupt"); } /* putchar('<'); */ }
/***************************************************************************** * * CloseUSB * ****************************************************************************/ status_t CloseUSB(unsigned int reader_index) { /* device not opened */ if (usbDevice[reader_index].handle == NULL) return STATUS_UNSUCCESSFUL; DEBUG_COMM3("Closing USB device: %s/%s", usbDevice[reader_index].dirname, usbDevice[reader_index].filename); if (usbDevice[reader_index].ccid.arrayOfSupportedDataRates && (usbDevice[reader_index].ccid.bCurrentSlotIndex == 0)) { free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates); usbDevice[reader_index].ccid.arrayOfSupportedDataRates = NULL; } /* one slot closed */ (*usbDevice[reader_index].nb_opened_slots)--; /* release the allocated ressources for the last slot only */ if (0 == *usbDevice[reader_index].nb_opened_slots) { DEBUG_COMM("Last slot closed. Release resources"); /* reset so that bSeq starts at 0 again */ if (DriverOptions & DRIVER_OPTION_RESET_ON_CLOSE) (void)usb_reset(usbDevice[reader_index].handle); (void)usb_release_interface(usbDevice[reader_index].handle, usbDevice[reader_index].interface); (void)usb_close(usbDevice[reader_index].handle); #ifdef __APPLE__ DEBUG_INFO3("Terminating thread: %s/%s", usbDevice[reader_index].dirname, usbDevice[reader_index].filename); // Terminate thread *usbDevice[reader_index].pTerminated = TRUE; pthread_join(usbDevice[reader_index].hThread, NULL); // Free bStatus lock pthread_mutex_destroy(usbDevice[reader_index].ccid.pbStatusLock); #endif // Free array of bStatus free(usbDevice[reader_index].ccid.bStatus); free(usbDevice[reader_index].dirname); free(usbDevice[reader_index].filename); } /* mark the resource unused */ usbDevice[reader_index].handle = NULL; usbDevice[reader_index].dirname = NULL; usbDevice[reader_index].filename = NULL; usbDevice[reader_index].interface = 0; usbDevice[reader_index].ccid.bStatus = NULL; // Array of bStatus return STATUS_SUCCESS; } /* CloseUSB */
int reset_wheel(const wheelstruct* w) { usb_dev_handle *handle = usb_open_device_with_vid_pid(NULL, VID_LOGITECH, w->native_pid ); if ( handle == NULL ) { printf ( "%s not found. Make sure it is set to native mode (use --native).\n", w->name); return -1; } return usb_reset(handle); }
int usbsign_reset(int vendorid, int productid, int interface, usbsign_handle** dev) { int ret = usb_reset(*dev); if (ret < 0) { config_error("Got error %d when resetting usb device", ret); return ret; } return usbsign_open(vendorid, productid, interface, dev); }
/* USB::DevHandle#usb_reset */ static VALUE rusb_reset(VALUE v) { usb_dev_handle *p = get_usb_devhandle(v); int ret = usb_reset(p); check_usb_error("usb_reset", ret); /* xxx: call usb_close? */ return Qnil; }
static int gp_port_usb_close (GPPort *port) { if (!port || !port->pl->dh) return GP_ERROR_BAD_PARAMETERS; if (usb_release_interface (port->pl->dh, port->settings.usb.interface) < 0) { gp_port_set_error (port, _("Could not " "release interface %d (%m)."), port->settings.usb.interface); return (GP_ERROR_IO); } #if 0 /* This does break Canon EOS and some PowerShots ... -Marcus */ /* This is only for our very special Canon cameras which need a good * whack after close, otherwise they get timeouts on reconnect. */ if (port->pl->d->descriptor.idVendor == 0x04a9) { if (usb_reset (port->pl->dh) < 0) { gp_port_set_error (port, _("Could not reset USB port (%m).")); return (GP_ERROR_IO); } } #endif #if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) && defined(USBDEVFS_CONNECT) if (port->pl->detached) { char filename[PATH_MAX + 1]; int fd; /* FIXME shouldn't be a fixed path to usb root */ snprintf(filename, sizeof(filename) - 1, "%s/%s/%s", "/dev/bus/usb", port->pl->d->bus->dirname, port->pl->d->filename); fd = open(filename, O_RDWR); if (fd >= 0) { struct usbdevfs_ioctl command; command.ifno = 0; command.ioctl_code = USBDEVFS_CONNECT; command.data = NULL; if (ioctl(fd, USBDEVFS_IOCTL, &command)) gp_log (GP_LOG_DEBUG,"libusb","reattach kernel driver failed"); close(fd); } } #endif if (usb_close (port->pl->dh) < 0) { gp_port_set_error (port, _("Could not close USB port (%m).")); return (GP_ERROR_IO); } port->pl->dh = NULL; return GP_OK; }
int usbResetDevice (UsbDevice *device) { UsbDeviceExtension *devx = device->extension; int result = usb_reset(devx->handle); if (result >= 0) return 1; errno = -result; logSystemError("USB device reset"); return 0; }
int libusb_reset (libusb_t *libusb) { int i; for ( i = 0 ; i < libusb->dev_number ; i++) { if (usb_reset (libusb->handlers[i]) < 0) return -1; } return 0; }
void USBDriver_Impl_Libusb::Close() { // never opened if( m_pHandle == NULL ) return; usb_set_altinterface( m_pHandle, 0 ); usb_reset( m_pHandle ); usb_close( m_pHandle ); m_pHandle = NULL; }
int usbResetDevice (UsbDevice *device) { logMessage(LOG_CATEGORY(USB_IO), "reset device"); UsbDeviceExtension *devx = device->extension; int result = usb_reset(devx->handle); if (result >= 0) return 1; errno = -result; logSystemError("USB device reset"); return 0; }
void usbevt_vbuson () { /// The standard code turns-on the USB subsystem and generates a rising edge /// on DP (D+) via reset-connect, which causes the host to enumerate this /// device as a 12 Mbps USB Full Speed Device. if (usb_enable() == kUSB_succeed){ usb_reset(); usb_connect(); } if (platform_ext.usb_wakeup != False) { sys_resume(); } }
int main(void) { /* * pgm_read_byte gets cached and there doesn't seem to be any other * way to dissuade gcc from doing this. */ volatile int zero = 0; uint32_t loop = 0; board_init(); spi_init(); _delay_ms(10); /* set MCP2515 clkdiv to /2 for 8MHz */ can_cs_l(); spi_io(INSTRUCTION_WRITE); spi_io(CANCTRL); spi_io(0x85); can_cs_h(); led_init(); usb_init(); dfu_init(); /* move interrupt vectors to the boot loader */ MCUCR = 1 << IVCE; MCUCR = 1 << IVSEL; sei(); while (loop < 5) { led_a_on(); led_b_on(); _delay_ms(50); led_a_off(); led_b_off(); _delay_ms(400); if (dfu.state == dfuIDLE && pgm_read_byte(zero) != 0xff) loop++; else loop = 0; } cli(); usb_reset(); run_payload(); while (1); }
void send_lamp_command(char* title, char* message1, char* message2){ usb_reset(launcher); usb_resetep(launcher, 0); usb_resetep(launcher, 1); usb_clear_halt(launcher, 0); usb_clear_halt(launcher, 1); send_cbw(); fprintf(stderr, "Submitting %s\n", title); int ret = send_message(message1, 0); fprintf(stderr, "%d bytes sent\n", ret); ret = send_message(message2, 0); fprintf(stderr, "%d bytes sent\n", ret); }
void usb_init(){ //uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); //GlobalInterruptDisable(); NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0)); NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1)); //SetGlobalInterruptMask(CurrentGlobalInt); usb_reset(); }
void USBDriver::Close() { // never opened if( m_pHandle == NULL ) return; LOG->Trace( "USBDriver::Close()" ); usb_set_altinterface( m_pHandle, 0 ); usb_reset( m_pHandle ); usb_close( m_pHandle ); m_pHandle = NULL; }
void irecv_reset(void) { devPhone = irecv_init(WTF_MODE); if(devPhone == NULL) { devPhone = irecv_init(RECV_MODE); if(devPhone == NULL) { printf("No iPhone/iPod found.\n"); exit(EXIT_FAILURE); } } if(devPhone != NULL) { usb_reset(devPhone); } }
static void usb_host_handle_reset(USBDevice *dev) { #ifdef DEBUG printf("usb_host_handle_reset called\n"); #endif #if 0 USBHostDevice *s = (USBHostDevice *)dev; /* USBDEVFS_RESET, but not the first time as it has already be * done by the host OS - usb_reset() - must reopen handle */ usb_reset(s->udev); #endif }
/** * reset the connected usb device to recall it to standard tty interface * @return 0 on success<br>-1 on failure **/ int reset() { if( devices.empty() ) { if( scan() < 0 ) return -1; }; struct usb_device *dev = devices[0]; usb_dev_handle *h = usb_open(dev); if( h < 0 ) { return -1; } int ret_val = usb_reset(h); return ret_val; }
void USBManager::slotConnect() { if (!mDeviceState) { usb_dev_handle *lDeviceHandle = NULL; usb_bus *lDeviceBus = NULL; struct usb_device *lCurrentDevice; for (lDeviceBus = usb_get_busses(); lDeviceBus != NULL && lDeviceHandle == NULL; lDeviceBus = lDeviceBus->next) { for (lCurrentDevice = lDeviceBus->devices; lCurrentDevice != NULL && lDeviceHandle == NULL; lCurrentDevice = lCurrentDevice->next) { if (lCurrentDevice->descriptor.idVendor == mVID && lCurrentDevice->descriptor.idProduct == mPID) { mUSBDevice = lCurrentDevice; lDeviceHandle = usb_open(lCurrentDevice); qDebug() << "lDeviceHandle: " << lDeviceHandle; } // qDebug() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; // qDebug() << "Pid: " << QString("%1").arg(lCurrentDevice->descriptor.idProduct, 0, 16); // qDebug() << "Vid: " << QString("%1").arg(lCurrentDevice->descriptor.idVendor, 0, 16); // qDebug() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; } } if (lDeviceHandle) { delete mDeviceHandle; mDeviceHandle = lDeviceHandle; } mDeviceState = (mDeviceHandle); } else { int lResult = usb_claim_interface(mDeviceHandle, usb_device(mDeviceHandle)->config->interface->altsetting->iInterface); if (lResult > 0) { usb_reset(mDeviceHandle); qDebug() << "reset"; } else { // qDebug() << metaObject()->className() << " device is already opened!"; } } slotDebugLogger(); }
static int gp_libusb1_close (GPPort *port) { C_PARAMS (port); if (port->pl->dh == NULL) return GP_OK; _close_async_interrupts(port); if (libusb_release_interface (port->pl->dh, port->settings.usb.interface) < 0) { int saved_errno = errno; gp_port_set_error (port, _("Could not release interface %d (%s)."), port->settings.usb.interface, strerror(saved_errno)); return GP_ERROR_IO; } #if 0 /* This confuses the EOS 5d camera and possible other EOSs. *sigh* */ /* This is only for our very special Canon cameras which need a good * whack after close, otherwise they get timeouts on reconnect. */ if (port->pl->d->descriptor.idVendor == 0x04a9) { if (usb_reset (port->pl->dh) < 0) { int saved_errno = errno; gp_port_set_error (port, _("Could not reset " "USB port (%s)."), strerror(saved_errno)); return (GP_ERROR_IO); } } #endif if (port->pl->detached) { if (LOG_ON_LIBUSB_E (libusb_attach_kernel_driver (port->pl->dh, port->settings.usb.interface))) gp_port_set_error (port, _("Could not reattach kernel driver of camera device.")); } libusb_close (port->pl->dh); free (port->pl->irqs); port->pl->irqs = NULL; free (port->pl->irqlens); port->pl->irqlens = NULL; port->pl->nrofirqs = 0; port->pl->dh = NULL; return GP_OK; }
int dfu_makeidle(usb_dev_handle *dev, uint16_t iface) { int i; dfu_status status; for(i = 0; i < 3; i++) { if(dfu_getstatus(dev, iface, &status) < 0) { dfu_clrstatus(dev, iface); continue; } i--; switch(status.bState) { case STATE_DFU_IDLE: return 0; case STATE_DFU_DOWNLOAD_SYNC: case STATE_DFU_DOWNLOAD_IDLE: case STATE_DFU_MANIFEST_SYNC: case STATE_DFU_UPLOAD_IDLE: case STATE_DFU_DOWNLOAD_BUSY: case STATE_DFU_MANIFEST: dfu_abort(dev, iface); continue; case STATE_DFU_ERROR: dfu_clrstatus(dev, iface); continue; case STATE_APP_IDLE: dfu_detach(dev, iface, DFU_DETACH_TIMEOUT); continue; case STATE_APP_DETACH: case STATE_DFU_MANIFEST_WAIT_RESET: usb_reset(dev); return -1; default: return -1; } } return -1; }
void usb_drv_init(void) { /* Enable USB clock */ #if CONFIG_CPU==S5L8701 PWRCON &= ~0x4000; PWRCONEXT &= ~0x800; INTMSK |= INTMSK_USB_OTG; #elif CONFIG_CPU==S5L8702 PWRCON(0) &= ~0x4; PWRCON(1) &= ~0x8; VIC0INTENABLE |= 1 << 19; #endif PCGCCTL = 0; /* reset the beast */ usb_reset(); }
usb_dev_handle* setup_libusb_access() { usb_dev_handle *lvr_winusb; if (debug) { usb_set_debug(255); } else { usb_set_debug(0); } usb_init(); usb_find_busses(); usb_find_devices(); if (!(lvr_winusb = find_lvr_winusb())) { printf("Couldn't find the USB device, exiting.\n"); return NULL; } usb_detach(lvr_winusb, INTERFACE1); usb_detach(lvr_winusb, INTERFACE2); // reset device if (usb_reset(lvr_winusb) != 0) { printf("Could not reset device.\n"); return NULL; } if (usb_set_configuration(lvr_winusb, 0x01) < 0) { printf("Could not set configuration 1.\n"); return NULL; } // Microdia tiene 2 interfaces if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) { printf("Could not claim interface.\n"); return NULL; } if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) { printf("Could not claim interface.\n"); return NULL; } return lvr_winusb; }
/***************************************************************************** * * CloseUSB * ****************************************************************************/ status_t CloseUSB(unsigned int reader_index) { /* device not opened */ if (usbDevice[reader_index].handle == NULL) return STATUS_UNSUCCESSFUL; DEBUG_COMM3("Closing USB device: %s/%s", usbDevice[reader_index].dirname, usbDevice[reader_index].filename); if (usbDevice[reader_index].ccid.arrayOfSupportedDataRates && (usbDevice[reader_index].ccid.bCurrentSlotIndex == 0)) { free(usbDevice[reader_index].ccid.arrayOfSupportedDataRates); usbDevice[reader_index].ccid.arrayOfSupportedDataRates = NULL; } /* one slot closed */ (*usbDevice[reader_index].nb_opened_slots)--; /* release the allocated ressources for the last slot only */ if (0 == *usbDevice[reader_index].nb_opened_slots) { DEBUG_COMM("Last slot closed. Release resources"); /* reset so that bSeq starts at 0 again */ if (DriverOptions & DRIVER_OPTION_RESET_ON_CLOSE) (void)usb_reset(usbDevice[reader_index].handle); (void)usb_release_interface(usbDevice[reader_index].handle, usbDevice[reader_index].interface); (void)usb_close(usbDevice[reader_index].handle); free(usbDevice[reader_index].dirname); free(usbDevice[reader_index].filename); } /* mark the resource unused */ usbDevice[reader_index].handle = NULL; usbDevice[reader_index].dirname = NULL; usbDevice[reader_index].filename = NULL; usbDevice[reader_index].interface = 0; return STATUS_SUCCESS; } /* CloseUSB */
static int gp_port_usb_close (GPPort *port) { if (!port || !port->pl->dh) return GP_ERROR_BAD_PARAMETERS; if (libusb_release_interface (port->pl->dh, port->settings.usb.interface) < 0) { int saved_errno = errno; gp_port_set_error (port, _("Could not release " "interface %d (%s)."), port->settings.usb.interface, strerror(saved_errno)); return (GP_ERROR_IO); } #if 0 /* This confuses the EOS 5d camera and possible other EOSs. *sigh* */ /* This is only for our very special Canon cameras which need a good * whack after close, otherwise they get timeouts on reconnect. */ if (port->pl->d->descriptor.idVendor == 0x04a9) { if (usb_reset (port->pl->dh) < 0) { int saved_errno = errno; gp_port_set_error (port, _("Could not reset " "USB port (%s)."), strerror(saved_errno)); return (GP_ERROR_IO); } } #endif if (port->pl->detached) { int ret; ret = libusb_attach_kernel_driver (port->pl->dh, port->settings.usb.interface); if (ret < 0) gp_port_set_error (port, _("Could not reattach kernel driver of camera device.")); } libusb_close (port->pl->dh); port->pl->dh = NULL; return GP_OK; }