Read "Android Deep Exploration (Volume 1) HAL and drive Development" some thoughts 08

Source: Internet
Author: User

Compiling is a Linux driver that consists of multiple files. For complex Linux drivers, it is necessary to use multiple source code files to store different function codes, which facilitates the classification and management of the code.

Small experiment: Compile 3. c files into 3.0 files, and deliver these 3.0 file links to. ko files.

1. Write main.c files, as well as FUN.C, product.c, and product.h files.

2. Writing the makefile file

Obj-m: = MAIN.O

Multi_file_driver-y: = FUN.O PRODUCT.O

3. Execution of #sh build.sh

4. Execute the DMESG command to view the log information.

Another way of sharing code: module dependencies, also known as export symbols. The use of export symbols for code sharing is: using the exported symbols (constants, variables, functions, etc.) from another driver module in one drive module.

To uninstall a Linux driver module that cannot be uninstalled due to an exception condition:

1. Initialization function crashes

2. The Unload function is blocked

Buzzer (PWM) drive:

1. Principle: Through the pulse to control the buzzer to open and stop.

2. Implement buzzer driver.

PWM consists of 3 files: pwm.c, Pwm_fun.h, pwm_fun.c. Where PWM.C is the driver main program. Pwm_fun.h refers to the corresponding header file and defines some macros. The Pwm_fun.c file contains two functions (Pwm_start and Pwm_stop) that open and stop the PWM.

3. Test Buzzer Driver

Under the/data/local directory, enter the following command to turn on PWM.

#./ioctl/dev/pwm_dev 1 0

Enter the following command to stop the PWM.

#./ioctl/dev/pwm_dev 0 0

Through the study of this chapter, we have mastered the common code reuse methods of Linux drivers, and learned some ways to uninstall Linux drivers.

Read "Android Deep Exploration (Volume 1) HAL and drive Development" some thoughts 08

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.