From: lroluk@gmail.com (Luca Ellero)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Implementing a driver that listen to a GPIO
Date: Fri, 03 Oct 2014 11:37:31 +0200 [thread overview]
Message-ID: <542E6E5B.1050203@gmail.com> (raw)
In-Reply-To: <CAAVVKahg=Hsfewb-RZ_Qk2a7L7BsDYM0z13f5vu_dT-R2y5FLQ@mail.gmail.com>
Hi,
On 03/10/2014 02:33, Jinqiang Zeng wrote:
> 2014-10-02 10:01 GMT-07:00 Clemens Gruber <clemens.gruber@pqgruber.com>:
>> Hi,
>>
>> I am just trying to solve a similar problem as Luca described. I have a
>> TQMa28 board running Linux 3.17-rc7 though.
>> The capacitors keep the system up for about 1500 more milliseconds after
>> the power fails. A GPIO line is set to high as soon as the main power is
>> lost.
>>
>> So I have not much time to quit an important user space process and to
>> clean up the ext4 root filesystem before the power fails.
>>
>> At the moment I pass rootflags=data=journal,commit=1 in the kernel
>> commandline to lower the risk of data loss.
>> In the user space application I open important files using the O_SYNC flag.
>>
>> Is there something else I should do to avoid data loss?
>>
>> How would you implement the "emergency cleanup on power-failure" logic?
>> Dedicated driver (similar to the mentioned gpio-event driver?),
>> implement it with UIO, let a userspace application running as root
>> select /dev/uioX and cleaning up?
> how about using netlink to notify the usersapce app on gpio interrupt .
thanks to all for your replies.
Anyway, I solved the issue simply using the GPIO driver (no kernel
modifications needed):
- export GPIO number (es 7):
$ echo 7 > /sys/class/gpio/export
- set direction:
$ echo "in" > /sys/class/gpio/gpio7/direction
- set event that triggers interrupt:
$ echo "falling" > /sys/class/gpio/gpio7/edge
Then I create a user space application that executes a poll system call
on "/sys/class/gpio/gpio7/value".
Regards
---
Luca Ellero
http://http://www.brickedbrain.com
next prev parent reply other threads:[~2014-10-03 9:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 17:01 Implementing a driver that listen to a GPIO Clemens Gruber
2014-10-03 0:33 ` Jinqiang Zeng
2014-10-03 9:37 ` Luca Ellero [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-10-02 8:03 Luca Ellero
2014-10-02 12:52 ` Greg KH
2014-10-02 14:39 ` Luca Ellero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=542E6E5B.1050203@gmail.com \
--to=lroluk@gmail.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).