附上源码
int car_open(struct inode * inode,struct file *filp)
{
return 0;
}
int car_release(struct inode *inode,struct file *filp)
{
return 0;
}
static struct file_operations car_fops = {
.owner = THIS_MODULE,
.open = car_open,
.ioctl = car_op,
.release = car_release,
.write = car_write,
};
static int __init car_init(void)
{
int ret;
//get the devid
if(major_number)
{
devid = MKDEV(major_number,minor_number);
ret = register_chrdev_region(devid,1,DEVICE_NAME);
}
else
{
ret = alloc_chrdev_region(&devid,minor_number,1,DEVICE_NAME);
major_number = MAJOR(devid);
minor_number = MINOR(devid);
}
if(ret <0)
{
printk(KERN_ALERT "can't get the major_number\n");
goto err1;
}
//add the cdev
dev = cdev_alloc();
dev->ops = &car_fops;
cdev_init(dev,&car_fops);
ret = cdev_add(dev,devid,1);
if (ret)
{
printk(KERN_ALERT "adding cdev error\n");
goto err2;
}
// init the car pin
//con6杩炴帴閬ユ帶杞﹁?鏄? //寮曡剼 璇存槑 鏂瑰悜 棰滆壊
//2 鐢靛帇 3.3V
//3 鎺ュ湴
//10 EINT1/GPF1 鍙? 绾? //12 EINT3/GPF3 宸? 鐧? //14 EINT5/GPF5 鍓? 榛? //16 EINT8/GPG0 鍚? 缁? //
//鍚勫唴瀛樺崟鍏冩帶鍒跺湴鍧