Example #1
0
int
libsoc_gpio_wait_interrupt (gpio * gpio, int timeout)
{
  if (gpio == NULL)
    {
      libsoc_gpio_debug (__func__, -1, "invalid gpio pointer");
      return LS_INT_ERROR;
    }

  if (libsoc_gpio_get_direction (gpio) != INPUT)
    {
      libsoc_gpio_debug (__func__, gpio->gpio, "gpio is not set as input");
      return LS_INT_ERROR;
    }

  gpio_edge test_edge = libsoc_gpio_get_edge (gpio);

  if (test_edge == EDGE_ERROR || test_edge == NONE)
    {
      libsoc_gpio_debug (__func__, gpio->gpio,
			 "edge must be FALLING, RISING or BOTH");
      return LS_INT_ERROR;
    }

  return libsoc_gpio_poll(gpio, timeout);
}
Example #2
0
int
libsoc_gpio_wait_interrupt (gpio * gpio, int timeout)
{
  if (gpio == NULL)
    {
      libsoc_gpio_debug (__func__, -1, "invalid gpio pointer");
      return EDGE_ERROR;
    }

  if (libsoc_gpio_get_direction (gpio) != INPUT)
    {
      libsoc_gpio_debug (__func__, gpio->gpio, "gpio is not set as input");
      return EXIT_FAILURE;
    }

  gpio_edge test_edge = libsoc_gpio_get_edge (gpio);

  if (test_edge == EDGE_ERROR || test_edge == NONE)
    {
      libsoc_gpio_debug (__func__, gpio->gpio,
			 "edge must be FALLING, RISING or BOTH");
      return EXIT_FAILURE;
    }

  struct pollfd pfd[1];
  char buffer[1];

  pfd[0].fd = gpio->value_fd;
  pfd[0].events = POLLPRI;
  pfd[0].revents = 0;

  // Read data for clean initial poll
  lseek (pfd[0].fd, 0, SEEK_SET);
  read (pfd[0].fd, buffer, 1);

  int ready = poll (pfd, 1, timeout);

  int ret;

  switch (ready)
    {
    case -1:
      libsoc_gpio_debug (__func__, gpio->gpio, "poll failed");
      perror ("libsoc-gpio-debug");
      ret = EXIT_FAILURE;
      break;

    case 0:
      ret = EXIT_FAILURE;
      break;

    default:
      ret = EXIT_SUCCESS;
      break;
    }

  return ret;

}