Exemplo n.º 1
0
int usbstrg_exportluns(FAR void *handle)
{
  FAR struct usbstrg_alloc_s *alloc = (FAR struct usbstrg_alloc_s *)handle;
  FAR struct usbstrg_dev_s *priv;
  FAR struct usbstrg_driver_s *drvr;
  irqstate_t flags;
#ifdef SDCC
  pthread_attr_t attr;
#endif
  int ret;

#ifdef CONFIG_DEBUG
  if (!alloc)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_EXPORTLUNSINVALIDARGS), 0);
      return -ENXIO;
    }
#endif

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

  /* Start the worker thread */

  pthread_mutex_lock(&priv->mutex);
  priv->thstate    = USBSTRG_STATE_NOTSTARTED;
  priv->theventset = USBSTRG_EVENT_NOEVENTS;

#ifdef SDCC
  (void)pthread_attr_init(&attr);
  ret = pthread_create(&priv->thread, &attr, usbstrg_workerthread, (pthread_addr_t)priv);
#else
  ret = pthread_create(&priv->thread, NULL, usbstrg_workerthread, (pthread_addr_t)priv);
#endif
  if (ret != OK)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_THREADCREATE), (uint16_t)-ret);
      goto errout_with_mutex;
    }

  /* Register the USB storage class driver */

  ret = usbdev_register(&drvr->drvr);
  if (ret != OK)
    {
      usbtrace(TRACE_CLSERROR(USBSTRG_TRACEERR_DEVREGISTER), (uint16_t)-ret);
      goto errout_with_mutex;
    }

  /* Signal to start the thread */

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

errout_with_mutex:
  pthread_mutex_unlock(&priv->mutex);
  return ret;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
FAR void *composite_initialize(void)
{
  FAR struct composite_alloc_s *alloc;
  FAR struct composite_dev_s *priv;
  FAR struct composite_driver_s *drvr;
  int ret;

  /* Allocate the structures needed */

  alloc = (FAR struct composite_alloc_s *)kmm_malloc(sizeof(struct composite_alloc_s));
  if (!alloc)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCDEVSTRUCT), 0);
      return NULL;
    }

  /* Convenience pointers into the allocated blob */

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

  /* Initialize the USB composite driver structure */

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

  /* Get the constitueat class driver objects */

  ret = DEV1_CLASSOBJECT(&priv->dev1);
  if (ret < 0)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_CLASSOBJECT), (uint16_t)-ret);
      goto errout_with_alloc;
    }

  ret = DEV2_CLASSOBJECT(&priv->dev2);
  if (ret < 0)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_CLASSOBJECT), (uint16_t)-ret);
      goto errout_with_alloc;
    }

  /* Initialize the USB class driver structure */

#ifdef CONFIG_USBDEV_DUALSPEED
  drvr->drvr.speed         = USB_SPEED_HIGH;
#else
  drvr->drvr.speed         = USB_SPEED_FULL;
#endif
  drvr->drvr.ops           = &g_driverops;
  drvr->dev                = priv;

  /* Register the USB composite class driver */

  ret = usbdev_register(&drvr->drvr);
  if (ret)
    {
      usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_DEVREGISTER), (uint16_t)-ret);
      goto errout_with_alloc;
    }

  return (FAR void *)alloc;

errout_with_alloc:
  kmm_free(alloc);
  return NULL;
}
Exemplo n.º 4
0
static
#endif
int usbmsc_exportluns(FAR void *handle)
{
	FAR struct usbmsc_alloc_s *alloc = (FAR struct usbmsc_alloc_s *)handle;
	FAR struct usbmsc_dev_s *priv;
#ifndef CONFIG_USBMSC_COMPOSITE
	FAR struct usbmsc_driver_s *drvr;
#endif
	irqstate_t flags;
	int ret = OK;

#ifdef CONFIG_DEBUG
	if (!alloc) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_EXPORTLUNSINVALIDARGS), 0);
		return -ENXIO;
	}
#endif

	priv = &alloc->dev;
#ifndef CONFIG_USBMSC_COMPOSITE
	drvr = &alloc->drvr;
#endif

	/* Start the worker thread
	 *
	 * REVISIT:  g_usbmsc_handoff is a global and, hence, really requires
	 * some protection against re-entrant usage.
	 */

	usbmsc_scsi_lock(priv);

	priv->thstate = USBMSC_STATE_NOTSTARTED;
	priv->theventset = USBMSC_EVENT_NOEVENTS;

	g_usbmsc_handoff = priv;

	uvdbg("Starting SCSI worker thread\n");
	priv->thpid = kernel_thread("scsid", CONFIG_USBMSC_SCSI_PRIO, CONFIG_USBMSC_SCSI_STACKSIZE, usbmsc_scsi_main, NULL);
	if (priv->thpid <= 0) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_THREADCREATE), (uint16_t)errno);
		goto errout_with_lock;
	}

	/* Wait for the worker thread to run and initialize */

	uvdbg("Waiting for the SCSI worker thread\n");
	usbmsc_sync_wait(priv);
	DEBUGASSERT(g_usbmsc_handoff == NULL);

	/* Register the USB storage class driver (unless we are part of a composite device) */

#ifndef CONFIG_USBMSC_COMPOSITE
	ret = usbdev_register(&drvr->drvr);
	if (ret != OK) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_DEVREGISTER), (uint16_t)-ret);
		goto errout_with_lock;
	}
#endif

	/* Signal to start the thread */

	uvdbg("Signalling for the SCSI worker thread\n");
	flags = irqsave();
	priv->theventset |= USBMSC_EVENT_READY;
	usbmsc_scsi_signal(priv);
	irqrestore(flags);

errout_with_lock:
	usbmsc_scsi_unlock(priv);
	return ret;
}