예제 #1
0
int msdis_main(int argc, char *argv[])
{
  /* First check if the USB mass storage device is already connected */

  if (!g_usbstrg.mshandle)
    {
      message("msdis: ERROR: Not connected\n");
      return 1;
    }
   check_test_memory_usage("Since MS connection");

  /* Then disconnect the device and uninitialize the USB mass storage driver */

   usbstrg_uninitialize(g_usbstrg.mshandle);
   g_usbstrg.mshandle = NULL;
   message("msdis: Disconnected\n");
   check_test_memory_usage("After usbstrg_uninitialize()");

   /* Dump debug memory usage */

   final_memory_usage("Final memory usage");
   return 0;
}
예제 #2
0
int user_start(int argc, char *argv[])
{
  void *handle;
  int ret;

  /* Initialize USB trace output IDs */

  usbtrace_enable(TRACE_BITSET);

  /* Register block drivers (architecture-specific) */

  message("user_start: Creating block drivers\n");
  ret = usbstrg_archinitialize();
  if (ret < 0)
    {
      message("user_start: usbstrg_archinitialize failed: %d\n", -ret);
      return 1;
    }

  /* Then exports the LUN(s) */

  message("user_start: Configuring with NLUNS=%d\n", CONFIG_EXAMPLES_USBSTRG_NLUNS);
  ret = usbstrg_configure(CONFIG_EXAMPLES_USBSTRG_NLUNS, &handle);
  if (ret < 0)
    {
      message("user_start: usbstrg_configure failed: %d\n", -ret);
      usbstrg_uninitialize(handle);
      return 2;
    }
  message("user_start: handle=%p\n", handle);

  message("user_start: Bind LUN=0 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH1);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH1, 0, 0, 0, false);
  if (ret < 0)
    {
      message("user_start: usbstrg_bindlun failed for LUN 1 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH1, -ret);
      usbstrg_uninitialize(handle);
      return 2;
    }

#if CONFIG_EXAMPLES_USBSTRG_NLUNS > 1

  message("user_start: Bind LUN=1 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH2);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH2, 1, 0, 0, false);
  if (ret < 0)
    {
      message("user_start: usbstrg_bindlun failed for LUN 2 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH2, -ret);
      usbstrg_uninitialize(handle);
      return 3;
    }

#if CONFIG_EXAMPLES_USBSTRG_NLUNS > 2

  message("user_start: Bind LUN=2 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH3);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH3, 2, 0, 0, false);
  if (ret < 0)
    {
      message("user_start: usbstrg_bindlun failed for LUN 3 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH3, -ret);
      usbstrg_uninitialize(handle);
      return 4;
    }

#endif
#endif

  ret = usbstrg_exportluns(handle);
  if (ret < 0)
    {
      message("user_start: usbstrg_exportluns failed: %d\n", -ret);
      usbstrg_uninitialize(handle);
      return 5;
    }

  /* Now just hang around and monitor the USB storage activity */

#ifndef CONFIG_DISABLE_SIGNALS
  for (;;)
    {
      msgflush();
      sleep(5);

#ifdef CONFIG_USBDEV_TRACE
      message("\nuser_start: USB TRACE DATA:\n");
      ret =  usbtrace_enumerate(usbstrg_enumerate, NULL);
      if (ret < 0)
        {
          message("user_start: usbtrace_enumerate failed: %d\n", -ret);
          usbstrg_uninitialize(handle);
          return 6;
        }
#else
      message("user_start: Still alive\n");
#endif
    }
#else
     message("user_start: Exiting\n");
 #endif
}
예제 #3
0
int usbstrg_configure(unsigned int nluns, void **handle)
{
  FAR struct usbstrg_alloc_s  *alloc;
  FAR struct usbstrg_dev_s    *priv;
  FAR struct usbstrg_driver_s *drvr;
  int ret;

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

  /* Allocate the structures needed */

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

  /* Initialize the USB storage driver structure */

  priv = &alloc->dev;
  memset(priv, 0, sizeof(struct usbstrg_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 usbstrg_lun_s*)kmalloc(priv->nluns*sizeof(struct usbstrg_lun_s));
  if (!priv->luntab)
    {
      ret = -ENOMEM;
      goto errout;
    }
  memset(priv->luntab, 0, priv->nluns * sizeof(struct usbstrg_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:
  usbstrg_uninitialize(alloc);
  return ret;
}
예제 #4
0
int MAIN_NAME(int argc, char *argv[])
{
  FAR void *handle;
  int ret;

  /* If this program is implemented as the NSH 'msconn' command, then we need to
   * do a little error checking to assure that we are not being called re-entrantly.
   */

#ifdef CONFIG_EXAMPLES_USBSTRG_BUILTIN

   /* Check if there is a non-NULL USB mass storage device handle (meaning that the
    * USB mass storage device is already configured).
    */

   if (g_usbstrg.mshandle)
     {
       message(MAIN_NAME_STRING ": ERROR: Already connected\n");
       return 1;
     }
#endif

#ifdef CONFIG_EXAMPLES_USBSTRG_DEBUGMM
#  ifdef CONFIG_CAN_PASS_STRUCTS
  g_usbstrg.mmstart    = mallinfo();
  g_usbstrg.mmprevious = g_usbstrg.mmstart;
#  else
  (void)mallinfo(&g_usbstrg.mmstart);
  memcpy(&g_usbstrg.mmprevious, &g_usbstrg.mmstart, sizeof(struct mallinfo));
#  endif
#endif

  /* Initialize USB trace output IDs */

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

  /* Register block drivers (architecture-specific) */

  message(MAIN_NAME_STRING ": Creating block drivers\n");
  ret = usbstrg_archinitialize();
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_archinitialize failed: %d\n", -ret);
      return 2;
    }
  check_test_memory_usage("After usbstrg_archinitialize()");

  /* Then exports the LUN(s) */

  message(MAIN_NAME_STRING ": Configuring with NLUNS=%d\n", CONFIG_EXAMPLES_USBSTRG_NLUNS);
  ret = usbstrg_configure(CONFIG_EXAMPLES_USBSTRG_NLUNS, &handle);
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_configure failed: %d\n", -ret);
      usbstrg_uninitialize(handle);
      return 3;
    }
  message(MAIN_NAME_STRING ": handle=%p\n", handle);
  check_test_memory_usage("After usbstrg_configure()");

  message(MAIN_NAME_STRING ": Bind LUN=0 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH1);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH1, 0, 0, 0, false);
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 1 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH1, -ret);
      usbstrg_uninitialize(handle);
      return 4;
    }
  check_test_memory_usage("After usbstrg_bindlun()");

#if CONFIG_EXAMPLES_USBSTRG_NLUNS > 1

  message(MAIN_NAME_STRING ": Bind LUN=1 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH2);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH2, 1, 0, 0, false);
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 2 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH2, -ret);
      usbstrg_uninitialize(handle);
      return 5;
    }
  check_test_memory_usage("After usbstrg_bindlun() #2");

#if CONFIG_EXAMPLES_USBSTRG_NLUNS > 2

  message(MAIN_NAME_STRING ": Bind LUN=2 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH3);
  ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH3, 2, 0, 0, false);
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 3 using %s: %d\n",
               CONFIG_EXAMPLES_USBSTRG_DEVPATH3, -ret);
      usbstrg_uninitialize(handle);
      return 6;
    }
  check_test_memory_usage("After usbstrg_bindlun() #3");

#endif
#endif

  ret = usbstrg_exportluns(handle);
  if (ret < 0)
    {
      message(MAIN_NAME_STRING ": usbstrg_exportluns failed: %d\n", -ret);
      usbstrg_uninitialize(handle);
      return 7;
    }
  check_test_memory_usage("After usbstrg_exportluns()");

  /* It this program was configued as an NSH command, then just exit now.
   * Also, if signals are not enabled (and, hence, sleep() is not supported.
   * then we have not real option but to exit now.
   */

#if !defined(CONFIG_EXAMPLES_USBSTRG_BUILTIN) && !defined(CONFIG_DISABLE_SIGNALS)

  /* Otherwise, this thread will hang around and monitor the USB storage activity */

  for (;;)
    {
      msgflush();
      sleep(5);

#  ifdef CONFIG_USBDEV_TRACE
      message("\nuser_start: USB TRACE DATA:\n");
      ret =  usbtrace_enumerate(usbstrg_enumerate, NULL);
      if (ret < 0)
        {
          message(MAIN_NAME_STRING ": usbtrace_enumerate failed: %d\n", -ret);
          usbstrg_uninitialize(handle);
          return 8;
        }
      check_test_memory_usage("After usbtrace_enumerate()");
#  else
      message(MAIN_NAME_STRING ": Still alive\n");
#  endif
    }
#elif defined(CONFIG_EXAMPLES_USBSTRG_BUILTIN)

   /* Return the USB mass storage device handle so it can be used by the 'misconn'
    * command.
    */

   message(MAIN_NAME_STRING ": Connected\n");
   g_usbstrg.mshandle = handle;
   check_test_memory_usage("After MS connection");

#else /* defined(CONFIG_DISABLE_SIGNALS) */

  /* Just exit */
 
   message(MAIN_NAME_STRING ": Exiting\n");

   /* Dump debug memory usage */
 
   final_memory_usage("Final memory usage");
#endif
   return 0;
}