The sixth chapter mainly studies the knowledge about the development of Android bottom, this chapter mainly introduces the first Linux driver: Count the number of words. Linux-driven work and access is one of the highlights of Linux. The Linux system maps each driver into a single file, which is called a device file or driver file, and is stored in the/dev directory. This design concept makes interacting with Linux drivers as easy as interacting with ordinary files. Of course, it's easier than visiting Linuxapi. Since most Linux drivers have their corresponding device files, exchanging data with the Linux driver becomes the exchange of data with the device files. For example, to send a print command to a Linux printer driver, you can open the device file directly using the C function open, and then use the C function ioctl to send the print command to the drive's device file.
The first steps to write a Linux driver are:
1th Step: Build Linux drive skeleton;
2nd Step: Registration and cancellation of equipment files;
3rd Step: Specify the information related to the drive;
4th step: Specify the callback function;
5th step: Write the business logic;
6th step: Write Makefile file;
7th step: Compiling Linux drivers;
8th step: Install and uninstall Linux drivers;
Then we have a driving example to count the number of words. Instead of accessing the hardware, the driver interacts with the application using the device files as media. The application passes a space-delimited string to the device file (each substring separated by a space is called a word), and the number of words that the string contains is read from the device file.
Then test the Linux driver, and the next step is to test the module. There are many ways to test--the most common is directly in. Tested in Ubuntu Linux. Of course, this is not a problem for Linux drivers that are implemented in this chapter, but it is not very convenient for drivers that need direct access to hardware to test on Ubuntu Linux, in which case they need to be tested on the appropriate hardware.
The final thing is to develop and test Linux programs in Eclipse.
For the development of this process:
1th Step: Establish C project;
2nd step: Establish C source code file link;
3rd Step: Set the Include path;
4th step: Compiling Linux drivers;
For testing this process:
1th Step: Import test_word_count.c file;
2nd step: Set the Include path;
3rd step: Set Target;
4th Step: Build project;
5th step; Run the test program.
Sixth Chapter Experience