下面是代码. 就是想做一个定时器实验...
#include <linux/module.h> /**/ #include <linux/kernel.h> /*printk()*/ #include <linux/fs.h> /*file_operations*/ #include <linux/cdev.h> /*cdev_init() cdev_add()*/ #include <linux/types.h> /*size_t*/ #include <linux/stat.h> /*dev_t*/ #include <linux/timer.h> /*timer_list and timer API*/ #include <linux/slab.h> /*kmalloc() kfree()*/
#define DEV_NUM 1 #define NAME "timer"
struct timer_list *timer; int tmajor; int tminor; struct cdev *dev; int tdelay = 1000; int count;
void timer_fn(unsigned long data) { count++; printk(KERN_INFO "timer start is already %d sec\n", count); timer->expires += tdelay; add_timer(timer); }
static int topen(struct inode *node, struct file *pfile) { return 0; }
static int trelease(struct inode *node, struct file *pfile) { return 0; }
static ssize_t twrite(struct file *pfile, const char __user *buff, size_t count, loff_t *f_pos) { return 0; } 保存下来一般用kdump就好了,配置下
问题好像出在alloc_chrdev_region
没有初始化
|