Welcome to reprint, reproduced in the need to retain the author's information, thank you.
Email:[email protected]
Blog Park Address: http://www.cnblogs.com/embedded-tzp
CSDN Blog Address: Http://blog.csdn.net/xiayulewa
1.1.1. Device number
Alloc_chrdev_region (&dev, 0, 1, "buttons")/ register_chrdev_region: Dynamic Request device number , the device number makes up the linked list node.
The final result is: allChar Devare available throughHashtable to index. Index consistent,Majorsmall in front, as above1,Majorconsistent, thenMinorsmall in the front.
1.1.2. Equipment
Cdev_init (&led_cdev, &led_fops)/Cdev_add (&led_cdev, Dev, 1): Added toProbearray of pointers, the device number is an index, according toRangefrom small to large lists, the list contains a lot of information, includingstruct Cdev,See.
by the above discussion, the device number can be indexed to devices and drivers, in /dev/ After adding the device node, the application in open The device is ready to operate.
of course, you can use automatic device creation :
cls = class_create (This_module, "LEDs"); // create /sys/class/leds/
device_create (CLS, null, dev, null, "myled"); // Create /sys/class/leds/myled
"Linux Drive Notes" character device driver related data structure and algorithm