Android Deep Explore (Vol. 1) Hal with Driver development sixth Chapter One Linux driver: Count the number of words reading notes

Source: Internet
Author: User

This chapter is a concrete example of the complete process of developing and testing a Linux driver. Especially test Linux drivers. In this example of counting the number of words, the emphasis is on the implementation of the algorithm: the Linux driver, not how to count.

What is the 6.1Linux drive?

Linuxthe way the driver works and how it is accessed isLinuxone of the characteristics. Linuxeach driver is mapped into a file, which is called a drive file or device file, saved inDevthe directory. Since mostLinuxdrivers have their corresponding device files, so theLinuxthe drive Exchange data becomes the exchange of data with the device file. In fact, writingLinuxdrivers also require more advanced functionality, such as writing data to the printer driver, which requires the printer driver to accept the data being written, and the disease passes through the port orUSBwait for the serial port to send to the printer. To implement this process, you need toLinuxthe driver can respond to the data that the application passes over. Is thatLinuxthe event that is driven is the callback function.

6.2 Steps to write Linux drivers

Linux drivers have their own rules as well as other types of Linux programs.

    1. Build Linux driver skeleton (load and unload Linux drivers)

Any type has a basic structure, such as c language requires an entry function main linux linux system needs to exit when you need to uninstall linux drive, to release linux drives resources such as deleting device files, freeing up memory address space, and so on. linux driver requires 2 module_init and module_exit

    1. Registering and unregistering device files

Any Linux driver requires a device file, or the application will not be able to interact with the driver.

    1. Specify driver-related information

The driver is self-describing.

    1. Specifying a callback function

many of the actions included in the Linux driver can also be referred to as events. The callback function is registered through the relevant mechanism.

    1. Writing business logic
    2. Writing Makefile files
    3. Compiling Linux Drivers
    4. Installing and uninstalling Linux Drivers

The first 5 steps above are the next three steps in how to write a Linux driver to make Linux drivers work correctly.

6.3 First Linux Driver: Count the number of words

1. first establish The directory where the Linux driver is stored, and then create the source code file. Finally write a makefile file

2. writing The skeleton of a Linux driver

Install Linux driver:insmod Word_count.ko

To see if word_count is installed successfully : lsmod | grep word_count

Uninstall Linux driver:rmmod word_count

View log information from Linux driver output:dmesg | grep word_count | tail –n 2

3. specify driver-related information

4. registering and unregistering device files

5. specifying a callback function

6. Implementing the algorithm

7. compiling, installing, and uninstalling Linux Drivers

This chapter also describes a number of test Linux drivers.

Software 1308 class 31st Zhang Fan Blog Park address: http://home.cnblogs.com/u/sxauzzz/

Android Deep Explore (Vol. 1) Hal with Driver development sixth Chapter One Linux driver: Count the number of words reading notes

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.