Ejemplo n.º 1
0
int stm32_usbhost_initialize(void)
{
  int pid;
  int ret;

  /* First, register all of the class drivers needed to support the drivers
   * that we care about:
   */

  uvdbg("Register class drivers\n");
  ret = usbhost_storageinit();
  if (ret != OK)
    {
      udbg("Failed to register the mass storage class\n");
    }

  /* Then get an instance of the USB host interface */

  uvdbg("Initialize USB host\n");
  g_drvr = usbhost_initialize(0);
  if (g_drvr)
    {
      /* Start a thread to handle device connection. */

      uvdbg("Start usbhost_waiter\n");

      pid = TASK_CREATE("usbhost", CONFIG_USBHOST_DEFPRIO,
                        CONFIG_USBHOST_STACKSIZE,
                        (main_t)usbhost_waiter, (FAR char * const *)NULL);
      return pid < 0 ? -ENOEXEC : OK;
    }

  return -ENODEV;
}
Ejemplo n.º 2
0
static int nsh_usbhostinitialize(void)
{
  int pid;
  int ret;

  /* First, register all of the class drivers needed to support the drivers
   * that we care about:
   */

  message("nsh_usbhostinitialize: Register class drivers\n");
  ret = usbhost_storageinit();
  if (ret != OK)
    {
      message("nsh_usbhostinitialize: Failed to register the mass storage class\n");
    }

  message("nsh_usbhostinitialize: Register device specific drivers\n");
  ret = usbhost_wlaninit();
  if (ret != OK)
    {
      message("nsh_usbhostinitialize: Failed to register the WLAN device\n");
    }

  /* Then get an instance of the USB host interface */

  message("nsh_usbhostinitialize: Initialize USB host\n");
  g_drvr = usbhost_initialize(0);
  if (g_drvr)
    {
      /* Start a thread to handle device connection. */

      message("nsh_usbhostinitialize: Start nsh_waiter\n");

#ifndef CONFIG_CUSTOM_STACK
      pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO,
                        CONFIG_USBHOST_STACKSIZE,
                        (main_t)nsh_waiter, (const char **)NULL);
#else
      pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO,
                        (main_t)nsh_waiter, (const char **)NULL);
#endif
      return pid < 0 ? -ENOEXEC : OK;
    }
  return -ENODEV;
}
Ejemplo n.º 3
0
int wlan_main(int argc, char *argv[])
{
  pid_t pid;
  int ret;

  /* First, register all of the USB host Wireless LAN drivers */

  printf("wlan_main: Register drivers\n");
  ret = usbhost_wlaninit();
  if (ret != OK)
    {
      printf("wlan_main: Failed to register the WLAN driver\n");
    }

  /* Then get an instance of the USB host interface */

  printf("wlan_main: Initialize USB host WLAN driver\n");
  g_drvr = usbhost_initialize(0);
  if (g_drvr)
    {
      /* Start a thread to handle device connection. */

      printf("wlan_main: Start wlan_waiter\n");

#ifndef CONFIG_CUSTOM_STACK
      pid = task_create("usbhost", CONFIG_EXAMPLES_WLAN_DEFPRIO,
                        CONFIG_EXAMPLES_WLAN_STACKSIZE,
                        (main_t)wlan_waiter, (const char **)NULL);
#else
      pid = task_create("usbhost", CONFIG_EXAMPLES_WLAN_DEFPRIO,
                        (main_t)wlan_waiter, (const char **)NULL);
#endif

      /* Now just sleep.  Eventually logic here will perform the device test. */

      for (;;)
        {
          sleep(5);
          printf("usert_start:  Still alive\n");
        }
    }
  return 0;
}
Ejemplo n.º 4
0
int hidkbd_main(int argc, char *argv[])
{
  char buffer[256];
  pid_t pid;
  ssize_t nbytes;
  int fd;
  int ret;

  /* First, register all of the USB host HID keyboard class driver */

  printf("hidkbd_main: Register class drivers\n");
  ret = usbhost_kbdinit();
  if (ret != OK)
    {
      printf("hidkbd_main: Failed to register the KBD class\n");
    }

  /* Then get an instance of the USB host interface */

  printf("hidkbd_main: Initialize USB host keyboard driver\n");
  g_drvr = usbhost_initialize(0);
  if (g_drvr)
    {
      /* Start a thread to handle device connection. */

      printf("hidkbd_main: Start hidkbd_waiter\n");

#ifndef CONFIG_CUSTOM_STACK
      pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
                        CONFIG_EXAMPLES_HIDKBD_STACKSIZE,
                        (main_t)hidkbd_waiter, (const char **)NULL);
#else
      pid = task_create("usbhost", CONFIG_EXAMPLES_HIDKBD_DEFPRIO,
                        (main_t)hidkbd_waiter, (const char **)NULL);
#endif

      /* Now just sleep.  Eventually logic here will open the kbd device and
       * perform the HID keyboard test.
       */

      for (;;)
        {
          /* Open the keyboard device.  Loop until the device is successfully
           * opened.
           */

          do
            {
              printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
              fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
              if (fd < 0)
                {
                   printf("Failed: %d\n", errno);
                   fflush(stdout);
                   sleep(3);
                }
            }
          while (fd < 0);

          printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
          fflush(stdout);

          /* Loop until there is a read failure */

          do
            {
              /* Read a buffer of data */

              nbytes = read(fd, buffer, 256);
              if (nbytes > 0)
                {
                  /* On success, echo the buffer to stdout */

                  (void)write(1, buffer, nbytes);
                }
            }
          while (nbytes >= 0);

          printf("Closing device %s: %d\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME, (int)nbytes);
          fflush(stdout);
          close(fd);
        }
    }
  return 0;
}