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

_______________________________________________
Kernelnewbies mailing list
[email protected]
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to