"Linux Drive Notes" character device driver related data structure and algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.