Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev)
{
  DEBUGASSERT(g_composite.mschandle != NULL);
  usbmsc_uninitialize(g_composite.mschandle);
}
Ejemplo n.º 3
0
int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
{
  int ret;

  DEBUGASSERT(g_composite.mschandle == NULL);

  /* Initialize USB trace output IDs */

  usbtrace_enable(TRACE_BITSET);
  check_test_memory_usage("After usbtrace_enable()");

  /* Configure the mass storage device */

  printf("board_mscclassobject: Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS);
  ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_composite.mschandle);
  if (ret < 0)
    {
      printf("board_mscclassobject: usbmsc_configure failed: %d\n", -ret);
      return ret;
    }

  printf("board_mscclassobject: MSC handle=%p\n", g_composite.mschandle);
  check_test_memory_usage("After usbmsc_configure()");

  /* Bind the LUN(s) */

  printf("board_mscclassobject: Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1);
  ret = usbmsc_bindlun(g_composite.mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, 0, 0, 0, false);
  if (ret < 0)
    {
      printf("board_mscclassobject: usbmsc_bindlun failed for LUN 1 using %s: %d\n",
               CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret);
      usbmsc_uninitialize(g_composite.mschandle);
      return ret;
    }

  check_test_memory_usage("After usbmsc_bindlun()");

#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1

  printf("board_mscclassobject: Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2);
  ret = usbmsc_bindlun(g_composite.mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, 1, 0, 0, false);
  if (ret < 0)
    {
      printf("board_mscclassobject: usbmsc_bindlun failed for LUN 2 using %s: %d\n",
               CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret);
      usbmsc_uninitialize(g_composite.mschandle);
      return ret;
    }

  check_test_memory_usage("After usbmsc_bindlun() #2");

#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2

  printf("board_mscclassobject: Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3);
  ret = usbmsc_bindlun(g_composite.mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, 2, 0, 0, false);
  if (ret < 0)
    {
      printf("board_mscclassobject: usbmsc_bindlun failed for LUN 3 using %s: %d\n",
               CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret);
      usbmsc_uninitialize(g_composite.mschandle);
      return ret;
    }

  check_test_memory_usage("After usbmsc_bindlun() #3");

#endif
#endif

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

  ret = usbmsc_classobject(g_composite.mschandle, classdev);
  if (ret < 0)
    {
      printf("board_mscclassobject: usbmsc_classobject failed: %d\n", -ret);
      usbmsc_uninitialize(g_composite.mschandle);
    }

  check_test_memory_usage("After usbmsc_classobject()");
  return ret;
}
Ejemplo n.º 4
0
int usbmsc_configure(unsigned int nluns, void **handle)
{
	FAR struct usbmsc_alloc_s *alloc;
	FAR struct usbmsc_dev_s *priv;
	FAR struct usbmsc_driver_s *drvr;
	int ret;

#ifdef CONFIG_DEBUG
	if (nluns > 15) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_TOOMANYLUNS), 0);
		return -EDOM;
	}
#endif

	/* Allocate the structures needed */

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

	/* Initialize the USB storage driver structure */

	priv = &alloc->dev;
	memset(priv, 0, sizeof(struct usbmsc_dev_s));

	/* Initialize semaphores */
	sem_init(&priv->thsynch, 0, 0);
	sem_init(&priv->thlock, 0, 1);
	sem_init(&priv->thwaitsem, 0, 0);

	/*
	 * The thsynch and thwaitsem semaphores are used for signaling and,
	 * hence, should not have priority inheritance enabled.
	 */
	sem_setprotocol(&priv->thsynch, SEM_PRIO_NONE);
	sem_setprotocol(&priv->thwaitsem, SEM_PRIO_NONE);

	sq_init(&priv->wrreqlist);

	priv->nluns = nluns;

	/* Allocate the LUN table */

	priv->luntab = (FAR struct usbmsc_lun_s *)
				   kmm_malloc(priv->nluns * sizeof(struct usbmsc_lun_s));

	if (!priv->luntab) {
		ret = -ENOMEM;
		goto errout;
	}

	memset(priv->luntab, 0, priv->nluns * sizeof(struct usbmsc_lun_s));

	/* Initialize the USB class driver structure */

	drvr = &alloc->drvr;
#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;

	/* Return the handle and success */

	*handle = (FAR void *)alloc;
	return OK;

errout:
	usbmsc_uninitialize(alloc);
	return ret;
}
int usbmsc_configure(unsigned int nluns, void **handle)
{
  FAR struct usbmsc_alloc_s  *alloc;
  FAR struct usbmsc_dev_s    *priv;
  FAR struct usbmsc_driver_s *drvr;
  int ret;

#ifdef CONFIG_DEBUG
  if (nluns > 15)
    {
      usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_TOOMANYLUNS), 0);
      return -EDOM;
    }
#endif

  /* Allocate the structures needed */

  alloc = (FAR struct usbmsc_alloc_s*)kmalloc(sizeof(struct usbmsc_alloc_s));
  if (!alloc)
    {
      usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCDEVSTRUCT), 0);
      return -ENOMEM;
    }

  /* Initialize the USB storage driver structure */

  priv = &alloc->dev;
  memset(priv, 0, sizeof(struct usbmsc_dev_s));

  pthread_mutex_init(&priv->mutex, NULL);
  pthread_cond_init(&priv->cond, NULL);
  sq_init(&priv->wrreqlist);

  priv->nluns = nluns;

  /* Allocate the LUN table */

  priv->luntab = (struct usbmsc_lun_s*)kmalloc(priv->nluns*sizeof(struct usbmsc_lun_s));
  if (!priv->luntab)
    {
      ret = -ENOMEM;
      goto errout;
    }

  memset(priv->luntab, 0, priv->nluns * sizeof(struct usbmsc_lun_s));

  /* Initialize the USB class driver structure */

  drvr             = &alloc->drvr;
#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;

  /* Return the handle and success */

  *handle = (FAR void*)alloc;
  return OK;

errout:
  usbmsc_uninitialize(alloc);
  return ret;
}
Ejemplo n.º 6
0
static void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev)
{
  DEBUGASSERT(g_mschandle != NULL);
  usbmsc_uninitialize(g_mschandle);
  g_mschandle = NULL;
}