GPIOIRQ(4) | Device Drivers Manual | GPIOIRQ(4) |
gpioirq
— Install
an interrupt handler on GPIO pins
gpioirq* at gpio? offset 0 mask 0x1 flag
0x00
The gpioirq
driver attaches an interrupt
handler to a one or more GPIO pins.
The base pin number is specified in the kernel configuration file with the offset locator. The mask locator can be 0x01 or greater to indicate that more pins should have an interrupt handler attached to them.
The flag locator specifies the interrupt mode to use:
0x01
0x02
0x04
0x08
0x10
Note that the interrupts modes are mutually-exclusive, and exactly
one interrupt mode must be specified. These flags correspond to the
GPIO_INTR
mode bits defined in
sys/gpio.h. In addition to the interrupt mode,
setting 0x1000
in flags will
enable the printing of a message to the console whenever the interrupt
handler is called.
The offset, mask, and
flag locators can also be specified when
gpioirq
is attached at runtime using the
GPIOATTACH
ioctl(2) on the
gpio(4) device.
The following example will output the device unit, pin and the pins current state for pins 4, 5, 6, 7, 8, 9, 10, 11, 12 on gpio0:
/etc/gpio.conf contains: gpio0 attach gpioirq 4 0x1ff 0x04 or a kernel was compiled to have the same parameters. #!/usr/pkg/bin/perl $dev = "/dev/gpioirq0"; sysopen(DEV,$dev,O_RDONLY) || die "sysopen: $!"; while (sysread(DEV,$b,3)) { @v = unpack("CCC",$b); print join(',',@v); print "\n"; }
The gpioirq
driver first appeared in
NetBSD 9.0.
The gpioirq
driver was written by
Brad Spencer
<brad@anduin.eldar.org>.
When an interrupt fires in most devices there is not any information carried along in the interrupt as to whether or not the pin is high or low. Hence the driver reads the current state of the pin after the interrupt has fired and it is possible that the state of the pin could have changed between the time the interrupt fired and the reading of the state. As a practical matter the only time the pin state will be reported wrong is if there is a very large number of interrupts happening. The driver could have made some assumptions if the interrupt was only for a rising edge or falling edge as in those cases it would be possible to know what the pin state would have been, but in the case of the double edge, there really will not be any way to be sure with most hardware and, in any case, the gpio(4) infrastructure does not support getting at that information even if it did exist.
It is important that if the gpioirq(4) device is opened that it be read, as it may be possible to run the kernel out of memory if the device is opened but not read and interrupts occur on a pin tied to the driver.
November 5, 2023 | NetBSD 10.99 |