From: lkml@woutersimons.org (Wouter Simons)
To: kernelnewbies@lists.kernelnewbies.org
Subject: get info in a loop from a sysfs entry
Date: Tue, 04 Jan 2011 13:46:38 +0100 [thread overview]
Message-ID: <4D2316AE.7000503@woutersimons.org> (raw)
In-Reply-To: <4D22FAFB.20207@woutersimons.org>
On 01/04/2011 11:48 AM, Wouter Simons wrote:
> Hi all,
>
> This might be a silly question, but I want to make sure I understand
> things correctly.
>
> I have a driver with a sysfs entry to get the next data sample every
> time I read the file. Used like below it works wonderful:
>
> # cat next
> 0x15814
> # cat next
> 0x1682B
>
> The last 12 bits are the sample and the first (20) bits are the channel
> the sample is from (some ADC hardware board with 24 inputs).
>
> Now I have some C code that will loop periodically to collect the
> samples and do some magic with them and I was hoping I could simply keep
> a FILE * open with a loop like this:
>
> for (i = 0; i < count; i++) {
> if (fscanf(fd_next, "0x%X", &sample) != 1) { /* No data */
> continue;
> }
> channel = sample >> 12;
> adc_data = sample & 0xFFF;
> if (channel > 23) { /* Sample out of range */
> error_helper("ADC sample out of range", 0x32000010, 0);
> continue;
> }
> a_in[channel] = adc_data;
> fseek(fd_next, 0, SEEK_SET);
> }
>
> The problem is that after storing 1 sample, the next samples are never
> getting updated. I suppose the last line (fseek) does not cause the
> sysfs function to be called again as I hoped.
>
> But the sysfs documentation in the kernel says:
> If userspace seeks back to zero or does a pread(2) with an offset of '0'
> the show() method will be called again, rearmed, to fill the buffer.
>
> Can anyone tell me what I might be doing wrong?
>
I believe I have found the issue. The older kernel my driver is
currently running on (a 2.6.21 version maintained by the hardware
supplier) does not seem to rearm the show method on seek to 0.
crap...
Wouter
next prev parent reply other threads:[~2011-01-04 12:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-04 10:48 get info in a loop from a sysfs entry Wouter Simons
2011-01-04 12:46 ` Wouter Simons [this message]
2011-01-04 13:56 ` Greg KH
2011-01-04 14:35 ` Wouter Simons
2011-01-04 15:52 ` Dave Hylands
2011-01-05 8:35 ` Wouter Simons
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=4D2316AE.7000503@woutersimons.org \
--to=lkml@woutersimons.org \
--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).