Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jan 2023 19:15:30 +0000
From:      "Dr. Rolf Jansen" <freebsd-rj@cyclaero.com>
To:        freebsd-arm <freebsd-arm@freebsd.org>
Subject:   Re: GPIO inputs on Pis?
Message-ID:  <01070185e534f221-14f362b5-2b96-43f0-b0b0-f496ad9994fe-000000@eu-central-1.amazonses.com>
In-Reply-To: <fec41ff8-b658-36c8-615d-e3ae63dd9b37@denninger.net>
References:  <0b235f83-7cb3-1d14-7c64-aee7c1c0c23d@denninger.net> <01070185e46b1a6e-ee34b885-1215-45c7-ac18-83320c02cac2-000000@eu-central-1.amazonses.com> <a9b00748-1a11-3806-1103-ac2e6ad6bf43@denninger.net> <01070185e4732fd8-c0bede0b-d9df-4557-a174-cb237fa4bfaf-000000@eu-central-1.amazonses.com> <fec41ff8-b658-36c8-615d-e3ae63dd9b37@denninger.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_A11E81C7-9742-46CA-9F56-79152AC5767A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

> Am 24.01.2023 um 13:58 schrieb Karl Denninger <karl@denninger.net =
<mailto:karl@denninger.net>>:
>=20
> On 1/24/2023 10:43, Dr. Rolf Jansen wrote:
>> I sent an old ink to the thread on the mailing list, which does not =
work anymore. Here ist the new link:
>>=20
>> =
https://lists.freebsd.org/pipermail/freebsd-arm/2020-November/022738.html =
<https://lists.freebsd.org/pipermail/freebsd-arm/2020-November/022738.html=
>
>>=20
>>> Am 24.01.2023 um 12:35 schrieb Karl Denninger <karl@denninger.net =
<mailto:karl@denninger.net>>:
>>>=20
>>> Thank you -- will check it out.
>>>=20
>>> On 1/24/2023 10:35, Dr. Rolf Jansen wrote:
>>>>> Am 23.01.2023 um 11:41 schrieb Karl Denninger <karl@denninger.net =
<mailto:karl@denninger.net>>:
>>>>>=20
>>>>> Is there support somewhere in the 13.x for other than "read =
current state" / "set current state"?
>>>>>=20
>>>>> Specifically, there is evidence in the sys/gpio.h header file that =
I can open up a file descriptor and then use select()/read() to grab the =
contents of a ring buffer of some size (presumably interrupt-posted) of =
events since last look, and determine if there's anything in there.  =
Provided you're reasonably fast this might be enough to, for example, =
read an optical encoder that has a modest pulse rate.
>>>>>=20
>>>>> I see apparent review code at https://reviews.freebsd.org/D27398 =
<https://reviews.freebsd.org/D27398>; from late 2020, but nothing else I =
can find digging around; an example (assuming it is actually implemented =
and works) would be helpful
>>>>>=20
>>>> See
>>>>=20
>>>> =
https://forums.freebsd.org/threads/gpio-api-general-orange-pi-h3.83950/pos=
t-556728 =
<https://forums.freebsd.org/threads/gpio-api-general-orange-pi-h3.83950/po=
st-556728>
>>>>=20
>>>> And the messages in that thread that follow the one linked above.
>>>>=20
>>>> There is a respective thread on this mailing list as well:
>>>>=20
>>>> Porting FreeBSD to ARM processors: User Space GPIO Interrupt =
programming - GSoC-2018 =
<https://lists.freebsd.org/archives/freebsd-arm/2020-November/022740.html>=
--=20
>>> Karl Denninger
>>> karl@denninger.net <mailto:karl@denninger.net>
>>> The Market Ticker
>>> [S/MIME encrypted email preferred]
>>=20
> So the answer at this point appears to be "not in the codebase and no =
indication on when/if it might be, but there are patches that are in =
some state of development.=E2=80=9C
>=20
No, at this point (13.1-RELEASE) everything is in the kernel, no patches =
needed. Even the test tool made it into the source tree. It has only be =
renamed from gpioc_intr_test.c to gpioevents.c.

/usr/src/tools/test/gpioevents/gpioevents.c

The documentation is missing. It is however easy to learn how things =
work by examining the code of gpioevents.c.

> Being able to read an encoder of some sort basically means being able =
to know how many events occurred between "looks"; for most purposes you =
don't need each event delivered exactly when it occurs, but missing some =
of the counts entirely is not acceptable.

Yes, and for this reason, this GPIO event code which was developed by =
Christian Kr=C3=A4mer in the course of the GSoC-2018 and has been =
submitted in 2020 by Ian Lepore to the freebsd tree is perfect.

Ian tested it with a 10 MHz sqaure wave on an imx6 (ARMv7, 1GHz) and got =
an event every 10 =C2=B5s. That means the max. speed without event =
losses would be 100 kHz. I did not do exact measurements, however, my =
impression is that my RPi4B can do it a tad faster than my BeagleBone =
Black. With the RPi4, I needed to improve the debouncing of the encoder =
and the buttons, because it saw hundreds of bounces which the BBB =
didn=E2=80=99t. However, it may also be, that the internal GPIO circuits =
of the BBB have a different damping characteristic.

Anyway for my applications, 100 kHz way faster than what I need.

On my GitHub repository I placed another example on using the GPIO =
events for the RPi:

https://github.com/cyclaero/shutdd <https://github.com/cyclaero/shutdd>;

See also the respective thread on this mailing list:

https://lists.freebsd.org/archives/freebsd-arm/2022-July/001576.html =
<https://lists.freebsd.org/archives/freebsd-arm/2022-July/001576.html>=

--Apple-Mail=_A11E81C7-9742-46CA-9F56-79152AC5767A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Verdana; font-size: 12px; font-style: normal; font-variant-caps: normal; =
font-weight: normal; letter-spacing: normal; orphans: auto; text-align: =
start; text-indent: 0px; text-transform: none; white-space: normal; =
widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; =
-webkit-text-stroke-width: 0px; text-decoration: none;" =
class=3D""><blockquote type=3D"cite" class=3D""><div class=3D"">Am =
24.01.2023 um 13:58 schrieb Karl Denninger &lt;<a =
href=3D"mailto:karl@denninger.net" =
class=3D"">karl@denninger.net</a>&gt;:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div class=3D""><div =
class=3D"moz-cite-prefix">On 1/24/2023 10:43, Dr. Rolf Jansen wrote:<br =
class=3D""></div><blockquote type=3D"cite" =
cite=3D"mid:01070185e4732fd8-c0bede0b-d9df-4557-a174-cb237fa4bfaf-000000@e=
u-central-1.amazonses.com" class=3D""><div class=3D"" style=3D"word-wrap: =
break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">I =
sent an old ink to the thread on the mailing list, which does not work =
anymore. Here ist the new link:<div class=3D""><br class=3D""></div><div =
class=3D""><a =
href=3D"https://lists.freebsd.org/pipermail/freebsd-arm/2020-November/0227=
38.html" class=3D"moz-txt-link-freetext" =
moz-do-not-send=3D"true">https://lists.freebsd.org/pipermail/freebsd-arm/2=
020-November/022738.html</a></div><div class=3D""><br =
class=3D""></div><div class=3D""><div class=3D""><blockquote type=3D"cite"=
 class=3D""><div class=3D"">Am 24.01.2023 um 12:35 schrieb Karl =
Denninger &lt;<a href=3D"mailto:karl@denninger.net" =
class=3D"moz-txt-link-freetext" =
moz-do-not-send=3D"true">karl@denninger.net</a>&gt;:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div class=3D""><p =
class=3D"">Thank you -- will check it out.<br class=3D""></p><div =
class=3D"moz-cite-prefix">On 1/24/2023 10:35, Dr. Rolf Jansen wrote:<br =
class=3D""></div><blockquote type=3D"cite" =
cite=3D"mid:01070185e46b1a6e-ee34b885-1215-45c7-ac18-83320c02cac2-000000@e=
u-central-1.amazonses.com" class=3D""><div class=3D""><blockquote =
type=3D"cite" class=3D""><div class=3D"">Am 23.01.2023 um 11:41 schrieb =
Karl Denninger &lt;<a href=3D"mailto:karl@denninger.net" =
class=3D"moz-txt-link-freetext" =
moz-do-not-send=3D"true">karl@denninger.net</a>&gt;:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div class=3D""><p =
class=3D"">Is there support somewhere in the 13.x for other than "read =
current state" / "set current state"?</p><p class=3D"">Specifically, =
there is evidence in the sys/gpio.h header file that I can open up a =
file descriptor and then use select()/read() to grab the contents of a =
ring buffer of some size (presumably interrupt-posted) of events since =
last look, and determine if there's anything in there.&nbsp; Provided =
you're reasonably fast this might be enough to, for example, read an =
optical encoder that has a modest pulse rate.</p><p class=3D"">I see =
apparent review code at<span =
class=3D"Apple-converted-space">&nbsp;</span><a =
class=3D"moz-txt-link-freetext" =
href=3D"https://reviews.freebsd.org/D27398" =
moz-do-not-send=3D"true">https://reviews.freebsd.org/D27398</a><span =
class=3D"Apple-converted-space">&nbsp;</span>from late 2020, but nothing =
else I can find digging around; an example (assuming it is actually =
implemented and works) would be =
helpful</p></div></div></blockquote></div>See<div class=3D""><br =
class=3D""></div><div class=3D""><a =
href=3D"https://forums.freebsd.org/threads/gpio-api-general-orange-pi-h3.8=
3950/post-556728" class=3D"moz-txt-link-freetext" =
moz-do-not-send=3D"true">https://forums.freebsd.org/threads/gpio-api-gener=
al-orange-pi-h3.83950/post-556728</a></div><div class=3D""><br =
class=3D""></div><div class=3D"">And the messages in that thread that =
follow the one linked above.</div><div class=3D""><br =
class=3D""></div><div class=3D"">There is a respective thread on this =
mailing list as well:</div><div class=3D""><br class=3D""></div><div =
class=3D""><a =
href=3D"https://lists.freebsd.org/archives/freebsd-arm/2020-November/02274=
0.html" class=3D"" moz-do-not-send=3D"true">Porting FreeBSD to ARM =
processors: User Space GPIO Interrupt programming - =
GSoC-2018</a></div></blockquote><div class=3D"moz-signature">--<span =
class=3D"Apple-converted-space">&nbsp;</span><br class=3D"">Karl =
Denninger<br class=3D""><a href=3D"mailto:karl@denninger.net" =
class=3D"moz-txt-link-freetext" =
moz-do-not-send=3D"true">karl@denninger.net</a><br class=3D""><i =
class=3D"">The Market Ticker</i><br class=3D""><font class=3D"" =
size=3D"-2"><i class=3D"">[S/MIME encrypted email =
preferred]</i></font></div></div></div></blockquote></div><br =
class=3D""></div></div></blockquote><p class=3D"">So the answer at this =
point appears to be "not in the codebase and no indication on when/if it =
might be, but there are patches that are in some state of =
development.=E2=80=9C</p></div></div></blockquote>No, at this point =
(13.1-RELEASE) everything is in the kernel, no patches needed. Even the =
test tool made it into the source tree. It has only be renamed =
from&nbsp;gpioc_intr_test.c to&nbsp;gpioevents.c.</div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Verdana; font-size: 12px; font-style: normal; font-variant-caps: normal; =
font-weight: normal; letter-spacing: normal; orphans: auto; text-align: =
start; text-indent: 0px; text-transform: none; white-space: normal; =
widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><br =
class=3D""></div><div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, =
0, 0); font-family: Verdana; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
orphans: auto; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
text-decoration: none;" =
class=3D"">/usr/src/tools/test/gpioevents/gpioevents.c</div><div =
style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: =
Verdana; font-size: 12px; font-style: normal; font-variant-caps: normal; =
font-weight: normal; letter-spacing: normal; orphans: auto; text-align: =
start; text-indent: 0px; text-transform: none; white-space: normal; =
widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; =
-webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><br =
class=3D""></div><div style=3D"caret-color: rgb(0, 0, 0); color: rgb(0, =
0, 0); font-family: Verdana; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
orphans: auto; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D"">The documentation is missing. It is =
however easy to learn how things work by examining the code of =
gpioevents.c.</div><div style=3D"caret-color: rgb(0, 0, 0); color: =
rgb(0, 0, 0); font-family: Verdana; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; =
orphans: auto; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: auto; word-spacing: 0px; =
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; =
text-decoration: none;" class=3D""><br class=3D""><blockquote =
type=3D"cite" class=3D""><div class=3D""><div class=3D""><div =
class=3D"">Being able to read an encoder of some sort basically means =
being able to know how many events occurred between "looks"; for most =
purposes you don't need each event delivered exactly when it occurs, but =
missing some of the counts entirely is not =
acceptable.</div></div></div></blockquote><div class=3D""><br =
class=3D""></div><div class=3D"">Yes, and for this reason, this GPIO =
event code which was developed by&nbsp;Christian Kr=C3=A4mer in the =
course of the GSoC-2018 and has been submitted in 2020 by Ian Lepore to =
the freebsd tree is perfect.</div><div class=3D""><br =
class=3D""></div><div class=3D"">Ian tested it with a 10 MHz sqaure =
wave&nbsp;on an imx6 (ARMv7, 1GHz) and got an event every 10 =C2=B5s. =
That means the max. speed without event losses would be 100 kHz. I did =
not do exact measurements, however, my impression is that my RPi4B can =
do it a tad faster than my BeagleBone Black. With the RPi4, I needed to =
improve the debouncing of the encoder and the buttons, because it saw =
hundreds of bounces which the BBB didn=E2=80=99t. However, it may also =
be, that the internal GPIO circuits of the BBB have a different damping =
characteristic.</div><div class=3D""><br class=3D""></div><div =
class=3D"">Anyway for my applications, 100 kHz way faster than what I =
need.</div><div class=3D""><br class=3D""></div><div class=3D"">On my =
GitHub repository I placed another example on using the GPIO events for =
the RPi:</div><div class=3D""><br class=3D""></div><div class=3D""><a =
href=3D"https://github.com/cyclaero/shutdd" =
class=3D"">https://github.com/cyclaero/shutdd</a></div><div class=3D""><br=
 class=3D""></div><div class=3D"">See also the respective thread on this =
mailing list:</div><div class=3D""><br class=3D""></div><div class=3D""><a=
 =
href=3D"https://lists.freebsd.org/archives/freebsd-arm/2022-July/001576.ht=
ml" =
class=3D"">https://lists.freebsd.org/archives/freebsd-arm/2022-July/001576=
.html</a></div></div></body></html>=

--Apple-Mail=_A11E81C7-9742-46CA-9F56-79152AC5767A--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01070185e534f221-14f362b5-2b96-43f0-b0b0-f496ad9994fe-000000>