Reading notes the sixth chapter

Source: Internet
Author: User

First Linux driver: Count the numbers of words

What a Linux driver is.

Programmers who have not been exposed to driver development may feel that Linux drivers are mysterious, but this is completely a misunderstanding. The Linux system maps each driver into a file, called a device file or a drive file, and is stored in/dev. This allows the exchange of data with the Linux driver to be equivalent to exchanging data with the device file. One of the concepts that is similar to an event is to write a callback function, otherwise data that interacts with the device file will not be processed.

Steps to write a Linux driver

    1. Build Linux driver skeleton (load and unload Linux drivers)
    2. Registering and unregistering device files
    3. Specify driver-related information
    4. Specifying a callback function
    5. Writing business logic
    6. Writing makefile Files
    7. Compiling Linux Drivers
    8. Install and uninstall Linux drivers.

Count the number of words:

1. Before writing the Linux driver: set up a directory to store Linux drivers and write makefile files. 2. Write the skeleton of the Linux driver: The printf function runs in user space, and the PRINTK function runs in kernel space. Install Linux drivers, see if Word_count installs successfully, uninstall Linux drivers, and view log information.        3. Specify driver-related information: #modinfo Word_count.ko to view word_count.ko information. 4. Registering and unregistering device files:

# define Device_name "WordCount" to define device files

Static struct Miscdevice misc = {}; Information describing the device file

ret = Misc_register (&MISC); Create a device file

Misc_deregister (&MISC); removing device files

5. Specify the callback function: the Word_count_read and Word_count_write functions separately handle reading data from the device file and writing data to the device file.

6. The algorithm that implements the statistic word number.

7. Compile, install, and uninstall Linux drivers.

Reading notes the sixth chapter

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.