コード例 #1
0
static void usbmsc_disconnect(FAR struct usbdevclass_driver_s *driver,
                              FAR struct usbdev_s *dev)
{
  struct usbmsc_dev_s *priv;
  irqstate_t flags;

  usbtrace(TRACE_CLASSDISCONNECT, 0);

#ifdef CONFIG_DEBUG
  if (!driver || !dev || !dev->ep0)
    {
      usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DISCONNECTINVALIDARGS), 0);
      return;
     }
#endif

  /* Extract reference to private data */

  priv = ((FAR struct usbmsc_driver_s *)driver)->dev;

#ifdef CONFIG_DEBUG
  if (!priv)
    {
      usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EP0NOTBOUND3), 0);
      return;
    }
#endif

  /* Reset the configuration */

  flags = irqsave();
  usbmsc_resetconfig(priv);

  /* Signal the worker thread */

  priv->theventset |= USBMSC_EVENT_DISCONNECT;
  pthread_cond_signal(&priv->cond);
  irqrestore(flags);

  /* Perform the soft connect function so that we will we can be
   * re-enumerated (unless we are part of a composite device)
   */

#ifndef CONFIG_USBMSC_COMPOSITE
  DEV_CONNECT(dev);
#endif
}
コード例 #2
0
ファイル: apb-es1.c プロジェクト: KimMui/GDMAC
static void usbclass_disconnect(struct usbdevclass_driver_s *driver,
                                struct usbdev_s *dev)
{
    struct apbridge_dev_s *priv;
    irqstate_t flags;

    usbtrace(TRACE_CLASSDISCONNECT, 0);

#ifdef CONFIG_DEBUG
    if (!driver || !dev || !dev->ep0) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_INVALIDARG), 0);
        return;
    }
#endif

    /* Extract reference to private data */

    priv = ((struct apbridge_driver_s *)driver)->dev;

#ifdef CONFIG_DEBUG
    if (!priv) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EP0NOTBOUND), 0);
        return;
    }
#endif

    /* Inform the "upper half serial driver that we have lost the USB serial
     * connection.
     */

    flags = irqsave();

    /* Reset the configuration */

    usbclass_resetconfig(priv);

    /* Clear out all outgoing data in the circular buffer */

    irqrestore(flags);

    /* Perform the soft connect function so that we will we can be
     * re-enumerated.
     */

    DEV_CONNECT(dev);
}
コード例 #3
0
ファイル: composite.c プロジェクト: a1ien/nuttx
static void composite_disconnect(FAR struct usbdevclass_driver_s *driver,
                                 FAR struct usbdev_s *dev)
{
  FAR struct composite_dev_s *priv;
  irqstate_t flags;

  usbtrace(TRACE_CLASSDISCONNECT, 0);

#ifdef CONFIG_DEBUG_FEATURES
  if (!driver || !dev)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_INVALIDARG), 0);
      return;
     }
#endif

  /* Extract reference to private data */

  priv = ((FAR struct composite_driver_s *)driver)->dev;

#ifdef CONFIG_DEBUG_FEATURES
  if (!priv)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_EP0NOTBOUND), 0);
      return;
    }
#endif

  /* Reset the configuration and inform the constituent class drivers of
   * the disconnection.
   */

  flags = enter_critical_section();
  priv->config = COMPOSITE_CONFIGIDNONE;
  CLASS_DISCONNECT(priv->dev1, dev);
  CLASS_DISCONNECT(priv->dev2, dev);
  leave_critical_section(flags);

  /* Perform the soft connect function so that we will we can be
   * re-enumerated.
   */

  DEV_CONNECT(dev);
}
コード例 #4
0
static void usbstrg_disconnect(FAR struct usbdev_s *dev)
{
  struct usbstrg_dev_s *priv;
  irqstate_t flags;

  usbtrace(TRACE_CLASSDISCONNECT, 0);

#ifdef CONFIG_DEBUG
  if (!dev || !dev->ep0)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_DISCONNECTINVALIDARGS), 0);
      return;
     }
#endif

  /* Extract reference to private data */

  priv = (FAR struct usbstrg_dev_s *)dev->ep0->priv;

#ifdef CONFIG_DEBUG
  if (!priv)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_EP0NOTBOUND3), 0);
      return;
    }
#endif

  /* Reset the configuration */

  flags = irqsave();
  usbstrg_resetconfig(priv);

  /* Signal the worker thread */

  priv->theventset |= USBSTRG_EVENT_DISCONNECT;
  pthread_cond_signal(&priv->cond);
  irqrestore(flags);

  /* Perform the soft connect function so that we will we can be
   * re-enumerated.
   */

  DEV_CONNECT(dev); 
}
コード例 #5
0
ファイル: composite.c プロジェクト: a1ien/nuttx
static int composite_bind(FAR struct usbdevclass_driver_s *driver,
                          FAR struct usbdev_s *dev)
{
  FAR struct composite_dev_s *priv = ((FAR struct composite_driver_s *)driver)->dev;
  int ret;

  usbtrace(TRACE_CLASSBIND, 0);

  /* Bind the structures */

  priv->usbdev   = dev;

  /* Save the reference to our private data structure in EP0 so that it
   * can be recovered in ep0 completion events.
   */

  dev->ep0->priv = priv;

  /* Preallocate one control request */

  priv->ctrlreq = composite_allocreq(dev->ep0, COMPOSITE_CFGDESCSIZE);
  if (priv->ctrlreq == NULL)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCCTRLREQ), 0);
      ret = -ENOMEM;
      goto errout;
    }

  /* Initialize the pre-allocated control request */

  priv->ctrlreq->callback = composite_ep0incomplete;

  /* Then bind each of the constituent class drivers */

  ret = CLASS_BIND(priv->dev1, dev);
  if (ret < 0)
    {
      goto errout;
    }

  ret = CLASS_BIND(priv->dev2, dev);
  if (ret < 0)
    {
      goto errout;
    }

  /* Report if we are selfpowered */

#ifdef CONFIG_USBDEV_SELFPOWERED
  DEV_SETSELFPOWERED(dev);
#endif

  /* And pull-up the data line for the soft connect function */

  DEV_CONNECT(dev);
  return OK;

errout:
  composite_unbind(driver, dev);
  return ret;
}
コード例 #6
0
ファイル: usbmsc.c プロジェクト: drashti304/TizenRT
static int usbmsc_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev)
{
	FAR struct usbmsc_dev_s *priv = ((FAR struct usbmsc_driver_s *)driver)->dev;
	FAR struct usbmsc_req_s *reqcontainer;
	irqstate_t flags;
	int ret = OK;
	int i;

	usbtrace(TRACE_CLASSBIND, 0);

	/* Bind the structures */

	priv->usbdev = dev;

	/* Save the reference to our private data structure in EP0 so that it
	 * can be recovered in ep0 completion events (Unless we are part of
	 * a composite device and, in that case, the composite device owns
	 * EP0).
	 */

#ifndef CONFIG_USBMSC_COMPOSITE
	dev->ep0->priv = priv;
#endif

	/* The configured EP0 size should match the reported EP0 size.  We could
	 * easily adapt to the reported EP0 size, but then we could not use the
	 * const, canned descriptors.
	 */

	DEBUGASSERT(CONFIG_USBMSC_EP0MAXPACKET == dev->ep0->maxpacket);

	/* Preallocate control request */

	priv->ctrlreq = usbmsc_allocreq(dev->ep0, USBMSC_MXDESCLEN);
	if (priv->ctrlreq == NULL) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCCTRLREQ), 0);
		ret = -ENOMEM;
		goto errout;
	}

	priv->ctrlreq->callback = usbmsc_ep0incomplete;

	/* Pre-allocate all endpoints... the endpoints will not be functional
	 * until the SET CONFIGURATION request is processed in usbmsc_setconfig.
	 * This is done here because there may be calls to kmm_malloc and the SET
	 * CONFIGURATION processing probably occurrs within interrupt handling
	 * logic where kmm_malloc calls will fail.
	 */

	/* Pre-allocate the IN bulk endpoint */

	priv->epbulkin = DEV_ALLOCEP(dev, USBMSC_EPINBULK_ADDR, true, USB_EP_ATTR_XFER_BULK);
	if (!priv->epbulkin) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKINALLOCFAIL), 0);
		ret = -ENODEV;
		goto errout;
	}

	priv->epbulkin->priv = priv;

	/* Pre-allocate the OUT bulk endpoint */

	priv->epbulkout = DEV_ALLOCEP(dev, USBMSC_EPOUTBULK_ADDR, false, USB_EP_ATTR_XFER_BULK);
	if (!priv->epbulkout) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EPBULKOUTALLOCFAIL), 0);
		ret = -ENODEV;
		goto errout;
	}

	priv->epbulkout->priv = priv;

	/* Pre-allocate read requests */

	for (i = 0; i < CONFIG_USBMSC_NRDREQS; i++) {
		reqcontainer = &priv->rdreqs[i];
		reqcontainer->req = usbmsc_allocreq(priv->epbulkout, CONFIG_USBMSC_BULKOUTREQLEN);
		if (reqcontainer->req == NULL) {
			usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDALLOCREQ), (uint16_t)-ret);
			ret = -ENOMEM;
			goto errout;
		}
		reqcontainer->req->priv = reqcontainer;
		reqcontainer->req->callback = usbmsc_rdcomplete;
	}

	/* Pre-allocate write request containers and put in a free list */

	for (i = 0; i < CONFIG_USBMSC_NWRREQS; i++) {
		reqcontainer = &priv->wrreqs[i];
		reqcontainer->req = usbmsc_allocreq(priv->epbulkin, CONFIG_USBMSC_BULKINREQLEN);
		if (reqcontainer->req == NULL) {
			usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRALLOCREQ), (uint16_t)-ret);
			ret = -ENOMEM;
			goto errout;
		}
		reqcontainer->req->priv = reqcontainer;
		reqcontainer->req->callback = usbmsc_wrcomplete;

		flags = irqsave();
		sq_addlast((FAR sq_entry_t *)reqcontainer, &priv->wrreqlist);
		irqrestore(flags);
	}

	/* Report if we are selfpowered (unless we are part of a composite device) */

#ifndef CONFIG_USBMSC_COMPOSITE
#ifdef CONFIG_USBDEV_SELFPOWERED
	DEV_SETSELFPOWERED(dev);
#endif

	/* And pull-up the data line for the soft connect function (unless we are
	 * part of a composite device)
	 */

	DEV_CONNECT(dev);
#endif
	return OK;

errout:
	usbmsc_unbind(driver, dev);
	return ret;
}
コード例 #7
0
ファイル: apb-es1.c プロジェクト: KimMui/GDMAC
static int usbclass_bind(struct usbdevclass_driver_s *driver,
                         struct usbdev_s *dev)
{
    struct apbridge_dev_s *priv = ((struct apbridge_driver_s *)driver)->dev;
    struct apbridge_req_s *reqcontainer;
    int ret;

    usbtrace(TRACE_CLASSBIND, 0);

    /* Bind the structures */

    priv->usbdev = dev;

    /* Save the reference to our private data structure in EP0 so that it
     * can be recovered in ep0 completion events (Unless we are part of
     * a composite device and, in that case, the composite device owns
     * EP0).
     */

    dev->ep0->priv = priv;

    /* Preallocate control request */

    priv->ctrlreq = usbclass_allocreq(dev->ep0, APBRIDGE_MXDESCLEN);
    if (priv->ctrlreq == NULL) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCCTRLREQ), 0);
        ret = -ENOMEM;
        goto errout;
    }
    priv->ctrlreq->callback = usbclass_ep0incomplete;

    /* Pre-allocate all endpoints... the endpoints will not be functional
     * until the SET CONFIGURATION request is processed in usbclass_setconfig.
     * This is done here because there may be calls to kmm_malloc and the SET
     * CONFIGURATION processing probably occurrs within interrupt handling
     * logic where kmm_malloc calls will fail.
     */

    /* Pre-allocate the IN interrupt endpoint */

    priv->epintin =
        DEV_ALLOCEP(dev, APBRIDGE_EPINTIN_ADDR, true, USB_EP_ATTR_XFER_INT);
    if (!priv->epintin) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPINTINALLOCFAIL), 0);
        ret = -ENODEV;
        goto errout;
    }
    priv->epintin->priv = priv;

    /* Pre-allocate the IN bulk endpoint */

    priv->epbulkin =
        DEV_ALLOCEP(dev, APBRIDGE_EPINBULK_ADDR, true, USB_EP_ATTR_XFER_BULK);
    if (!priv->epbulkin) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKINALLOCFAIL), 0);
        ret = -ENODEV;
        goto errout;
    }
    priv->epbulkin->priv = priv;

    /* Pre-allocate the OUT bulk endpoint */

    priv->epbulkout =
        DEV_ALLOCEP(dev, APBRIDGE_EPOUTBULK_ADDR, false,
                    USB_EP_ATTR_XFER_BULK);
    if (!priv->epbulkout) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_EPBULKOUTALLOCFAIL), 0);
        ret = -ENODEV;
        goto errout;
    }
    priv->epbulkout->priv = priv;

    reqcontainer = &priv->intreq;
    reqcontainer->req =
        usbclass_allocreq(priv->epintin, APBRIDGE_EPINTIN_MXPACKET);
    reqcontainer->req->priv = reqcontainer;
    reqcontainer->req->callback = usbclass_intcomplete;
    reqcontainer = &priv->rdreq;
    reqcontainer->req =
        usbclass_allocreq(priv->epbulkout, APBRIDGE_BULK_MXPACKET);
    reqcontainer->req->priv = reqcontainer;
    reqcontainer->req->callback = usbclass_rdcomplete;
    reqcontainer = &priv->wrreq;
    reqcontainer->req =
        usbclass_allocreq(priv->epbulkin, APBRIDGE_BULK_MXPACKET);
    reqcontainer->req->priv = reqcontainer;
    reqcontainer->req->callback = usbclass_wrcomplete;

    /* Report if we are selfpowered */

#ifdef CONFIG_USBDEV_SELFPOWERED
    DEV_SETSELFPOWERED(dev);
#endif

    /* And pull-up the data line for the soft connect function */

    DEV_CONNECT(dev);
    return OK;

 errout:

    /* 
     * One endpoint allocation fail.
     * Release the endpoints which were allocated.
     */

    usbclass_unbind(driver, dev);
    return ret;
}