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