static void usb_connect_work_fn(struct work_struct *work) { struct diag_usb_info *ch = container_of(work, struct diag_usb_info, connect_work); usb_connect(ch); }
void UsbConnection::print_info() { int error_config; libusb_config_descriptor *config_desc; libusb_device_descriptor desc; if (!device) { ConnectionStatus status = usb_connect (); if (status == ready){ return; } } libusb_get_device_descriptor(device, &desc); unsigned char data[255] = {}; int response = libusb_get_string_descriptor_ascii (handler, desc.iProduct, data, sizeof(data)); qDebug("Product Description: %s|\n", data); response = libusb_get_string_descriptor_ascii (handler, desc.iManufacturer, data, sizeof(data)); qDebug("Manufacturer Description: %s|\n", data); libusb_get_string_descriptor_ascii (handler, desc.iSerialNumber, data, sizeof(data)); qDebug("SerialNumber Description: %s|\n", data); qDebug("\nbegin descriptor\n"); qDebug("\tbus_num: %d\n", libusb_get_bus_number(device)); qDebug("\taddress: %d\n", libusb_get_device_address(device)); qDebug("\tspeed: %d\n", libusb_get_device_speed(device)); qDebug("\tClass: %d\n", desc.bDeviceClass); qDebug("\tSubClass: %d\n", desc.bDeviceSubClass); qDebug("\tDeviceProtocol: %d\n", desc.bDeviceProtocol); qDebug("\tidVendor: %d\n", desc.idVendor); qDebug("\tidProduct: %d\n", desc.idProduct); qDebug("\tiManufacturer: %d\n", desc.iManufacturer); qDebug("\tiProduct: %d\n", desc.iProduct); qDebug("\tiSerialNumber: %d\n", desc.iSerialNumber); qDebug("\tbMaxPacketSize0: %d\n", desc.bMaxPacketSize0); qDebug("\tbNumConfigurations: %d\n", desc.bNumConfigurations); qDebug("\tconfigDescriptor:\n"); error_config = libusb_get_active_config_descriptor(device, &config_desc); if (error_config) { if (error_config == LIBUSB_ERROR_NOT_FOUND) { qDebug("Error config not founds\n"); } else { qDebug("Error in config %s\n", libusb_error_name (error_config)); } } else { qDebug("\tiConfiguration: %d\n", config_desc->iConfiguration); qDebug("\tbNumInterface: %d\n", config_desc->bNumInterfaces); qDebug("\tbmAttributes: %d\n", config_desc->bmAttributes); for (int i_interface = 0; i_interface < config_desc->bNumInterfaces; i_interface++) { for (int i_altinterface = 0; i_altinterface < config_desc->interface[i_interface].num_altsetting; i_altinterface++) { libusb_interface_descriptor alt_settings = config_desc->interface[i_interface].altsetting[i_altinterface]; qDebug("\tbInterfaceNumber[%d][%d]: %d\n", i_interface, i_altinterface, alt_settings.bInterfaceNumber); qDebug("\tbInterfaceClass[%d][%d]: %d\n", i_interface, i_altinterface, alt_settings.bInterfaceClass); qDebug("\bInterfaceSubClass[%d][%d]: %d\n", i_interface, i_altinterface, alt_settings.bInterfaceSubClass); qDebug("\tbInterfaceProtocol[%d][%d]: %d\n", i_interface, i_altinterface, alt_settings.bInterfaceProtocol); qDebug("\textra[%d][%d]: %s\n", i_interface, i_altinterface, alt_settings.extra); for (int i_ep = 0; i_ep < alt_settings.bNumEndpoints; i_ep++) { libusb_endpoint_descriptor ep_desc = alt_settings.endpoint[i_ep]; qDebug("\t\tbEndpointAddress[%d][%d][%d]: %d (in=%d / out=%d)\n", i_interface, i_altinterface, i_ep, ep_desc.bEndpointAddress, LIBUSB_ENDPOINT_IN, LIBUSB_ENDPOINT_OUT); qDebug("\t\tbDescriptorType[%d][%d][%d]: %d\n", i_interface, i_altinterface, i_ep, ep_desc.bDescriptorType); qDebug("\t\tbmAttributes[%d][%d][%d]: %d\n", i_interface, i_altinterface, i_ep, ep_desc.bmAttributes); qDebug("\t\textra[%d][%d][%d]: %d\n", i_interface, i_altinterface, i_ep, ep_desc.extra_length); qDebug("\t\tbSynchAddress[%d][%d][%d]: %d\n", i_interface, i_altinterface, i_ep, ep_desc.bSynchAddress); } } } libusb_free_config_descriptor(config_desc); } }
static void usb_hub_port_connect_change(struct usb_device *hub, int port, struct usb_port_status *portsts) { struct usb_device *dev; unsigned short portstatus, portchange; unsigned int delay = HUB_SHORT_RESET_TIME; int i; char *portstr, *tempstr; portstatus = le16_to_cpu(portsts->wPortStatus); portchange = le16_to_cpu(portsts->wPortChange); dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portstatus & (1 << USB_PORT_FEAT_LOWSPEED) ? "1.5 Mb/s" : "12 Mb/s"); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); tempstr = kmalloc(1024, GFP_KERNEL); portstr = kmalloc(1024, GFP_KERNEL); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev, *cdev; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } hub->children[port] = dev; /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Create a readable topology string */ cdev = dev; pdev = dev->parent; if (portstr && tempstr) { portstr[0] = 0; while (pdev) { int port; for (port = 0; port < pdev->maxchild; port++) if (pdev->children[port] == cdev) break; strcpy(tempstr, portstr); if (!strlen(tempstr)) sprintf(portstr, "%d", port + 1); else sprintf(portstr, "%d/%s", port + 1, tempstr); cdev = pdev; pdev = pdev->parent; } info("USB new device connect on bus%d/%s, assigned device number %d", dev->bus->busnum, portstr, dev->devnum); } else info("USB new device connect on bus%d, assigned device number %d", dev->bus->busnum, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) goto done; /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); if (portstr) kfree(portstr); if (tempstr) kfree(tempstr); }
static void usb_hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = hubstate->dev; struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if (usb_hub_port_debounce(hub, port)) { err("connect-debounce failed, port %d disabled", port+1); usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev; int len; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Save readable and stable topology id, distinguishing * devices by location for diagnostics, tools, etc. The * string is a path along hub ports, from the root. Each * device's id will be stable until USB is re-cabled, and * hubs are often labeled with these port numbers. * * Initial size: ".NN" times five hubs + NUL = 16 bytes max * (quite rare, since most hubs have 4-6 ports). */ pdev = dev->parent; if (pdev->devpath [0] != '0') /* parent not root? */ len = snprintf (dev->devpath, sizeof dev->devpath, "%s.%d", pdev->devpath, port + 1); /* root == "0", root port 2 == "2", port 3 that hub "2.3" */ else len = snprintf (dev->devpath, sizeof dev->devpath, "%d", port + 1); if (len == sizeof dev->devpath) warn ("devpath size! usb/%03d/%03d path %s", dev->bus->busnum, dev->devnum, dev->devpath); USB_SET_LED(USB_CONNECT); //2005-02-24 by kanki for USB LED info("new USB device %s-%s, assigned address %d", dev->bus->bus_name, dev->devpath, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) { hub->children[port] = dev; goto done; } /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); }
void usb_init(void) { int i, resume; /* USB is in use */ disable_sleep(SLEEP_MASK_USB_DEVICE); /* * Resuming from a deep sleep is a lot like a cold boot, but there are * few things that we need to do slightly differently. However, we ONLY * do them if we're really resuming due to a USB wakeup. If we're woken * for some other reason, we just do a normal USB reset. The host * doesn't mind. */ resume = ((system_get_reset_flags() & RESET_FLAG_USB_RESUME) && (GR_USB_GINTSTS & GC_USB_GINTSTS_WKUPINT_MASK)); /* TODO(crosbug.com/p/46813): Clean this up. Do only what's needed, and * use meaningful constants instead of magic numbers. */ GREG32(GLOBALSEC, DDMA0_REGION0_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DDMA0_REGION1_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DDMA0_REGION2_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DDMA0_REGION3_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DUSB0_REGION0_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DUSB0_REGION1_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DUSB0_REGION2_CTRL) = 0xffffffff; GREG32(GLOBALSEC, DUSB0_REGION3_CTRL) = 0xffffffff; /* Enable clocks */ clock_enable_module(MODULE_USB, 1); /* TODO(crbug.com/496888): set up pinmux */ gpio_config_module(MODULE_USB, 1); /* Make sure interrupts are disabled */ GR_USB_GINTMSK = 0; GR_USB_DAINTMSK = 0; GR_USB_DIEPMSK = 0; GR_USB_DOEPMSK = 0; /* Select the correct PHY */ usb_select_phy(which_phy); /* Full-Speed Serial PHY */ GR_USB_GUSBCFG = GUSBCFG_PHYSEL_FS | GUSBCFG_FSINTF_6PIN | GUSBCFG_TOUTCAL(7) /* FIXME: Magic number! 14 is for 15MHz! Use 9 for 30MHz */ | GUSBCFG_USBTRDTIM(14); if (!resume) /* Don't reset on resume, because some preserved internal state * will be lost and there's no way to restore it. */ usb_softreset(); GR_USB_GUSBCFG = GUSBCFG_PHYSEL_FS | GUSBCFG_FSINTF_6PIN | GUSBCFG_TOUTCAL(7) /* FIXME: Magic number! 14 is for 15MHz! Use 9 for 30MHz */ | GUSBCFG_USBTRDTIM(14); /* Global + DMA configuration */ /* TODO: What about the AHB Burst Length Field? It's 0 now. */ GR_USB_GAHBCFG = GAHBCFG_DMA_EN | GAHBCFG_GLB_INTR_EN | GAHBCFG_NP_TXF_EMP_LVL; /* Be in disconnected state until we are ready */ if (!resume) usb_disconnect(); if (resume) /* DEVADDR is preserved in the USB module during deep sleep, * but it doesn't show up in USB_DCFG on resume. If we don't * restore it manually too, it doesn't work. */ GR_USB_DCFG = GREG32(PMU, PWRDN_SCRATCH18); else /* Init: USB2 FS, Scatter/Gather DMA, DEVADDR = 0x00 */ GR_USB_DCFG |= DCFG_DEVSPD_FS48 | DCFG_DESCDMA; /* If we've restored a nonzero device address, update our state. */ if (GR_USB_DCFG & GC_USB_DCFG_DEVADDR_MASK) { /* Caution: We only have one config TODAY, so there's no real * difference between DS_CONFIGURED and DS_ADDRESS. */ device_state = DS_CONFIGURED; configuration_value = 1; } else { device_state = DS_DEFAULT; configuration_value = 0; } /* Now that DCFG.DesDMA is accurate, prepare the FIFOs */ setup_data_fifos(); /* If resuming, reinitialize the endpoints now. For a cold boot we'll * do this as part of handling the host-driven reset. */ if (resume) usb_init_endpoints(); /* Clear any pending interrupts */ for (i = 0; i < 16; i++) { GR_USB_DIEPINT(i) = 0xffffffff; GR_USB_DOEPINT(i) = 0xffffffff; } GR_USB_GINTSTS = 0xFFFFFFFF; /* Unmask some endpoint interrupt causes */ GR_USB_DIEPMSK = DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK; GR_USB_DOEPMSK = DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK | DOEPMSK_SETUPMSK; /* Enable interrupt handlers */ task_enable_irq(GC_IRQNUM_USB0_USBINTR); /* Allow USB interrupts to come in */ GR_USB_GINTMSK = /* NAK bits that must be cleared by the DCTL register */ GINTMSK(GOUTNAKEFF) | GINTMSK(GINNAKEFF) | /* Initialization events */ GINTMSK(USBRST) | GINTMSK(ENUMDONE) | /* Endpoint activity, cleared by the DOEPINT/DIEPINT regs */ GINTMSK(OEPINT) | GINTMSK(IEPINT) | /* Reset detected while suspended. Need to wake up. */ GINTMSK(RESETDET) | /* TODO: Do we need this? */ /* Idle, Suspend detected. Should go to sleep. */ GINTMSK(ERLYSUSP) | GINTMSK(USBSUSP) | /* Watch for first SOF */ GINTMSK(SOF); /* Device registers have been setup */ GR_USB_DCTL |= DCTL_PWRONPRGDONE; udelay(10); GR_USB_DCTL &= ~DCTL_PWRONPRGDONE; /* Clear global NAKs */ GR_USB_DCTL |= DCTL_CGOUTNAK | DCTL_CGNPINNAK; #ifndef CONFIG_USB_INHIBIT_CONNECT /* Indicate our presence to the USB host */ if (!resume) usb_connect(); #endif }
void MainWindow::timerEvent(QTimerEvent *) { int ret=0; if(usbdevhandle!=NULL) ret=usb_bulk_read(usbdevhandle, EP_IN, (char*)usb_in, 64, 1000); if(ret!=64) { ui->label_status->setText("Connecting"); if(usbdevhandle!=NULL) usb_close(usbdevhandle); usbdevhandle=NULL; usbdevhandle=usb_connect(); if(usbdevhandle==NULL) { return; } else { ui->label_status->setText("Working"); } } else ui->label_status->setText("Working"); float temp_raw, temp_raw_max; float temp_C; temp_raw=(usb_in[0]<<8)|usb_in[1]; temp_raw_max=(usb_in[2]<<8)|usb_in[3]; if(temp_raw!=temp_raw_max) temp_C = 235.0 - 400.0*temp_raw/(temp_raw_max-temp_raw); else temp_C = -273.0; ui->label_t->setText(QString::number(temp_C)); usb_out[63]=95; //marker int tc1=0, tv1=0; tv1=ui->spinBox_shift1->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Shift1", tv1); tv1=ui->spinBox_shift2->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Shift2", tv1); tv1=ui->spinBox_gain1->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Gain1", tv1); usb_out[tc1++] = (ui->checkBox_led2->isChecked()<<3) | (ui->checkBox_led1->isChecked()<<2) | (ui->checkBox_pd2->isChecked()<<1) | (ui->checkBox_pd1->isChecked()); S->setValue("LED2", ui->checkBox_led2->isChecked()); S->setValue("LED1", ui->checkBox_led1->isChecked()); S->setValue("PD2", ui->checkBox_pd2->isChecked()); S->setValue("PD1", ui->checkBox_pd1->isChecked()); tv1=ui->spinBox_gain2->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Gain2", tv1); tv1=ui->spinBox_slope1->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Slope1", tv1); tv1=ui->spinBox_slope2->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("Slope2", tv1); tv1=ui->spinBox_hv1->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("HV1", tv1); tv1=ui->spinBox_hv2->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("HV2", tv1); tv1=ui->spinBox_fol->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("FOL", tv1); tv1=ui->spinBox_dil->value(); usb_out[tc1++]=tv1>>8; usb_out[tc1++]=tv1&255; S->setValue("DIL", tv1); ret=usb_bulk_write(usbdevhandle, EP_OUT, (char*)usb_out, 64, 1000); if(ret!=64) { ui->label_status->setText("Connecting"); if(usbdevhandle!=NULL) usb_close(usbdevhandle); usbdevhandle=NULL; usbdevhandle=usb_connect(); if(usbdevhandle==NULL) { return; } else { ui->label_status->setText("Working"); } } else ui->label_status->setText("Working"); }
static void hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = interface_to_usbdev(hubstate->intf); struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; dev_dbg (&hubstate->intf->dev, "port %d, status %x, change %x, %s\n", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) hub_port_disable(hub, port); return; } if (hub_port_debounce(hub, port)) { dev_err (&hubstate->intf->dev, "connect-debounce failed, port %d disabled\n", port+1); hub_port_disable(hub, port); return; } /* Some low speed devices have problems with the quick delay, so */ /* be a bit pessimistic with those devices. RHbug #23670 */ if (portstatus & USB_PORT_STAT_LOW_SPEED) delay = HUB_LONG_RESET_TIME; down(&usb_address0_sem); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev; int len; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { dev_err (&hubstate->intf->dev, "couldn't allocate usb_device\n"); break; } hub->children[port] = dev; dev->state = USB_STATE_POWERED; /* Reset the device, and detect its speed */ if (hub_port_reset(hub, port, dev, delay)) { usb_put_dev(dev); break; } /* Find a new address for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Save readable and stable topology id, distinguishing * devices by location for diagnostics, tools, etc. The * string is a path along hub ports, from the root. Each * device's id will be stable until USB is re-cabled, and * hubs are often labeled with these port numbers. * * Initial size: ".NN" times five hubs + NUL = 16 bytes max * (quite rare, since most hubs have 4-6 ports). */ pdev = dev->parent; if (pdev->devpath [0] != '0') /* parent not root? */ len = snprintf (dev->devpath, sizeof dev->devpath, "%s.%d", pdev->devpath, port + 1); /* root == "0", root port 2 == "2", port 3 that hub "2.3" */ else len = snprintf (dev->devpath, sizeof dev->devpath, "%d", port + 1); if (len == sizeof dev->devpath) dev_err (&hubstate->intf->dev, "devpath size! usb/%03d/%03d path %s\n", dev->bus->busnum, dev->devnum, dev->devpath); dev_info (&hubstate->intf->dev, "new USB device on port %d, assigned address %d\n", port + 1, dev->devnum); /* put the device in the global device tree. the hub port * is the "bus_id"; hubs show in hierarchy like bridges */ dev->dev.parent = dev->parent->dev.parent->parent; /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev, &hub->dev)) goto done; /* Free the configuration if there was an error */ usb_put_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; hub_port_disable(hub, port); done: up(&usb_address0_sem); }
static void usb_hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = hubstate->dev; struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if (usb_hub_port_debounce(hub, port)) { err("connect-debounce failed, port %d disabled", port+1); usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev; int len; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } hub->children[port] = dev; /* add by Levis for wakeup BP */ int begin = 0; #ifdef CONFIG_ARCH_EZXBASE set_GPIO_mode(GPIO_IN | GPIO_BP_RDY); if(!GPIO_is_high(GPIO_BP_RDY)) { if(GPIO_is_high(GPIO_AP_RDY )) { GPCR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); udelay(WAKE_UP_BP_UDELAY); GPSR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); }else { GPSR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); udelay(WAKE_UP_BP_UDELAY); GPCR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); } begin = jiffies; while(!GPIO_is_high(GPIO_BP_RDY) && (jiffies < (begin+HZ))) ; if(!GPIO_is_high(GPIO_BP_RDY)) { printk("%s: Wakeup BP timeout! BP is still in sleep state!\n", __FUNCTION__); } } #else set_GPIO_mode(GPIO_IN | 41); if(GPIO_is_high(41)) { if(GPIO_is_high(GPIO_MCU_INT_SW)) GPCR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); else { GPSR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); } begin = jiffies; while(GPIO_is_high(41) && (jiffies < (begin+HZ))) printk("%s: waitting for BP active!\n", __FUNCTION__); if(GPIO_is_high(GPIO_MCU_INT_SW)) GPCR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); else { GPSR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); } } #endif /* end Levis */ /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Save readable and stable topology id, distinguishing * devices by location for diagnostics, tools, etc. The * string is a path along hub ports, from the root. Each * device's id will be stable until USB is re-cabled, and * hubs are often labeled with these port numbers. * * Initial size: ".NN" times five hubs + NUL = 16 bytes max * (quite rare, since most hubs have 4-6 ports). */ pdev = dev->parent; if (pdev->devpath [0] != '0') /* parent not root? */ len = snprintf (dev->devpath, sizeof dev->devpath, "%s.%d", pdev->devpath, port + 1); /* root == "0", root port 2 == "2", port 3 that hub "2.3" */ else len = snprintf (dev->devpath, sizeof dev->devpath, "%d", port + 1); if (len == sizeof dev->devpath) warn ("devpath size! usb/%03d/%03d path %s", dev->bus->busnum, dev->devnum, dev->devpath); info("new USB device %s-%s, assigned address %d", dev->bus->bus_name, dev->devpath, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) goto done; /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); }
int main(void) { #ifndef NO_DEBUG uart_init(); stdout = &uart_stdout; banner(); #endif shared_memory_init(); system_init(); sram_init(); pwm_init(); irq_init(); boot_startup_rom(50); globals_init(); pwm_stop(); usbInit(); usb_connect(); sei(); while (1) { system_set_bus_avr(); system_set_wr_disable(); while (usb_trans.req_state != REQ_STATUS_SNES) { usbPoll(); #if DO_SHELL #ifndef NO_DEBUG shell_run(); #endif #endif } #if DO_SHM shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0); #endif #if DO_SHM_SCRATCHPAD shared_memory_scratchpad_region_tx_restore(); shared_memory_scratchpad_region_rx_restore(); #endif #if DO_CRC_CHECK info_P(PSTR("-->CRC Check\n")); crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size); #endif system_set_rom_mode(&usb_trans); system_set_wr_disable(); system_set_bus_snes(); system_send_snes_reset(); irq_stop(); while ((usb_trans.req_state != REQ_STATUS_AVR)) { usbPoll(); #if DO_SHELL #ifndef NO_DEBUG shell_run(); #endif #endif } info_P(PSTR("-->Switch TO AVR\n")); shared_memory_init(); irq_init(); if (usb_trans.loader_enabled) { boot_startup_rom(50); } else { system_set_bus_avr(); system_send_snes_reset(); } globals_init(); } return 0; }