2008-04-18 08:21:11 How to apply poll() function for char-device?
Ruslan Cray (GERMANY)
Message: 54476
I have a code but it don't work. I want to read data from /dev/sport0 only if sport0 have data. Overwise I have blocked thread - read() function block my thread. How can I do it?
sport.c
QuoteReplyEditDelete
2008-04-18 08:55:43 Re: How to apply poll() function for char-device?
Vitja Makarov (RUSSIAN FEDERATION)
Message: 54479 If you want to use polling, first of all you should ensure, that your character device do support poll().
It should implement poll() syscall as well as read() and write()
looking at bfin_sport I see it doesn't moreover looking at read() function I see that it's starts receiving only when read is called.
So you have to modify the driver to receive data after configuration was set and port enabled, that requires some kind of internal driver buffers with overhead on memory transfers from kernel to userspace. After you should implement poll
here is simple example:
static unsigned int simple_poll(struct file *filp, poll_table *wait)
{
struct simple_dev *pdev = (struct simple_dev *) filp->private_data;
if (!simple_dev_poll_condition(pdev))
poll_wait(filp, &pdev->poll_wq, wait);
if (simple_dev_poll_conditionpdev))
return POLLIN | POLLRDNORM;
return 0;
}
vitja.