示例#1
0
文件: composite.c 项目: a1ien/nuttx
void composite_uninitialize(FAR void *handle)
{
  FAR struct composite_alloc_s *alloc = (FAR struct composite_alloc_s *)handle;
  FAR struct composite_dev_s *priv;

  DEBUGASSERT(alloc != NULL);

  /* First phase uninitialization each of the member classes */

  priv = &alloc->dev;

  DEV1_UNINITIALIZE(priv->dev1);
  DEV2_UNINITIALIZE(priv->dev2);

  /* Then unregister and destroy the composite class */

  usbdev_unregister(&alloc->drvr.drvr);

  /* Free any resources used by the composite driver */
  /* None */

  /* Second phase uninitialization:  Clean up all memory resources */

  DEV1_UNINITIALIZE(priv->dev1);
  DEV2_UNINITIALIZE(priv->dev2);

  /* Then free the composite driver state structure itself */

  kmm_free(priv);
}
示例#2
0
文件: apb-es1.c 项目: KimMui/GDMAC
int usbdev_apbinitialize(struct apbridge_usb_driver *driver)
{
    struct apbridge_alloc_s *alloc;
    struct apbridge_dev_s *priv;
    struct apbridge_driver_s *drvr;
    int ret;

    /* Allocate the structures needed */

    alloc = (struct apbridge_alloc_s *)
        kmm_malloc(sizeof(struct apbridge_alloc_s));
    if (!alloc) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_ALLOCDEVSTRUCT), 0);
        return -ENOMEM;
    }

    /* Convenience pointers into the allocated blob */

    priv = &alloc->dev;
    drvr = &alloc->drvr;

    /* Initialize the USB driver structure */

    memset(priv, 0, sizeof(struct apbridge_dev_s));
    priv->driver = driver;

    /* Initialize the USB class driver structure */

    drvr->drvr.speed = USB_SPEED_HIGH;
    drvr->drvr.ops = &g_driverops;
    drvr->dev = priv;

    /* Register the USB serial class driver */

    ret = usbdev_register(&drvr->drvr);
    if (ret) {
        usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_DEVREGISTER),
                 (uint16_t) - ret);
        goto errout_with_alloc;
    }
    ret = priv->driver->init(priv);
    if (ret)
        goto errout_with_init;

    /* Register the single port supported by this implementation */
    return OK;

 errout_with_init:
    usbdev_unregister(&drvr->drvr);
 errout_with_alloc:
    kmm_free(alloc);
    return ret;
}
示例#3
0
void usbmsc_uninitialize(FAR void *handle)
{
	FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
	FAR struct usbmsc_dev_s *priv;
	irqstate_t flags;
#if 0
	void *value;
#endif
	int i;

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

	priv = &alloc->dev;

#ifdef CONFIG_USBMSC_COMPOSITE
	/* Check for pass 2 uninitialization.  We did most of the work on the
	 * first pass uninitialization.
	 */

	if (priv->thpid == 0) {
		/* In this second and final pass, all that remains to be done is to
		 * free the memory resources.
		 */

		kmm_free(priv);
		return;
	}
#endif

	/* If the thread hasn't already exitted, tell it to exit now */

	if (priv->thstate != USBMSC_STATE_NOTSTARTED) {
		/* The thread was started.. Is it still running? */

		usbmsc_scsi_lock(priv);
		if (priv->thstate != USBMSC_STATE_TERMINATED) {
			/* Yes.. Ask the thread to stop */

			flags = irqsave();
			priv->theventset |= USBMSC_EVENT_TERMINATEREQUEST;
			usbmsc_scsi_signal(priv);
			irqrestore(flags);
		}

		usbmsc_scsi_unlock(priv);

		/* Wait for the thread to exit */

		while ((priv->theventset & USBMSC_EVENT_TERMINATEREQUEST) != 0) {
			usbmsc_sync_wait(priv);
		}
	}

	priv->thpid = 0;

	/* Unregister the driver (unless we are a part of a composite device) */

#ifndef CONFIG_USBMSC_COMPOSITE
	usbdev_unregister(&alloc->drvr.drvr);
#endif

	/* Uninitialize and release the LUNs */

	for (i = 0; i < priv->nluns; ++i) {
		usbmsc_lununinitialize(&priv->luntab[i]);
	}

	kmm_free(priv->luntab);

	/* Release the I/O buffer */

	if (priv->iobuffer) {
		kmm_free(priv->iobuffer);
	}

	/* Uninitialize and release the driver structure */

	sem_destroy(&priv->thsynch);
	sem_destroy(&priv->thlock);
	sem_destroy(&priv->thwaitsem);

#ifndef CONFIG_USBMSC_COMPOSITE
	/* For the case of the composite driver, there is a two pass
	 * uninitialization sequence.  We cannot yet free the driver structure.
	 * We will do that on the second pass (and we will know that it is the
	 * second pass because of priv->thpid == 0)
	 */

	kmm_free(priv);
#endif
}
示例#4
0
void usbstrg_uninitialize(FAR void *handle)
{
  FAR struct usbstrg_alloc_s *alloc = (FAR struct usbstrg_alloc_s *)handle;
  FAR struct usbstrg_dev_s *priv;
  irqstate_t flags;
#ifdef SDCC
  pthread_addr_t result1, result2;
  pthread_attr_t attr;
#endif
  void *value;
  int ret;
  int i;

#ifdef CONFIG_DEBUG
  if (!handle)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_UNINITIALIZEINVALIDARGS), 0);
      return;
    }
#endif
  priv = &alloc->dev;

  /* If the thread hasn't already exitted, tell it to exit now */

  if (priv->thstate != USBSTRG_STATE_NOTSTARTED)
    {
       /* The thread was started.. Is it still running? */

      pthread_mutex_lock(&priv->mutex);
      if (priv->thstate != USBSTRG_STATE_TERMINATED)
        {
          /* Yes.. Ask the thread to stop */

          flags = irqsave();
          priv->theventset |= USBSTRG_EVENT_TERMINATEREQUEST;
          pthread_cond_signal(&priv->cond);
          irqrestore(flags);
        }
      pthread_mutex_unlock(&priv->mutex);

      /* Wait for the thread to exit.  This is necessary even if the
       * thread has already exitted in order to collect the join
       * garbage
       */

      ret = pthread_join(priv->thread, &value);
    }
  priv->thread = 0;

  /* Unregister the driver */

  usbdev_unregister(&alloc->drvr.drvr);

  /* Uninitialize and release the LUNs */

  for (i = 0; i < priv->nluns; ++i)
    {
      usbstrg_lununinitialize(&priv->luntab[i]);
    }
  kfree(priv->luntab);

  /* Release the I/O buffer */

  if (priv->iobuffer)
    {
      kfree(priv->iobuffer);
    }

  /* Uninitialize and release the driver structure */

  pthread_mutex_destroy(&priv->mutex);
  pthread_cond_destroy(&priv->cond);

  kfree(priv);
}