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.
- 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
- Registering and unregistering device files
Any Linux driver requires a device file, or the application will not be able to interact with the driver.
- Specify driver-related information
The driver is self-describing.
- 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.
- Writing business logic
- Writing Makefile files
- Compiling Linux Drivers
- 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