示例#1
0
static int tweak_reset_device_cmd(struct urb *urb)
{
	struct usb_ctrlrequest *req;
	__u16 value;
	__u16 index;
	int ret;

	req = (struct usb_ctrlrequest *) urb->setup_packet;
	value = le16_to_cpu(req->wValue);
	index = le16_to_cpu(req->wIndex);
#if 0	/* hided by tf, for reason that "bus_id" isn't supported in kernel2.6.31 */
	uinfo("reset_device (port %d) to %s\n", index, urb->dev->dev.bus_id);
#endif

	/* all interfaces should be owned by usbip driver, so just reset it. */
	ret = usb_lock_device_for_reset(urb->dev, NULL);
	if (ret < 0) {
		uerr("lock for reset\n");
		return ret;
	}
#if 0	/* hided it temporarily */
	/* try to reset the device */
	ret = usb_reset_composite_device(urb->dev, NULL);
	if (ret < 0)
		uerr("device reset\n");
#endif
	usb_unlock_device(urb->dev);

	return ret;
}
示例#2
0
static int valid_args(__u32 rhport, __u32 busnum, __u32 devnum,
		enum usb_device_speed speed)
{
	/* check rhport */
	if ((rhport < 0) || (rhport >= VHCI_NPORTS)) {
		uerr("port %u\n", rhport);
		return -EINVAL;
	}

	/* check busnum & devnum */
	if ((busnum <= 0) || (busnum >= 128) || (devnum <= 0) || (devnum >= 128)) {
		uerr("busnum %u devnum %u\n", busnum, devnum);
		return -EINVAL;
	}

	/* check speed */
	switch(speed) {
		case USB_SPEED_LOW:
		case USB_SPEED_FULL:
		case USB_SPEED_HIGH:
		case USB_SPEED_VARIABLE:
			break;

		default:
			uerr("speed %d\n", speed);
			return -EINVAL;
	}

	return 0;
}
示例#3
0
文件: stub_rx.c 项目: pjump/usbip
static int tweak_reset_device_cmd(struct urb *urb)
{
	struct usb_ctrlrequest *req;
	__u16 value;
	__u16 index;
	int ret;

	req = (struct usb_ctrlrequest *) urb->setup_packet;
	value = le16_to_cpu(req->wValue);
	index = le16_to_cpu(req->wIndex);

	uinfo("reset_device (port %d) to %s\n", index, urb->dev->dev.bus->name);

	/* all interfaces should be owned by usbip driver, so just reset it. */
	ret = usb_lock_device_for_reset(urb->dev, NULL);
	if (ret < 0) {
		uerr("lock for reset\n");
		return ret;
	}

	/* try to reset the device */
	ret = usb_reset_device(urb->dev);
	if (ret < 0)
		uerr("device reset\n");

	usb_unlock_device(urb->dev);

	return ret;
}
示例#4
0
ssize_t socket_to_addrstr(struct socket *socket, char *buf)
{
	struct sockaddr uaddr;
	int uaddrlen;
	int ret;

	ret = socket->ops->getname(socket, &uaddr, &uaddrlen, 1);
	if (ret) {
		uerr("getname failed, socket %p\n", socket);
		return ret;
	}

	if (uaddr.sa_family == AF_INET) {
		struct sockaddr_in *v4addr = (struct sockaddr_in *) &uaddr;
		ret =  sprintf(buf, "%u.%u.%u.%u", NIPQUAD(v4addr->sin_addr.s_addr));
	} else if (uaddr.sa_family == AF_INET6) {
		struct sockaddr_in6 *v6addr = (struct sockaddr_in6 *) &uaddr;
		ret =  sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
				NIP6(v6addr->sin6_addr));
	} else {
		uerr("unknown sa_family %d\n", uaddr.sa_family);
		ret = -1;
	}

	return ret;
}
示例#5
0
/* recv a pdu */
static void stub_rx_pdu(struct usbip_device *ud)
{
	int ret;
	struct usbip_header pdu;
	struct stub_device *sdev = container_of(ud, struct stub_device, ud);

	dbg_stub_rx("Enter\n");

	memset(&pdu, 0, sizeof(pdu));

	/* 1. receive a pdu header */
	dbg_stub_rx("before usbip_xmit\n");
	ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu), 0);
	dbg_stub_rx("after usbip_xmit\n");
	if (ret != sizeof(pdu)) {
		uerr("recv a header, %d\n", ret);
		usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		return;
	}

	usbip_header_correct_endian(&pdu, 0);

	if (dbg_flag_stub_rx)
		usbip_dump_header(&pdu);

	if (!valid_request(sdev, &pdu)) {
		uerr("recv invalid request\n");
		usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		return;
	}
	
#if CLIENT > 2	
	sdev->heartbeat_pending = 0;
#endif
	switch (pdu.base.command) {
		case USBIP_CMD_UNLINK:
			stub_recv_cmd_unlink(sdev, &pdu);
			break;

		case USBIP_CMD_SUBMIT:
			stub_recv_cmd_submit(sdev, &pdu);
			break;

#if CLIENT > 2	
		// added by tf, 110530
		case USBIP_HEARTBEAT_REPLY:
		    sdev->heartbeat_pending = 0;
			break;
       	 // end --- added
#endif	

		default:
			/* NOTREACHED */
			uerr("unknown pdu\n");
			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
			return;
	}

}
示例#6
0
static int get_pipe(struct stub_device *sdev, int epnum, int dir)
{
	struct usb_device *udev = interface_to_usbdev(sdev->interface);
	struct usb_host_endpoint *ep;
	struct usb_endpoint_descriptor *epd = NULL;

	ep = get_ep_from_epnum(udev, epnum);
	if (!ep) {
		uerr("no such endpoint?, %d", epnum);
		BUG();
	}

	epd = &ep->desc;


#if 0
	/* epnum 0 is always control */
	if (epnum == 0) {
		if (dir == USBIP_DIR_OUT)
			return usb_sndctrlpipe(udev, 0);
		else
			return usb_rcvctrlpipe(udev, 0);
	}
#endif

	if (usb_endpoint_xfer_control(epd)) {
		if (dir == USBIP_DIR_OUT)
			return usb_sndctrlpipe(udev, epnum);
		else
			return usb_rcvctrlpipe(udev, epnum);
	}

	if (usb_endpoint_xfer_bulk(epd)) {
		if (dir == USBIP_DIR_OUT)
			return usb_sndbulkpipe(udev, epnum);
		else
			return usb_rcvbulkpipe(udev, epnum);
	}

	if (usb_endpoint_xfer_int(epd)) {
		if (dir == USBIP_DIR_OUT)
			return usb_sndintpipe(udev, epnum);
		else
			return usb_rcvintpipe(udev, epnum);
	}

	if (usb_endpoint_xfer_isoc(epd)) {
		if (dir == USBIP_DIR_OUT)
			return usb_sndisocpipe(udev, epnum);
		else
			return usb_rcvisocpipe(udev, epnum);
	}

	/* NOT REACHED */
	uerr("get pipe, epnum %d\n", epnum);
	return 0;
}
示例#7
0
 void worhp_disp(int mode, const char message[]) {
   if (mode & WORHP_PRINT_MESSAGE) {
     uout() << message << std::endl;
   }
   if (mode & WORHP_PRINT_WARNING) {
     uerr() << message << std::endl;
   }
   if (mode & WORHP_PRINT_ERROR) {
     uerr() << message << std::endl;
   }
 }
示例#8
0
文件: stm32_usb.c 项目: a1ien/nuttx
int stm32_usbhost_initialize(void)
{
  int pid;
  int ret;

  /* First, register all of the class drivers needed to support the drivers
   * that we care about:
   */

  uinfo("Register class drivers\n");

#ifdef CONFIG_USBHOST_MSC
  /* Register the USB mass storage class class */

  ret = usbhost_msc_initialize();
  if (ret != OK)
    {
      uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
    }
#endif

#ifdef CONFIG_USBHOST_CDCACM
  /* Register the CDC/ACM serial class */

  ret = usbhost_cdcacm_initialize();
  if (ret != OK)
    {
      uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
    }
#endif

  /* Then get an instance of the USB host interface */

  uinfo("Initialize USB host\n");
  g_usbconn = stm32_otgfshost_initialize(0);
  if (g_usbconn)
    {
      /* Start a thread to handle device connection. */

      uinfo("Start usbhost_waiter\n");

      pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO,
                        CONFIG_USBHOST_STACKSIZE,
                        (main_t)usbhost_waiter, (FAR char * const *)NULL);
      return pid < 0 ? -ENOEXEC : OK;
    }

  return -ENODEV;
}
示例#9
0
/* recv a pdu */
static void stub_rx_pdu(struct usbip_device *ud)
{
	int ret;
	struct usbip_header pdu;
	struct stub_device *sdev = container_of(ud, struct stub_device, ud);


	dbg_stub_rx("Enter\n");

	memset(&pdu, 0, sizeof(pdu));


	/* 1. receive a pdu header */
	ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu),0);
	if (ret != sizeof(pdu)) {
		uerr("recv a header, %d\n", ret);
		usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		return;
	}

	usbip_header_correct_endian(&pdu, 0);

	if (dbg_flag_stub_rx)
		usbip_dump_header(&pdu);

	if (!valid_request(sdev, &pdu)) {
		uerr("recv invalid request\n");
		usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		return;
	}

	switch (pdu.base.command) {
		case USBIP_CMD_UNLINK:
			stub_recv_cmd_unlink(sdev, &pdu);
			break;

		case USBIP_CMD_SUBMIT:
			stub_recv_cmd_submit(sdev, &pdu);
			break;

		default:
			/* NOTREACHED */
			uerr("unknown pdu\n");
			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
			return;
	}

}
示例#10
0
static struct stub_priv *stub_priv_alloc(struct stub_device *sdev,
		struct usbip_header *pdu)
{
	struct stub_priv *priv;
	struct usbip_device *ud = &sdev->ud;
	unsigned long flags;

	spin_lock_irqsave(&sdev->priv_lock, flags);

	priv = kmem_cache_alloc(stub_priv_cache, GFP_ATOMIC);
	if (!priv) {
		uerr("alloc stub_priv\n");
		spin_unlock_irqrestore(&sdev->priv_lock, flags);
		usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
		return NULL;
	}

	memset(priv, 0, sizeof(struct stub_priv));

	priv->seqnum = pdu->base.seqnum;
	priv->sdev = sdev;

	/*
	 * After a stub_priv is linked to a list_head,
	 * our error handler can free allocated data.
	 */
	list_add_tail(&priv->list, &sdev->priv_init);

	spin_unlock_irqrestore(&sdev->priv_lock, flags);

	return priv;
}
示例#11
0
static int vhci_port_disconnect(__u32 rhport)
{
	struct vhci_device *vdev;

	dbg_vhci_sysfs("enter\n");

	/* lock */
	spin_lock(&the_controller->lock);

	vdev = port_to_vdev(rhport);

	spin_lock(&vdev->ud.lock);
	if (vdev->ud.status == VDEV_ST_NULL) {
		uerr("not connected %d\n", vdev->ud.status);

		/* unlock */
		spin_unlock(&vdev->ud.lock);
		spin_unlock(&the_controller->lock);

		return -EINVAL;
	}

	/* unlock */
	spin_unlock(&vdev->ud.lock);
	spin_unlock(&the_controller->lock);

	usbip_event_add(&vdev->ud, VDEV_EVENT_DOWN);

	return 0;
}
示例#12
0
  void BonminInterface::
  finalize_solution(BonminMemory* m, TMINLP::SolverReturn status,
      const double* x, double obj_value) const {
    try {
      // Get primal solution
      casadi_copy(x, nx_, m->x);

      // Get optimal cost
      m->f = obj_value;

      // Dual solution not calculated
      casadi_fill(m->lam_x, nx_, nan);
      casadi_fill(m->lam_g, ng_, nan);

      // Get the constraints
      casadi_fill(m->gk, ng_, nan);

      // Get statistics
      m->iter_count = 0;

      // Interpret return code
      m->return_status = return_status_string(status);
      m->success = status==Bonmin::TMINLP::SUCCESS;

    } catch(exception& ex) {
      uerr() << "finalize_solution failed: " << ex.what() << endl;
    }
  }
示例#13
0
  bool BonminInterface::
  get_starting_point(BonminMemory* m, bool init_x, double* x,
                     bool init_z, double* z_L, double* z_U,
                     bool init_lambda, double* lambda) const {
    try {
      // Initialize primal variables
      if (init_x) {
        casadi_copy(m->x, nx_, x);
      }

      // Initialize dual variables (simple bounds)
      if (init_z) {
        for (casadi_int i=0; i<nx_; ++i) {
          z_L[i] = max(0., -m->lam_x[i]);
          z_U[i] = max(0., m->lam_x[i]);
        }
      }

      // Initialize dual variables (nonlinear bounds)
      if (init_lambda) {
        casadi_copy(m->lam_g, ng_, lambda);
      }

      return true;
    } catch(exception& ex) {
      uerr() << "get_starting_point failed: " << ex.what() << endl;
      return false;
    }
  }
示例#14
0
static int board_mscclassobject(int minor,
                                FAR struct usbdev_devinfo_s *devinfo,
                                FAR struct usbdevclass_driver_s **classdev)
{
  int ret;

  DEBUGASSERT(g_mschandle == NULL);

  /* Configure the mass storage device */

  uinfo("Configuring with NLUNS=1\n");
  ret = usbmsc_configure(1, &g_mschandle);
  if (ret < 0)
    {
      uerr("ERROR: usbmsc_configure failed: %d\n", -ret);
      return ret;
    }

  uinfo("MSC handle=%p\n", g_mschandle);

  /* Bind the LUN(s) */

  uinfo("Bind LUN=0 to /dev/mmcsd0\n");
  ret = usbmsc_bindlun(g_mschandle, "/dev/mmcsd0", 0, 0, 0, false);
  if (ret < 0)
    {
      uerr("ERROR: usbmsc_bindlun failed for LUN 1 at /dev/mmcsd0: %d\n",
           ret);
      usbmsc_uninitialize(g_mschandle);
      g_mschandle = NULL;
      return ret;
    }

  /* Get the mass storage device's class object */

  ret = usbmsc_classobject(g_mschandle, devinfo, classdev);
  if (ret < 0)
    {
      uerr("ERROR: usbmsc_classobject failed: %d\n", -ret);
      usbmsc_uninitialize(g_mschandle);
      g_mschandle = NULL;
    }

  return ret;
}
示例#15
0
static int event_handler(struct usbip_device *ud)
{

	dbg_eh("enter\n");


	/*
	 * Events are handled by only this thread.
	 */
	while ( usbip_event_happend(ud) ) {
		dbg_eh("pending event %lx\n", ud->event);

		/*
		 * NOTE: shutdown must come first.
		 * Shutdown the device.
		 */
		if (ud->event & USBIP_EH_SHUTDOWN) {
			ud->eh_ops.shutdown(ud);

			ud->event &= ~USBIP_EH_SHUTDOWN;

			break;
		}

		/* Stop the error handler. */
		if (ud->event & USBIP_EH_BYE)
			return -1;

		/* Reset the device. */
		if (ud->event & USBIP_EH_RESET) {
			ud->eh_ops.reset(ud);

			ud->event &= ~USBIP_EH_RESET;

			break;
		}

		/* Mark the device as unusable. */
		if (ud->event & USBIP_EH_UNUSABLE) {
			ud->eh_ops.unusable(ud);

			ud->event &= ~USBIP_EH_UNUSABLE;

			break;
		}

		/* NOTREACHED */
		uerr("unknown event\n");
		return -1;
	}

	return 0;
}
示例#16
0
int set_sockaddr(struct socket *socket, struct sockaddr_storage *ss)
{
	int  addrlen;
	int  ret;

	ret = socket->ops->getname(socket, (struct sockaddr *) ss, &addrlen, 1);
	if (ret) {
		uerr("getname failed, socket %p\n", socket);
		return ret;
	}
	return ret;
}
示例#17
0
 bool BonminInterface::
 get_list_of_nonlinear_variables(int num_nonlin_vars, int* pos_nonlin_vars) const {
   try {
     for (casadi_int i=0; i<nl_ex_.size(); ++i) {
       if (nl_ex_[i]) *pos_nonlin_vars++ = i;
     }
     return true;
   } catch(exception& ex) {
     uerr() << "get_list_of_nonlinear_variables failed: " << ex.what() << endl;
     return false;
   }
 }
示例#18
0
 bool BonminInterface::
 get_bounds_info(BonminMemory* m, double* x_l, double* x_u,
                 double* g_l, double* g_u) const {
   try {
     casadi_copy(m->lbx, nx_, x_l);
     casadi_copy(m->ubx, nx_, x_u);
     casadi_copy(m->lbg, ng_, g_l);
     casadi_copy(m->ubg, ng_, g_u);
     return true;
   } catch(exception& ex) {
     uerr() << "get_bounds_info failed: " << ex.what() << endl;
     return false;
   }
 }
示例#19
0
static int tweak_reset_device_cmd(struct urb *urb)
{
	struct usb_ctrlrequest *req;
	__u16 value;
	__u16 index;
	int ret;

	req = (struct usb_ctrlrequest *) urb->setup_packet;
	value = le16_to_cpu(req->wValue);
	index = le16_to_cpu(req->wIndex);

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
	uinfo("reset_device (port %d) to %s\n", index, urb->dev->dev.bus_id);
#else
	uinfo("reset_device (port %d) to %s\n", index, dev_name(&urb->dev->dev));
#endif

	/* all interfaces should be owned by usbip driver, so just reset it. */
	ret = usb_lock_device_for_reset(urb->dev, NULL);
	if (ret < 0) {
		uerr("lock for reset\n");
		return ret;
	}

	/* try to reset the device */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
    ret = usb_reset_composite_device(urb->dev, NULL);
#else
	ret = usb_reset_device(urb->dev);
#endif
	if (ret < 0)
		uerr("device reset\n");

	usb_unlock_device(urb->dev);

	return ret;
}
示例#20
0
 int BonminInterface::get_number_of_nonlinear_variables() const {
   try {
     if (!pass_nonlinear_variables_) {
       // No Hessian has been interfaced
       return -1;
     } else {
       // Number of variables that appear nonlinearily
       int nv = 0;
       for (auto&& i : nl_ex_) if (i) nv++;
       return nv;
     }
   } catch(exception& ex) {
     uerr() << "get_number_of_nonlinear_variables failed: " << ex.what() << endl;
     return -1;
   }
 }
示例#21
0
  void BonminInterface::get_nlp_info(BonminMemory* m, int& nx, int& ng,
                                    int& nnz_jac_g, int& nnz_h_lag) const {
    try {
      // Number of variables
      nx = nx_;

      // Number of constraints
      ng = ng_;

      // Number of Jacobian nonzeros
      nnz_jac_g = ng_==0 ? 0 : jacg_sp_.nnz();

      // Number of Hessian nonzeros (only upper triangular half)
      nnz_h_lag = exact_hessian_ ? hesslag_sp_.nnz() : 0;

    } catch(exception& ex) {
      uerr() << "get_nlp_info failed: " << ex.what() << endl;
    }
  }
示例#22
0
/* some members of urb must be substituted before. */
int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
{
	void *buff;
	struct usbip_iso_packet_descriptor *iso;
	int np = urb->number_of_packets;
	int size = np * sizeof(*iso);
	int i;
	int ret;

	if (!usb_pipeisoc(urb->pipe))
		return 0;

	buff = kzalloc(size, GFP_KERNEL);
	if (!buff)
		return -ENOMEM;

	ret = usbip_xmit(0, ud->tcp_socket, buff, size, 0);
	if (ret != size) {
		uerr("recv iso_frame_descriptor, %d\n", ret);
		kfree(buff);

		if (ud->side == USBIP_STUB)
			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		else
			usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);

		return -EPIPE;
	}

	for (i = 0; i < np; i++) {
		iso = buff + (i * sizeof(*iso));

		usbip_iso_pakcet_correct_endian(iso, 0);
		usbip_pack_iso(iso, &urb->iso_frame_desc[i], 0);
	}


	kfree(buff);

	return ret;
}
示例#23
0
struct socket *sockfd_to_socket(unsigned int sockfd)
{
	struct socket *socket;
	struct file *file;
	struct inode *inode;

	file = fget(sockfd);
	if (!file) {
		uerr("invalid sockfd\n");
		return NULL;
	}

	inode = file->f_dentry->d_inode;

	if (!inode || !S_ISSOCK(inode->i_mode))
		return NULL;

	socket = SOCKET_I(inode);

	return socket;
}
示例#24
0
static ssize_t store_detach(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count) {
	int err;
	__u32 rhport = 0;

	sscanf(buf, "%u", &rhport);

	/* check rhport */
	if (rhport >= VHCI_NPORTS) {
		uerr("invalid port %u\n", rhport);
		return -EINVAL;
	}

	err = vhci_port_disconnect(rhport);
	if (err < 0) {
		return -EINVAL;
	}

	dbg_vhci_sysfs("Leave\n");
	return count;
}
示例#25
0
/* some members of urb must be substituted before. */
int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb)
{
	int ret;
	int size;

	if (ud->side == USBIP_STUB) {
		/* stub_rx.c */
		/* the direction of urb must be OUT. */
		if (usb_pipein(urb->pipe))
			return 0;

		size = urb->transfer_buffer_length;
	} else {
		/* vhci_rx.c */
		/* the direction of urb must be IN. */
		if (usb_pipeout(urb->pipe))
			return 0;

		size = urb->actual_length;
	}

	/* no need to recv xbuff */
	if (!(size > 0))
		return 0;

	ret = usbip_xmit(0, ud->tcp_socket, (char *) urb->transfer_buffer, size, 0);
	if (ret != size) {
		uerr("recv xbuf, %d\n", ret);
		if (ud->side == USBIP_STUB) {
			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		} else {
			usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
			return -EPIPE;
		}
	}

	return ret;
}
示例#26
0
int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
{
	int ret;
	char *iso_frame_desc = (char *) &urb->iso_frame_desc[0];
	int np = urb->number_of_packets;
	int size = np * sizeof(struct usb_iso_packet_descriptor);

	if (!usb_pipeisoc(urb->pipe))
		return 0;

	ret = usbip_xmit(0, ud->tcp_socket, iso_frame_desc, size, 0);
	if (ret != size ) {
		uerr("recv iso_frame_descriptor, %d\n", ret);
		if (ud->side == USBIP_STUB) {
			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
		} else {
			usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
		}
		return -EPIPE;
	}

	return ret;
}
示例#27
0
int lpc31_usbhost_initialize(void)
{
  pid_t pid;
  int ret;

  /* First, register all of the class drivers needed to support the drivers
   * that we care about
   */

#ifdef CONFIG_USBHOST_HUB
  /* Initialize USB hub support */

  ret = usbhost_hub_initialize();
  if (ret < 0)
    {
      syslog(LOG_ERR, "ERROR: usbhost_hub_initialize failed: %d\n", ret);
    }
#endif

#ifdef CONFIG_USBHOST_MSC
  /* Register theUSB host Mass Storage Class */

  ret = usbhost_msc_initialize();
  if (ret != OK)
    {
      uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
    }
#endif

#ifdef CONFIG_USBHOST_CDCACM
  /* Register the CDC/ACM serial class */

  ret = usbhost_cdcacm_initialize();
  if (ret != OK)
    {
      uerr("ERROR: Failed to register the CDC/ACM serial class\n");
    }
#endif

#ifdef CONFIG_USBHOST_HIDKBD
  /* Register the USB host HID keyboard class driver */

  ret = usbhost_kbdinit();
  if (ret != OK)
    {
      uerr("ERROR: Failed to register the KBD class\n");
    }
#endif

  /* Then get an instance of the USB EHCI interface. */

  g_ehciconn = lpc31_ehci_initialize(0);
  if (!g_ehciconn)
    {
      uerr("ERROR: lpc31_ehci_initialize failed\n");
      return -ENODEV;
    }

  /* Start a thread to handle device connection. */

  pid = task_create("EHCI Monitor", CONFIG_USBHOST_DEFPRIO,  CONFIG_USBHOST_STACKSIZE,
                    (main_t)ehci_waiter, (FAR char * const *)NULL);
  if (pid < 0)
    {
      uerr("ERROR: Failed to create ehci_waiter task: %d\n", ret);
      return -ENODEV;
    }

  return OK;
}
示例#28
0
文件: util.cpp 项目: vis15/fractions
int Error::getErrorValue()
{
    UerrorName uerr(error_name_);
    return uerr.value;
}
示例#29
0
文件: sam_usb.c 项目: a1ien/nuttx
void sam_usbhost_vbusdrive(int rhport, bool enable)
{
  pio_pinset_t pinset = 0;

  uinfo("RHPort%d: enable=%d\n", rhport+1, enable);

  /* Pick the PIO configuration associated with the selected root hub port */

  switch (rhport)
    {
    case SAM_RHPORT1:
#if !defined(CONFIG_SAMA5_UHPHS_RHPORT1)
      uerr("ERROR: RHPort1 is not available in this configuration\n");
      return;

#elif !defined(PIO_USBA_VBUS_ENABLE)
      /* SAMA5D3-Xplained has no port A VBUS enable */

      uerr("ERROR: RHPort1 has no VBUS enable\n");
      return;
#else
      pinset = PIO_USBA_VBUS_ENABLE;
      break;
#endif

    case SAM_RHPORT2:
#ifndef CONFIG_SAMA5_UHPHS_RHPORT2
      uerr("ERROR: RHPort2 is not available in this configuration\n");
      return;
#else
      pinset = PIO_USBB_VBUS_ENABLE;
      break;
#endif

    case SAM_RHPORT3:
#ifndef CONFIG_SAMA5_UHPHS_RHPORT3
      uerr("ERROR: RHPort3 is not available in this configuration\n");
      return;
#else
      pinset = PIO_USBC_VBUS_ENABLE;
      break;
#endif

    default:
      uerr("ERROR: RHPort%d is not supported\n", rhport+1);
      return;
    }

  /* Then enable or disable VBUS power (active low for SP2526A-2) */

  if (enable)
    {
      /* Enable the Power Switch by driving the enable pin low */

      sam_piowrite(pinset, false);
    }
  else
    {
      /* Disable the Power Switch by driving the enable pin high */

      sam_piowrite(pinset, true);
    }
}
示例#30
0
  bool BonminInterface::
  intermediate_callback(BonminMemory* m, const double* x, const double* z_L, const double* z_U,
                        const double* g, const double* lambda, double obj_value, int iter,
                        double inf_pr, double inf_du, double mu, double d_norm,
                        double regularization_size, double alpha_du, double alpha_pr,
                        int ls_trials, bool full_callback) const {
    m->n_iter += 1;
    try {
      if (verbose_) casadi_message("intermediate_callback started");
      m->inf_pr.push_back(inf_pr);
      m->inf_du.push_back(inf_du);
      m->mu.push_back(mu);
      m->d_norm.push_back(d_norm);
      m->regularization_size.push_back(regularization_size);
      m->alpha_pr.push_back(alpha_pr);
      m->alpha_du.push_back(alpha_du);
      m->ls_trials.push_back(ls_trials);
      m->obj.push_back(obj_value);
      if (!fcallback_.is_null()) {
        m->fstats.at("callback_fun").tic();
        if (full_callback) {
          casadi_copy(x, nx_, m->x);
          for (casadi_int i=0; i<nx_; ++i) {
            m->lam_x[i] = z_U[i]-z_L[i];
          }
          casadi_copy(lambda, ng_, m->lam_g);
          casadi_copy(g, ng_, m->gk);
        } else {
          if (iter==0) {
            uerr()
              << "Warning: intermediate_callback is disfunctional in your installation. "
              "You will only be able to use stats(). "
              "See https://github.com/casadi/casadi/wiki/enableBonminCallback to enable it."
              << endl;
          }
        }

        // Inputs
        fill_n(m->arg, fcallback_.n_in(), nullptr);
        if (full_callback) {
          // The values used below are meaningless
          // when not doing a full_callback
          m->arg[NLPSOL_X] = x;
          m->arg[NLPSOL_F] = &obj_value;
          m->arg[NLPSOL_G] = g;
          m->arg[NLPSOL_LAM_P] = nullptr;
          m->arg[NLPSOL_LAM_X] = m->lam_x;
          m->arg[NLPSOL_LAM_G] = m->lam_g;
        }

        // Outputs
        fill_n(m->res, fcallback_.n_out(), nullptr);
        double ret_double;
        m->res[0] = &ret_double;

        fcallback_(m->arg, m->res, m->iw, m->w, 0);
        int ret = static_cast<int>(ret_double);

        m->fstats.at("callback_fun").toc();
        return  !ret;
      } else {
        return 1;
      }
    } catch(KeyboardInterruptException& ex) {
      return 0;
    } catch(exception& ex) {
      if (iteration_callback_ignore_errors_) {
        uerr() << "intermediate_callback: " << ex.what() << endl;
        return 1;
      }
      return 0;
    }
  }