Re: get info in a loop from a sysfs entry

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux