Beispiel #1
0
int serdis_main(int argc, char *argv[])
#endif
{
  struct boardioc_usbdev_ctrl_s ctrl;

  /* First check if the USB mass storage device is already connected */

  if (!g_cdcacm.handle)
    {
      printf("serdis: ERROR: Not connected\n");
      return EXIT_FAILURE;
    }

  /* Then, in any event, disable trace data collection as configured BEFORE
   * enabling the CDC/ACM device.
   */

  usbtrace_enable(0);

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

  ctrl.usbdev   = BOARDIOC_USBDEV_CDCACM;
  ctrl.action   = BOARDIOC_USBDEV_DISCONNECT;
  ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
  ctrl.handle   = &g_cdcacm.handle;

  (void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
  g_cdcacm.handle = NULL;
  printf("serdis: Disconnected\n");
  return EXIT_SUCCESS;
}
Beispiel #2
0
void symtab_initialize(void)
{
  /* We set the symbol table indirectly through the boardctl() */

  struct boardioc_symtab_s symdesc;

  symdesc.symtab   = g_symtab;
  symdesc.nsymbols = NSYMBOLS;
  (void)boardctl(BOARDIOC_SYMTAB, (uintptr_t)&symdesc);
}
Beispiel #3
0
int sercon_main(int argc, char *argv[])
#endif
{
  struct boardioc_usbdev_ctrl_s ctrl;
  int ret;

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

  if (g_cdcacm.handle)
    {
      printf("sercon:: ERROR: Already connected\n");
      return EXIT_FAILURE;
    }

  /* Then, in any event, enable trace data collection as configured BEFORE
   * enabling the CDC/ACM device.
   */

  usbtrace_enable(TRACE_BITSET);

  /* Initialize the USB CDC/ACM serial driver */

  printf("sercon: Registering CDC/ACM serial driver\n");

  ctrl.usbdev   = BOARDIOC_USBDEV_CDCACM;
  ctrl.action   = BOARDIOC_USBDEV_CONNECT;
  ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
  ctrl.handle   = &g_cdcacm.handle;

  ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
  if (ret < 0)
    {
      printf("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret);
      return EXIT_FAILURE;
    }

  printf("sercon: Successfully registered the CDC/ACM serial driver\n");
  return EXIT_SUCCESS;
}
Beispiel #4
0
static inline int nximage_initialize(void)
{
  FAR NX_DRIVERTYPE *dev;

#if defined(CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT)
  struct boardioc_graphics_s devinfo;
  int ret;

  /* Use external graphics driver initialization */

  printf("nximage_initialize: Initializing external graphics device\n");

  devinfo.devno = CONFIG_EXAMPLES_NXIMAGE_DEVNO;
  devinfo.dev = NULL;

  ret = boardctl(BOARDIOC_GRAPHICS_SETUP, (uintptr_t)&devinfo);
  if (ret < 0)
    {
      printf("nximage_initialize: boardctl failed, devno=%d: %d\n",
             CONFIG_EXAMPLES_NXIMAGE_DEVNO, errno);
      g_nximage.code = NXEXIT_EXTINITIALIZE;
      return ERROR;
    }

  dev = devinfo.dev;

#elif defined(CONFIG_NX_LCDDRIVER)
  int ret;

  /* Initialize the LCD device */

  printf("nximage_initialize: Initializing LCD\n");
  ret = board_lcd_initialize();
  if (ret < 0)
    {
      printf("nximage_initialize: board_lcd_initialize failed: %d\n", -ret);
      g_nximage.code = NXEXIT_LCDINITIALIZE;
      return ERROR;
    }

  /* Get the device instance */

  dev = board_lcd_getdev(CONFIG_EXAMPLES_NXIMAGE_DEVNO);
  if (!dev)
    {
      printf("nximage_initialize: board_lcd_getdev failed, devno=%d\n",
             CONFIG_EXAMPLES_NXIMAGE_DEVNO);
      g_nximage.code = NXEXIT_LCDGETDEV;
      return ERROR;
    }

  /* Turn the LCD on at 75% power */

  (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
#else
  int ret;

  /* Initialize the frame buffer device */

  printf("nximage_initialize: Initializing framebuffer\n");

  ret = up_fbinitialize(0);
  if (ret < 0)
    {
      printf("nximage_initialize: up_fbinitialize failed: %d\n", -ret);

      g_nximage.code = NXEXIT_FBINITIALIZE;
      return ERROR;
    }

  dev = up_fbgetvplane(0, CONFIG_EXAMPLES_NXIMAGE_VPLANE);
  if (!dev)
    {
      printf("nximage_initialize: up_fbgetvplane failed, vplane=%d\n",
             CONFIG_EXAMPLES_NXIMAGE_VPLANE);

      g_nximage.code = NXEXIT_FBGETVPLANE;
      return ERROR;
    }
#endif

  /* Then open NX */

  printf("nximage_initialize: Open NX\n");
  g_nximage.hnx = nx_open(dev);
  if (!g_nximage.hnx)
    {
      printf("nximage_initialize: nx_open failed: %d\n", errno);
      g_nximage.code = NXEXIT_NXOPEN;
      return ERROR;
    }

  return OK;
}
Beispiel #5
0
int adc_main(int argc, char *argv[])
#endif
{
  struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE];
  size_t readsize;
  ssize_t nbytes;
  int fd;
  int errval = 0;
  int ret;
  int i;

  /* Check if we have initialized */

  if (!g_adcstate.initialized)
    {
      /* Initialization of the ADC hardware is performed by logic external to
       * this test.
       */

      printf("adc_main: Initializing external ADC device\n");
      ret = boardctl(BOARDIOC_ADCTEST_SETUP, 0);
      if (ret < 0)
        {
          printf("adc_main: boardctl failed: %d\n", errno);
          errval = 1;
          goto errout;
        }

      /* Set the default values */

      adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH);

#if CONFIG_EXAMPLES_ADC_NSAMPLES > 0
      g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES;
#else
      g_adcstate.count = 1;
#endif
      g_adcstate.initialized = true;
    }

  /* Parse the command line */

#ifdef CONFIG_NSH_BUILTIN_APPS
  parse_args(&g_adcstate, argc, argv);
#endif

  /* If this example is configured as an NX add-on, then limit the number of
   * samples that we collect before returning.  Otherwise, we never return
   */

#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_ADC_NSAMPLES > 0
  printf("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
#endif

  /* Open the ADC device for reading */

  printf("adc_main: Hardware initialized. Opening the ADC device: %s\n",
          g_adcstate.devpath);

  fd = open(g_adcstate.devpath, O_RDONLY);
  if (fd < 0)
    {
      printf("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
      errval = 2;
      goto errout;
    }

  /* Now loop the appropriate number of times, displaying the collected
   * ADC samples.
   */

#if defined(CONFIG_NSH_BUILTIN_APPS)
  for (; g_adcstate.count > 0; g_adcstate.count--)
#elif CONFIG_EXAMPLES_ADC_NSAMPLES > 0
  for (g_adcstate.count = 0; g_adcstate.count < CONFIG_EXAMPLES_ADC_NSAMPLES; g_adcstate.count++)
#else
  for (;;)
#endif
  {
    /* Flush any output before the loop entered or from the previous pass
     * through the loop.
     */

    fflush(stdout);

#ifdef CONFIG_EXAMPLES_ADC_SWTRIG
    /* Issue the software trigger to start ADC conversion */

    ret = ioctl(fd, ANIOC_TRIGGER, 0);
    if (ret < 0)
      {
        int errcode = errno;
        printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode);
      }
#endif

    /* Read up to CONFIG_EXAMPLES_ADC_GROUPSIZE samples */

    readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
    nbytes = read(fd, sample, readsize);

    /* Handle unexpected return values */

    if (nbytes < 0)
      {
        errval = errno;
        if (errval != EINTR)
          {
            printf("adc_main: read %s failed: %d\n",
                    g_adcstate.devpath, errval);
            errval = 3;
            goto errout_with_dev;
          }

        printf("adc_main: Interrupted read...\n");
      }
    else if (nbytes == 0)
      {
        printf("adc_main: No data read, Ignoring\n");
      }

    /* Print the sample data on successful return */

    else
      {
        int nsamples = nbytes / sizeof(struct adc_msg_s);
        if (nsamples * sizeof(struct adc_msg_s) != nbytes)
          {
            printf("adc_main: read size=%ld is not a multiple of sample size=%d, Ignoring\n",
                   (long)nbytes, sizeof(struct adc_msg_s));
          }
        else
          {
            printf("Sample:\n");
            for (i = 0; i < nsamples ; i++)
              {
                printf("%d: channel: %d value: %d\n",
                        i+1, sample[i].am_channel, sample[i].am_data);
              }
          }
      }
  }

  close(fd);
  return OK;

  /* Error exits */

errout_with_dev:
  close(fd);

errout:
  printf("Terminating!\n");
  fflush(stdout);
  return errval;
}
Beispiel #6
0
int usbterm_main(int argc, char *argv[])
#endif
{
  struct boardioc_usbdev_ctrl_s ctrl;
  FAR void *handle;
  pthread_attr_t attr;
  int ret;

  /* Initialize global data */

  memset(&g_usbterm, 0, sizeof(struct usbterm_globals_s));

  /* Initialization of the USB hardware may be performed by logic external to
   * this test.
   */

#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT
  printf("usbterm_main: Performing external device initialization\n");
  ret = usbterm_devinit();
  if (ret != OK)
    {
      printf("usbterm_main: usbterm_devinit failed: %d\n", ret);
      goto errout;
    }
#endif

  /* Initialize the USB serial driver */

  printf("usbterm_main: Registering USB serial driver\n");

#ifdef CONFIG_CDCACM

  ctrl.usbdev   = BOARDIOC_USBDEV_CDCACM;
  ctrl.action   = BOARDIOC_USBDEV_CONNECT;
  ctrl.instance = 0;
  ctrl.handle   = &handle;

#else

  ctrl.usbdev   = BOARDIOC_USBDEV_PL2303;
  ctrl.action   = BOARDIOC_USBDEV_CONNECT;
  ctrl.instance = 0;
  ctrl.handle   = &handle;

#endif

  ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
  if (ret < 0)
    {
      printf("usbterm_main: ERROR: Failed to create the USB serial device: %d\n", -ret);
      goto errout_with_devinit;
    }

  printf("usbterm_main: Successfully registered the serial driver\n");

#if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0
  /* If USB tracing is enabled and tracing of initial USB events is specified,
   * then dump all collected trace data to stdout
   */

  sleep(5);
  dumptrace();
#endif

  /* Then, in any event, configure trace data collection as configured */

  usbtrace_enable(TRACE_BITSET);

  /* Open the USB serial device for writing */

  do
    {
      printf("usbterm_main: Opening USB serial driver\n");

      g_usbterm.outstream = fopen(USBTERM_DEVNAME, "w");
      if (g_usbterm.outstream == NULL)
        {
          int errcode = errno;
          printf("usbterm_main: ERROR: Failed to open " USBTERM_DEVNAME " for writing: %d\n",
                 errcode);

          /* ENOTCONN means that the USB device is not yet connected */

          if (errcode == ENOTCONN)
            {
              printf("usbterm_main:        Not connected. Wait and try again.\n");
              sleep(5);
            }
          else
            {
              /* Give up on other errors */

              goto errout_with_devinit;
            }
        }

      /* If USB tracing is enabled, then dump all collected trace data to stdout */

      dumptrace();
    }
  while (g_usbterm.outstream == NULL);

  /* Open the USB serial device for reading.  Since we are already connected, this
   * should not fail.
   */

  g_usbterm.instream = fopen(USBTERM_DEVNAME, "r");
  if (g_usbterm.instream == NULL)
    {
      printf("usbterm_main: ERROR: Failed to open " USBTERM_DEVNAME " for reading: %d\n", errno);
      goto errout_with_outstream;
    }

  printf("usbterm_main: Successfully opened the serial driver\n");

  /* Start the USB term listener thread */

  printf("usbterm_main: Starting the listener thread\n");

  ret = pthread_attr_init(&attr);
  if (ret != OK)
    {
      printf("usbterm_main: pthread_attr_init failed: %d\n", ret);
      goto errout_with_streams;
    }

  ret = pthread_create(&g_usbterm.listener, &attr,
                       usbterm_listener, (pthread_addr_t)0);
  if (ret != 0)
    {
      printf("usbterm_main: Error in thread creation: %d\n", ret);
      goto errout_with_streams;
    }

  /* Send messages and get responses -- forever */

  printf("usbterm_main: Waiting for local input\n");
  for (;;)
    {
      /* Display the prompt string on stdout */

      fputs("usbterm> ", stdout);
      fflush(stdout);

      /* Get the next line of input */

#ifdef CONFIG_EXAMPLES_USBTERM_FGETS
      /* fgets returns NULL on end-of-file or any I/O error */

      if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin) == NULL)
        {
          printf("ERROR: fgets failed: %d\n", errno);
          return 1;
        }
#else
      ret = readline(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin, stdout);

      /* Readline normally returns the number of characters read,
       * but will return EOF on end of file or if an error occurs.  Either
       * will cause the session to terminate.
       */

      if (ret == EOF)
        {
          printf("ERROR: readline failed: %d\n", ret);
          return 1;
        }
#endif
      /* Is there anyone listening on the other end? */

      else if (g_usbterm.peer)
        {
          /* Yes.. Send the line of input via USB */

          fputs(g_usbterm.outbuffer, g_usbterm.outstream);

          /* Display the prompt string on the remote USB serial connection */

          fputs("\rusbterm> ", g_usbterm.outstream);
          fflush(g_usbterm.outstream);
        }
      else
        {
          printf("Still waiting for remote peer.  Please try again later.\n");
        }

      /* If USB tracing is enabled, then dump all collected trace data to stdout */

      dumptrace();
    }

  /* Error exits */

errout_with_streams:
  fclose(g_usbterm.instream);
errout_with_outstream:
  fclose(g_usbterm.outstream);
errout_with_devinit:
#ifdef CONFIG_EXAMPLES_USBTERM_DEVINIT
  usbterm_devuninit();
errout:
#endif
  printf("usbterm_main:        Aborting\n");
  return 1;
}
Beispiel #7
0
int nx_servertask(int argc, char *argv[])
{
  FAR NX_DRIVERTYPE *dev;
  int ret;

#if defined(CONFIG_EXAMPLES_NX_EXTERNINIT)
  /* Use external graphics driver initialization */

  printf("nxeg_initialize: Initializing external graphics device\n");
  dev = boardctl(BOARDIOC_GRAPHICS_SETUP, CONFIG_EXAMPLES_NX_DEVNO);
  if (!dev)
    {
      printf("nxeg_initialize: boardctl failed, devno=%d\n",
             CONFIG_EXAMPLES_NX_DEVNO);
      g_exitcode = NXEXIT_EXTINITIALIZE;
      return ERROR;
    }

#elif defined(CONFIG_NX_LCDDRIVER)
  /* Initialize the LCD device */

  printf("nx_servertask: Initializing LCD\n");
  ret = board_lcd_initialize();
  if (ret < 0)
    {
      printf("nx_servertask: board_lcd_initialize failed: %d\n", -ret);
      return 1;
    }

  /* Get the device instance */

  dev = board_lcd_getdev(CONFIG_EXAMPLES_NX_DEVNO);
  if (!dev)
    {
      printf("nx_servertask: board_lcd_getdev failed, devno=%d\n",
             CONFIG_EXAMPLES_NX_DEVNO);
      return 2;
    }

  /* Turn the LCD on at 75% power */

  (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
#else
  /* Initialize the frame buffer device */

  printf("nx_servertask: Initializing framebuffer\n");
  ret = up_fbinitialize();
  if (ret < 0)
    {
      printf("nx_servertask: up_fbinitialize failed: %d\n", -ret);
      return 1;
    }

  dev = up_fbgetvplane(CONFIG_EXAMPLES_NX_VPLANE);
  if (!dev)
    {
      printf("nx_servertask: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NX_VPLANE);
      return 2;
    }
#endif

  /* Then start the server */

  ret = nx_run(dev);
  printf("nx_servertask: nx_run returned: %d\n", errno);
  return 3;
}
Beispiel #8
0
int tc_main(int argc, char *argv[])
#endif
{
#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE
  struct mouse_report_s sample;
#else
  struct touch_sample_s sample;
#endif
  ssize_t nbytes;
#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES > 0
  long nsamples;
#endif
  int fd;
  int errval = 0;
#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_ARCHINIT
  int ret;
#endif

  /* If this example is configured as an NX add-on, then limit the number of
   * samples that we collect before returning.  Otherwise, we never return
   */

#if defined(CONFIG_NSH_BUILTIN_APPS)
  nsamples = 1;
  if (argc > 1)
    {
      nsamples = strtol(argv[1], NULL, 10);
    }
  printf("tc_main: nsamples: %d\n", nsamples);
#elif CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES > 0
  printf("tc_main: nsamples: %d\n", CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES);
#endif

#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_ARCHINIT
  /* Initialization of the touchscreen hardware is performed by logic
   * external to this test.
   */

  printf("tc_main: Initializing external touchscreen device\n");
  ret = boardctl(BOARDIOC_TSCTEST_SETUP, CONFIG_EXAMPLES_TOUCHSCREEN_MINOR);
  if (ret != OK)
    {
      printf("tc_main: board_tsc_setup failed: %d\n", errno);
      errval = 1;
      goto errout;
    }
#endif

  /* Open the touchscreen device for reading */

  printf("tc_main: Opening %s\n", CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH);
  fd = open(CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH, O_RDONLY);
  if (fd < 0)
    {
      printf("tc_main: open %s failed: %d\n",
              CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH, errno);
      errval = 2;
      goto errout_with_tc;
    }

  /* Now loop the appropriate number of times, displaying the collected
   * touchscreen samples.
   */

#if defined(CONFIG_NSH_BUILTIN_APPS)
  for (; nsamples > 0; nsamples--)
#elif CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES > 0
  for (nsamples = 0; nsamples < CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES; nsamples++)
#else
  for (;;)
#endif
  {
    /* Flush any output before the loop entered or from the previous pass
     * through the loop.
     */

    fflush(stdout);

#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_MOUSE
    /* Read one sample */

    ivdbg("Reading...\n");
    nbytes = read(fd, &sample, sizeof(struct mouse_report_s));
    ivdbg("Bytes read: %d\n", nbytes);

    /* Handle unexpected return values */

    if (nbytes < 0)
      {
        errval = errno;
        if (errval != EINTR)
          {
            printf("tc_main: read %s failed: %d\n",
                   CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH, errval);
            errval = 3;
            goto errout_with_dev;
          }

        printf("tc_main: Interrupted read...\n");
      }
    else if (nbytes != sizeof(struct mouse_report_s))
      {
        printf("tc_main: Unexpected read size=%d, expected=%d, Ignoring\n",
               nbytes, sizeof(struct mouse_report_s));
      }

    /* Print the sample data on successful return */

    else
      {
        printf("Sample     :\n");
        printf("   buttons : %02x\n", sample.buttons);
        printf("         x : %d\n",   sample.x);
        printf("         y : %d\n",   sample.y);
#ifdef CONFIG_MOUSE_WHEEL
        printf("     wheel : %d\n",   sample.wheel);
#endif
      }
#else
    /* Read one sample */

    ivdbg("Reading...\n");
    nbytes = read(fd, &sample, sizeof(struct touch_sample_s));
    ivdbg("Bytes read: %d\n", nbytes);

    /* Handle unexpected return values */

    if (nbytes < 0)
      {
        errval = errno;
        if (errval != EINTR)
          {
            printf("tc_main: read %s failed: %d\n",
                   CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH, errval);
            errval = 3;
            goto errout_with_dev;
          }

        printf("tc_main: Interrupted read...\n");
      }
    else if (nbytes != sizeof(struct touch_sample_s))
      {
        printf("tc_main: Unexpected read size=%ld, expected=%d, Ignoring\n",
               (long)nbytes, sizeof(struct touch_sample_s));
      }

    /* Print the sample data on successful return */

    else
      {
        printf("Sample     :\n");
        printf("   npoints : %d\n",   sample.npoints);
        printf("Point 1    :\n");
        printf("        id : %d\n",   sample.point[0].id);
        printf("     flags : %02x\n", sample.point[0].flags);
        printf("         x : %d\n",   sample.point[0].x);
        printf("         y : %d\n",   sample.point[0].y);
        printf("         h : %d\n",   sample.point[0].h);
        printf("         w : %d\n",   sample.point[0].w);
        printf("  pressure : %d\n",   sample.point[0].pressure);
      }
#endif
  }

errout_with_dev:
  close(fd);

errout_with_tc:
#ifdef CONFIG_EXAMPLES_TOUCHSCREEN_ARCHINIT
  boardctl(BOARDIOC_TSCTEST_TEARDOWN, 0);

errout:
#endif
  printf("Terminating!\n");
  fflush(stdout);
  return errval;
}
Beispiel #9
0
int nxterm_server(int argc, char *argv[])
{
  FAR NX_DRIVERTYPE *dev;
  int ret;

#if defined(CONFIG_EXAMPLES_NXTERM_EXTERNINIT)
  struct boardioc_graphics_s devinfo;
  int ret;

  /* Use external graphics driver initialization */

  printf("nxterm_server: Initializing external graphics device\n");

  devinfo.devno = CONFIG_EXAMPLES_NXTERM_DEVNO;
  devinfo.dev = NULL;

  ret = boardctl(BOARDIOC_GRAPHICS_SETUP, (uintptr_t)&devinfo);
  if (ret < 0)
    {
      printf("nxterm_server: boardctl failed, devno=%d: %d\n",
             CONFIG_EXAMPLES_NXTERM_DEVNO, errno);
      return ERROR;
    }

  dev = devinfo.dev;

#elif defined(CONFIG_NX_LCDDRIVER)
  /* Initialize the LCD device */

  printf("nxterm_server: Initializing LCD\n");
  ret = board_lcd_initialize();
  if (ret < 0)
    {
      printf("nxterm_server: board_lcd_initialize failed: %d\n", -ret);
      return 1;
    }

  /* Get the device instance */

  dev = board_lcd_getdev(CONFIG_EXAMPLES_NXTERM_DEVNO);
  if (!dev)
    {
      printf("nxterm_server: board_lcd_getdev failed, devno=%d\n",
             CONFIG_EXAMPLES_NXTERM_DEVNO);
      return 2;
    }

  /* Turn the LCD on at 75% power */

  (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
#else
  /* Initialize the frame buffer device */

  printf("nxterm_server: Initializing framebuffer\n");

  ret = up_fbinitialize(0);
  if (ret < 0)
    {
      printf("nxterm_server: up_fbinitialize failed: %d\n", -ret);
      return 1;
    }

  dev = up_fbgetvplane(0, CONFIG_EXAMPLES_NXTERM_VPLANE);
  if (!dev)
    {
      printf("nxterm_server: up_fbgetvplane failed, vplane=%d\n",
             CONFIG_EXAMPLES_NXTERM_VPLANE);
      return 2;
    }
#endif

  /* Then start the server */

  ret = nx_run(dev);
  gvdbg("nx_run returned: %d\n", errno);
  return 3;
}
Beispiel #10
0
int ostest_main(int argc, FAR char *argv[])
{
  int result;
#ifdef CONFIG_EXAMPLES_OSTEST_WAITRESULT
  int ostest_result = ERROR;
#else
  int ostest_result = OK;
#endif

  /* Verify that stdio works first */

  stdio_test();

#ifdef SDCC
  /* I am not yet certain why SDCC does not like the following initilizers.
   * It involves some issues with 2- vs 3-byte pointer types.
   */

  g_argv[0] = arg1;
  g_argv[1] = arg2;
  g_argv[2] = arg3;
  g_argv[3] = arg4;
  g_argv[4] = NULL;
#endif

  /* Set up some environment variables */

#ifndef CONFIG_DISABLE_ENVIRON
  printf("ostest_main: putenv(%s)\n", g_putenv_value);
  putenv(g_putenv_value);                   /* Varaible1=BadValue3 */
  printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value);
  setenv(g_var1_name, g_var1_value, TRUE);  /* Variable1=GoodValue1 */

  printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1);
  setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */
  printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value);
  setenv(g_var2_name, g_var2_value, TRUE);  /* Variable2=GoodValue2 */

  printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
  setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */
  printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
  setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */
  show_environment(true, true, true);
#endif

  /* Verify that we can spawn a new task */

  result = task_create("ostest", PRIORITY, STACKSIZE, user_main,
                       (FAR char * const *)g_argv);
  if (result == ERROR)
    {
      printf("ostest_main: ERROR Failed to start user_main\n");
      ostest_result = ERROR;
    }
  else
    {
      printf("ostest_main: Started user_main at PID=%d\n", result);

#ifdef CONFIG_EXAMPLES_OSTEST_WAITRESULT
      /* Wait for the test to complete to get the test result */

      if (waitpid(result, &ostest_result, 0) != result)
        {
          printf("ostest_main: ERROR Failed to wait for user_main to terminate\n");
          ostest_result = ERROR;
        }
#endif
    }

  printf("ostest_main: Exiting with status %d\n", ostest_result);

#ifdef CONFIG_EXAMPLES_OSTEST_POWEROFF
  /* Power down, providing the test result.  This is really only an
   *interesting case when used with the NuttX simulator.  In that case,
   * test management logic can received the result of the test.
   */

  boardctl(BOARDIOC_POWEROFF, ostest_result);
#endif

  return ostest_result;
}
Beispiel #11
0
int can_main(int argc, FAR char *argv[])
#endif
{
  struct canioc_bittiming_s bt;

#ifdef CONFIG_EXAMPLES_CAN_WRITE
  struct can_msg_s txmsg;
#ifdef CONFIG_CAN_EXTID
  bool extended = true;
  uint32_t msgid;
#else
  uint16_t msgid;
#endif
  long minid    = 1;
  long maxid    = MAX_ID;
  int msgdlc;
  uint8_t msgdata;
  int i;
#endif

#ifdef CONFIG_EXAMPLES_CAN_READ
  struct can_msg_s rxmsg;
#endif

  size_t msgsize;
  ssize_t nbytes;
  bool badarg   = false;
  bool help     = false;
#ifdef CONFIG_NSH_BUILTIN_APPS
  long nmsgs    = CONFIG_EXAMPLES_CAN_NMSGS;
  long msgno;
#endif
  int option;
  int fd;
  int errval    = 0;
  int ret;

  /* Parse command line parameters */

  while ((option = getopt(argc, argv, OPT_STR)) != ERROR)
    {
      switch (option)
        {
#ifdef CONFIG_EXAMPLES_CAN_WRITE
#ifdef CONFIG_CAN_EXTID
          case 's':
            extended = false;
            break;
#endif

          case 'a':
            minid = strtol(optarg, NULL, 10);
            if (minid < 1 || minid > maxid)
              {
                fprintf(stderr, "<min-id> out of range\n");
                badarg = true;
              }
            break;

          case 'b':
            maxid = strtol(optarg, NULL, 10);
            if (maxid < minid || maxid > MAX_ID)
              {
                fprintf(stderr, "ERROR: <max-id> out of range\n");
                badarg = true;
              }
            break;
#endif

          case 'h':
            help = true;
            break;

#ifdef CONFIG_NSH_BUILTIN_APPS
          case 'n':
            nmsgs = strtol(optarg, NULL, 10);
            if (nmsgs < 1)
              {
                fprintf(stderr, "ERROR: <nmsgs> out of range\n");
                badarg = true;
              }
            break;
#endif

          case ':':
            fprintf(stderr, "ERROR: Bad option argument\n");
            badarg = true;
            break;

          case '?':
          default:
            fprintf(stderr, "ERROR: Unrecognized option\n");
            badarg = true;
            break;
        }
    }

  if (badarg)
    {
      show_usage(argv[0]);
      return EXIT_FAILURE;
    }

  if (help)
    {
      show_usage(argv[0]);
      return EXIT_SUCCESS;
    }

#if defined(CONFIG_EXAMPLES_CAN_WRITE) && defined(CONFIG_CAN_EXTID)
  if (!extended && maxid > CAN_MAX_STDMSGID)
    {
      maxid = CAN_MAX_STDMSGID;
      if (minid > maxid)
        {
          minid = maxid;
        }
    }
#endif

  if (optind != argc)
    {
      fprintf(stderr, "ERROR: Garbage on command line\n");
      show_usage(argv[0]);
      return EXIT_FAILURE;
    }

#ifdef CONFIG_NSH_BUILTIN_APPS
  printf("nmsgs: %d\n", nmsgs);
#endif
#ifdef CONFIG_EXAMPLES_CAN_WRITE
  printf("min ID: %ld max ID: %ld\n", minid, maxid);
#endif

  /* Initialization of the CAN hardware is performed by logic external to
   * this test.
   */

  ret = boardctl(BOARDIOC_CAN_INITIALIZE, 0);
  if (ret < 0)
    {
      printf("ERROR: BOARDIOC_CAN_INITIALIZE failed: %d\n", ret);
      errval = 1;
      goto errout;
    }

  /* Open the CAN device for reading */

  fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS);
  if (fd < 0)
    {
      printf("ERROR: open %s failed: %d\n",
             CONFIG_EXAMPLES_CAN_DEVPATH, errno);
      errval = 2;
      goto errout_with_dev;
    }

  /* Show bit timing information if provided by the driver.  Not all CAN
   * drivers will support this IOCTL.
   */

  ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)((uintptr_t)&bt));
  if (ret < 0)
    {
      printf("Bit timing not available: %d\n", errno);
    }
  else
    {
      printf("Bit timing:\n");
      printf("   Baud: %lu\n", (unsigned long)bt.bt_baud);
      printf("  TSEG1: %u\n", bt.bt_tseg1);
      printf("  TSEG2: %u\n", bt.bt_tseg2);
      printf("    SJW: %u\n", bt.bt_sjw);
    }

  /* Now loop the appropriate number of times, performing one loopback test
   * on each pass.
   */

#ifdef CONFIG_EXAMPLES_CAN_WRITE
  msgdlc  = 1;
  msgid   = minid;
  msgdata = 0;
#endif

#ifdef CONFIG_NSH_BUILTIN_APPS
  for (msgno = 0; msgno < nmsgs; msgno++)
#else
  for (; ; )
#endif
    {
      /* Flush any output before the loop entered or from the previous pass
       * through the loop.
       */

      fflush(stdout);

#ifdef CONFIG_EXAMPLES_CAN_WRITE

      /* Construct the next TX message */

      txmsg.cm_hdr.ch_id     = msgid;
      txmsg.cm_hdr.ch_rtr    = false;
      txmsg.cm_hdr.ch_dlc    = msgdlc;
#ifdef CONFIG_CAN_ERRORS
      txmsg.cm_hdr.ch_error  = 0;
#endif
#ifdef CONFIG_CAN_EXTID
      txmsg.cm_hdr.ch_extid  = extended;
#endif
      txmsg.cm_hdr.ch_unused = 0;

      for (i = 0; i < msgdlc; i++)
        {
          txmsg.cm_data[i] = msgdata + i;
        }

      /* Send the TX message */

      msgsize = CAN_MSGLEN(msgdlc);
      nbytes = write(fd, &txmsg, msgsize);
      if (nbytes != msgsize)
        {
          printf("ERROR: write(%ld) returned %ld\n",
                 (long)msgsize, (long)nbytes);
          errval = 3;
          goto errout_with_dev;
        }

      printf("  ID: %4u DLC: %d\n", msgid, msgdlc);

#endif

#ifdef CONFIG_EXAMPLES_CAN_READ

      /* Read the RX message */

      msgsize = sizeof(struct can_msg_s);
      nbytes = read(fd, &rxmsg, msgsize);
      if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
        {
          printf("ERROR: read(%ld) returned %ld\n",
                 (long)msgsize, (long)nbytes);
          errval = 4;
          goto errout_with_dev;
        }

      printf("  ID: %4u DLC: %u\n",
             rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc);

#ifdef CONFIG_CAN_ERRORS
      /* Check for error reports */

      if (rxmsg.cm_hdr.ch_error != 0)
        {
          printf("ERROR: CAN error report: [0x%04x]\n", rxmsg.cm_hdr.ch_id);
          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TXTIMEOUT) != 0)
            {
              printf("  TX timeout\n");
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_LOSTARB) != 0)
            {
              printf("  Lost arbitration: %02x\n", rxmsg.cm_data[0]);
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_CONTROLLER) != 0)
            {
              printf("  Controller error: %02x\n", rxmsg.cm_data[1]);
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_PROTOCOL) != 0)
            {
              printf("  Protocol error: %02x %02x\n", rxmsg.cm_data[2], rxmsg.cm_data[3]);
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TRANSCEIVER) != 0)
            {
              printf("  Transceiver error: %02x\n", rxmsg.cm_data[4]);
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_NOACK) != 0)
            {
              printf("  No ACK received on transmission\n");
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_BUSOFF) != 0)
            {
              printf("  Bus off\n");
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_BUSERROR) != 0)
            {
              printf("  Bus error\n");
            }

          if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_RESTARTED) != 0)
            {
              printf("  Controller restarted\n");
            }
        }
      else
#endif
        {
#if defined(CONFIG_EXAMPLES_CAN_WRITE) && defined(CONFIG_CAN_LOOPBACK)

          /* Verify that the received messages are the same */

          if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0)
            {
              printf("ERROR: Sent header does not match received header:\n");
              lib_dumpbuffer("Sent header",
                             (FAR const uint8_t *)&txmsg.cm_hdr,
                             sizeof(struct can_hdr_s));
              lib_dumpbuffer("Received header",
                             (FAR const uint8_t *)&rxmsg.cm_hdr,
                             sizeof(struct can_hdr_s));
              errval = 4;
              goto errout_with_dev;
            }

          if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0)
            {
              printf("ERROR: Data does not match. DLC=%d\n", msgdlc);
              for (i = 0; i < msgdlc; i++)
                {
                  printf("  %d: TX 0x%02x RX 0x%02x\n",
                         i, txmsg.cm_data[i], rxmsg.cm_data[i]);
                  errval = 5;
                  goto errout_with_dev;
                }
            }

          /* Report success */

          printf("  ID: %4u DLC: %d -- OK\n", msgid, msgdlc);

#else

          /* Print the data received */

          printf("Data received:\n");
          for (i = 0; i < msgdlc; i++)
            {
              printf("  %d: 0x%02x\n", i, rxmsg.cm_data[i]);
            }
#endif
        }
#endif

#ifdef CONFIG_EXAMPLES_CAN_WRITE

      /* Set up for the next pass */

      msgdata += msgdlc;

      if (++msgid > maxid)
        {
          msgid = minid;
        }

      if (++msgdlc > CAN_MAXDATALEN)
        {
          msgdlc = 1;
        }
#endif
    }

errout_with_dev:
  close(fd);

errout:
  printf("Terminating!\n");
  fflush(stdout);
  return errval;
}