Android Deep Exploration--sixth chapter reading notes and Experiences

Source: Internet
Author: User

Number of words Statistics program

--sixth chapter reading notes and Experience

Through this chapter, we learned to test Linux driver development using a variety of platforms. Learned to count the number of words of the program, through the program know that the implementation of the algorithm for the Linux driver, because the program's words are encapsulated in the Linux driver. Prior to this, we also had a deep understanding of Linux. Know the steps written by the Linux driver. Learned some important functions. Learned to register and unregister device files. Learned to make a callback function. Know how to develop and test Linux drivers in Eclipse.

The Linux system maps each driver to a file, called a device file or driver file, and is stored in/dev, making it easy to interact. The most important step in writing a Linux driver is to write a callback function, otherwise the data that interacts with the device file cannot be processed.

The Linux driver is written with the same specifications as most programs. The steps are as follows:

1. Build Linux Drive Skeleton

2. Registration and cancellation of equipment files

3, the development of information related to the drive

4. Make callback function

5. Write Business logic

6. Writing Makefile Files

7. Compiling Linux Drivers

8. Install and uninstall Linux drivers

The program that counts the number of words does not have access to the hardware but interacts with the application using the device files as media. Before writing the program, you need to set up a directory for the Linux driver, then create a driver source code file, and finally write the makefile file.

The PRINTK function is used in writing the skeleton of the driver-initialization and exit drivers. This function is used to output log information. Run in kernel space.

Install Linux driver: #insmod Xxx.ko

Check if XXX is installed successfully: #lsmod | grep xxx

Uninstall Linux driver: #rmmod xxx

You can use #modinfo XXX to view the information in Xxx.ko.

When writing registration and unregistering device files, it is important to note that the device files are described by the main device number and the secondary device number, and the Misc_register function can only set the secondary device number. File_operation structure weight defines the callback function pointer variable. If the device file Misc_register is successfully registered, the return value is a non-0 integer, or 0 if it fails.

When writing code, it is important to note that because kernel-space programs do not have direct access to user-space data, you need to use Copy_to_user and copy_from_ separately in the Word_count_read and Word_count_write functions. The user function copies data from the kernel space to the user space or from the user space to the kernel space.

Many of the platforms that test Linux drive include Ubuntu Linux, Android Simulator, and s3c6410 Development Board.

Developing a driver in eclipse requires first building a C project, then building a C source file link, then setting the include path, and compiling the Linux driver. To test Linux drivers in Eclipse, you first need to import the. c file, then set the include path, then set the target, then bulid the project, and finally run the test program.

Android Deep Exploration--sixth chapter reading notes and Experiences

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.