User Space GPIO Interrupt programming - GSoC-2018

Ian Lepore ian at freebsd.org
Fri Nov 27 22:05:12 UTC 2020


On Fri, 2020-11-27 at 11:04 -0700, Ian Lepore wrote:
> > I think we need a way for the app to choose whether it wants simple
> > reporting of pin number (like the original code) perhaps along with
> > a count, versus requesting detailed per-event data.  I'm going to
> > propose something more detailed about this as soon as I get my
> > thoughts all organized.

Okay, here's my current thinking on this (with tabs compressed down to
just a couple spaces to prevent line-wrap in email).  This is a snippet
from gpio.h...

/*
 * Reporting gpio pin-change per-event details to userland.
 *
 * When configured for detail reporting, each call to read(2) will
 * return one or more of these structures (or will return
 * EWOULDBLOCK in non-blocking IO mode when there are no new events
 * to report).
 */
struct gpio_event_detail {
  struct timespec gp_time;        /* Time of event */
  uint16_t        gp_pin;         /* Pin number */
  bool            gp_pinstate;    /* Pin state at time of event */
};

/*
 * Reporting gpio pin-change summary data to userland.
 *
 * When configured for summary reporting (the default), each call to
 * read(2) will return one or more of these structures (or will
 * return EWOULDBLOCK in non-blocking IO mode when there are no new
 * events to report).
 */
struct gpio_event_summary {
  struct timespec gp_first_time;  /* Time of first event */
  struct timespec gp_last_time;   /* Time of last event */
  uint16_t        gp_pin;         /* Pin number */
  uint16_t        gp_count;       /* Event count */
  bool            gp_first_state; /* Pin state at first event */
  bool            gp_last_state;  /* Pin state at last event */
};

/*
 * Configuring event reporting to userland.
 *
 * The default is to deliver gpio_event_summary reporting.  To
 * change it, you must use the GPIOCONFIGEVENTS ioctl to set the
 * event fifo size before using GPIOSETCONFIG to configure reporting
 * interrupt events on any pins.  This config is tracked on a
 * per-open-descriptor basis.  Once it has been set, it cannot be
 * changed without closing and re-opening the file descriptor.
 */
struct gpio_event_config {
  uint32_t        gp_fifo_size;   /* Zero for summary reporting. */
};

#define	GPIOCONFIGEVENTS	_IOW('G', 9, struct gpio_event_config)

I haven't written the implementation of all this yet, but I have a
pretty good idea of how to do so.

-- Ian




More information about the freebsd-arm mailing list