Results 1 to 2 of 2
I'm trying to read from a device from a user application using:
int* frame = (int*) malloc( 83 * sizeof(int));
FILE *ICAP;
ICAP = fopen("/dev/icap0", "w+b"); // The deivce is ...
- 09-22-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
Question about device read option count
I'm trying to read from a device from a user application using:
int* frame = (int*) malloc( 83 * sizeof(int));
FILE *ICAP;
ICAP = fopen("/dev/icap0", "w+b"); // The deivce is opened OK. "w+b" should mean "read and write, binary".
fread(frame, sizeof(int), 83, ICAP);
The device read operation is defined as:
static ssize_t hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
I have two problems:
1). inside the hwicap_read function, the value of count is 0x400, not 0x53 as I passed to fread;
2). frame does not get the read out data.
For 1), I do not have any clue ... why 0x53 is not used, but 400 (which seems like a default buffer size).
For 2), there seems to be something wrong when "copy_to_user". Inside some "low level" function that the driver read calls, I can see data are fetched, but not copied.
- 09-22-2009 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
2) is not an issue ... copy_to_user is OK. (even though kernel buffer is int* and user space buffer is char*).
However, the device I would like to read can not have arbitrary words to read. The read function must use a fixed value of count, like 83.
I guess for some device, the default value of count is OK to be 0x1000 or something, as long as the desired # of bytes are passed by fread.
Can someone tell me how to let the device read function has the exact count as fread passes?


Reply With Quote