- UID
- 1029342
- 性别
- 男
|
/*注册设备*/ static int ds18b20_init(void)
{
int result;
dev = MKDEV(ds18b20_major,0);
if(ds18b20_major)
result = register_chrdev_region(dev,1,"ds18b20");
else{
result = alloc_chrdev_region(&dev,0,1,"ds18b20");
ds18b20_major=MAJOR(dev);
}
if( result < 0 ){
printk(KERN_WARNING"ds18b20:unable to get major %d\n",ds18b20_major);
return result;
}
if(ds18b20_major == 0 )
ds18b20_major = result;
ds18b20_setup_cdev();
printk("ds18b20 initialized.\n");
return 0;
}
static void __exit ds18b20_exit(void)
{
dev_t devno = MKDEV (ds18b20_major, 0);
device_destroy(my_class,devno);
class_destroy(my_class);
cdev_del (&cdev);
unregister_chrdev_region (devno, number_of_devices);
printk("ds18b20_major=%d\n",ds18b20_major);
printk("ds18b20 device uninstalled\n");
}
module_init(ds18b20_init);
module_exit(ds18b20_exit); |
|