I'm starting to learn Linux driver development. I am trying to create a simple driver that polls a function which in the end will read a hardware register at a constant rate (ie 10 times a second) and adds the hardware output to a queue which can then be accessed by procfs.
First things first. I need to be able to poll at a consistent rate. I have been reading this online a lot and it seems very simple (my code below). However, when I insmod my module, it doesn't seem to poll at all!!
Can someone please help me understand this and help me figure out what I need to do to make it poll?
I really appreciate you guys' help!
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/version.h>
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/ioport.h>
#include <linux/poll.h>
MODULE_LICENSE("Dual BSD/GPL");
int silly_open(struct inode *inode, struct file *filp)
{
printk(KERN_ALERT "open\n");
return 0;
}
int silly_release(struct inode *inode, struct file *filp)
{
printk(KERN_ALERT "release\n");
return 0;
}
ssize_t silly_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
printk(KERN_ALERT "read\n");
return 0;
}
ssize_t silly_write(struct file *filp, const char __user *buf, size_t count,
loff_t *f_pos)
{
printk(KERN_ALERT "write\n");
return 0;
}
unsigned int silly_poll(struct file *filp, poll_table *wait)
{
printk(KERN_ALERT "poll\n");
return POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM;
}
struct file_operations silly_fops = {
.read = silly_read,
.write = silly_write,
.poll = silly_poll,
.open = silly_open,
.release = silly_release,
.owner = THIS_MODULE
};
int silly_init(void)
{ printk(KERN_ALERT "init\n");
return 0;
}
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
In hello_init(), you don't connect silly_fops to it. It cannot work automatically if there is no any connection between them.
In order to connect, you probably need to initialize a device with silly_fops(), refer to ch3.4 of ldd3 at http://www.makelinux.net/ldd3/ , hope this works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.