summaryrefslogtreecommitdiff
path: root/static/netbsd/man4/gpioirq.4 4.html
blob: 0989156ca8a2e77ec1e925d0157db78681b2e020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<table class="head">
  <tr>
    <td class="head-ltitle">GPIOIRQ(4)</td>
    <td class="head-vol">Device Drivers Manual</td>
    <td class="head-rtitle">GPIOIRQ(4)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">gpioirq</code> &#x2014; <span class="Nd">Install
    an interrupt handler on GPIO pins</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="Cd">gpioirq* at gpio? offset 0 mask 0x1 flag
    0x00</code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The <code class="Nm">gpioirq</code> driver attaches an interrupt
    handler to a one or more GPIO pins.</p>
<p class="Pp">The base pin number is specified in the kernel configuration file
    with the <var class="Ar">offset</var> locator. The
    <var class="Ar">mask</var> locator can be 0x01 or greater to indicate that
    more pins should have an interrupt handler attached to them.</p>
<p class="Pp">The <var class="Ar">flag</var> locator specifies the interrupt
    mode to use:</p>
<dl class="Bl-tag">
  <dt id="0x01"><a class="permalink" href="#0x01"><code class="Dv">0x01</code></a></dt>
  <dd>Interrupt on the positive (rising) edge of the pin.</dd>
  <dt id="0x02"><a class="permalink" href="#0x02"><code class="Dv">0x02</code></a></dt>
  <dd>Interrupt on the negative (falling) edge of the pin.</dd>
  <dt id="0x04"><a class="permalink" href="#0x04"><code class="Dv">0x04</code></a></dt>
  <dd>Interrupt on both edges of the pin.</dd>
  <dt id="0x08"><a class="permalink" href="#0x08"><code class="Dv">0x08</code></a></dt>
  <dd>Assert the interrupt as long as the pin is high.</dd>
  <dt id="0x10"><a class="permalink" href="#0x10"><code class="Dv">0x10</code></a></dt>
  <dd>Assert the interrupt as long as the pin is low.</dd>
</dl>
<p class="Pp">Note that the interrupts modes are mutually-exclusive, and exactly
    one interrupt mode must be specified. These flags correspond to the
    <code class="Dv">GPIO_INTR</code> mode bits defined in
    <span class="Pa">sys/gpio.h</span>. In addition to the interrupt mode,
    setting <code class="Dv">0x1000</code> in <var class="Ar">flags</var> will
    enable the printing of a message to the console whenever the interrupt
    handler is called.</p>
<p class="Pp">The <var class="Ar">offset</var>, <var class="Ar">mask</var>, and
    <var class="Ar">flag</var> locators can also be specified when
    <code class="Nm">gpioirq</code> is attached at runtime using the
    <code class="Dv">GPIOATTACH</code> <a class="Xr">ioctl(2)</a> on the
    <a class="Xr">gpio(4)</a> device.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="FILES"><a class="permalink" href="#FILES">FILES</a></h1>
<dl class="Bl-tag Bl-compact">
  <dt>/dev/gpioirq<var class="Ar">u</var></dt>
  <dd>GPIOIRQ device unit <var class="Ar">u</var> file. The output from this
      device are three uint8_t bytes every time an interrupt fires. The bytes
      contain the device unit, pin number and the current state of the pin.</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<p class="Pp">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:</p>
<div class="Bd Pp Bd-indent Li">
<pre>/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 = &quot;/dev/gpioirq0&quot;;

sysopen(DEV,$dev,O_RDONLY) || die &quot;sysopen: $!&quot;;

while (sysread(DEV,$b,3)) {
    @v = unpack(&quot;CCC&quot;,$b);

    print join(',',@v);
    print &quot;\n&quot;;
}

</pre>
</div>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">gpio(4)</a>, <a class="Xr">drvctl(8)</a>,
    <a class="Xr">gpioctl(8)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Nm">gpioirq</code> driver first appeared in
    <span class="Ux">NetBSD 9.0</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">The <code class="Nm">gpioirq</code> driver was written by
    <span class="An">Brad Spencer</span>
    &lt;<a class="Mt" href="mailto:brad@anduin.eldar.org">brad@anduin.eldar.org</a>&gt;.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
<p class="Pp">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
    <a class="Xr">gpio(4)</a> infrastructure does not support getting at that
    information even if it did exist.</p>
<p class="Pp">It is important that if the <a class="Xr">gpioirq(4)</a> 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.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">November 5, 2023</td>
    <td class="foot-os">NetBSD 10.1</td>
  </tr>
</table>