kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* get info in a loop from a sysfs entry
@ 2011-01-04 10:48 Wouter Simons
  2011-01-04 12:46 ` Wouter Simons
  2011-01-04 15:52 ` Dave Hylands
  0 siblings, 2 replies; 6+ messages in thread
From: Wouter Simons @ 2011-01-04 10:48 UTC (permalink / raw)
  To: kernelnewbies

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?

Wouter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-01-05  8:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-04 10:48 get info in a loop from a sysfs entry Wouter Simons
2011-01-04 12:46 ` Wouter Simons
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

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).