Android Deep Explore (Vol. 1) Hal with Driver development Eighth Chapter reading notes

Source: Internet
Author: User

With the principle of buzzer, a complete buzzer driver can be turned on and off. PWM drives are implemented differently than led drivers, and the PWM driver consists of multiple files. This is also the standard implementation of most Linux drivers.

The first is led-driven code reuse, and there are many ways to reuse Linux-driven code. The standard C program can be used in the way. Put the code you want to reuse in a different file (declared in the header file). If you want to use some features, include the corresponding header file (this way is called static reuse). You can also use another way of dynamic reuse, which means that a Linux driver can use resources (functions, variables, macros, and so on) from another ← Linux driver. The next step is to forcibly uninstall the contents of the Linux driver, this section of the method can only unload from the exception caused by the Linux driver module can not be uninstalled.

Scenario 1: White initialization function crashes

Scenario 2: The Unload function is blocked

Buzzer driver buzzer driven principle buzzer is also called PWM (pulse width modulation), the basic principle is to control the buzzer by pulse to open and stop. Implement buzzer driver Test buzzer driver

The PWM driver is similar to the principle of the LED driver, as long as an experiment is made, and the other one will understand. But the code needs to be carefully written to understand the steps involved in running

With the I/o command to open and stop the PWM, thePWM Drive consists of 3 files: pwm.c, Pwm_fun.h,pwm_fun.c.

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 .

< Span lang= "en-US" > After running, from makefile file, you can see that

< Span lang= "en-US" > 1, first compiled pwm.c and pwm_fun.c files into pwm.o and pwm_fun.o < Span lang= "en-US" >

< Span lang= "en-US" > 2, and then the two *.o file links to pwm_driver.o< Span lang= "en-US" > < Span lang= "en-US" >

< Span lang= "en-US" > < Span lang= "en-US" >3, finally generating pwm_driver.ko.

< Span lang= "en-us" > Next Test buzzer driver, first enter/root/drivers/ioctl directory, execute build script file compilation and upload Span lang= "en-US" >ioctl file (if you start multiple android devices, select upload to s3c6410 Development Board. Before testing the PWM driver, the PWM driver is compiled and installed according to the previous section, and then the i of the Development Board terminal is entered. data/local directory, enter the explicit opening and closing pwm. Because ioctl command must require input i/o command parameters, but PWM driver is not using i /o command parameter. So ioctl the last command line argument can be entered arbitrarily. After executing the above command, if output (#./ioctl/dev/pwm_dev 1 0) information, and pwm. can scream normally, stating PWM Drive test succeeded.

Pwm

Reuse of Linux code:

Loading in a header file can be used for all of the original functions, and the dynamic way is to drive a resource using another driver.

For experiments like a buzzer, there are many internal files, all of which have a lot of source code for proper management.

With multiple files, module-y specifies all the files and then generates a build.sh script that executes with SH and uses DMESG to view the log information.

Code reuse is divided into static and dynamic. Static reuse is the generation of. Ko cores, dynamic reuse is a module dependency, and one driver uses symbols derived from another driver module.

Restart the Development Board or emulator. ko files will automatically disappear. Use exception Condition Uninstall: 1. Initialize function unload. 2. The Unload function is blocked

To unload a driver, you need to enter a bunch of commands to query the first address of the module struct, install and download the Force_kill_driver driver.

The driving principle of the buzzer is basically the same as the LED, but the implementation is different because PWM is made up of multiple files.

The basic principle of PWM is to control the buzzer's opening and stopping by means of pulses. The Gpfcon uses only the highest two bits to control the PWM.

static function structure, PWM device file Open function, use semaphore control at the same time only to open the PWM device file, then the close function to release the semaphore, the IOCTL () function to handle I/O command, set the file device File_operation device, finally in the most open The semaphore is initialized and the semaphore is removed. In the pwm.h file Pwm_iotcl_start Open, Pwm_iotcl_stop stop, here in the Linux bottom driver, there is a detailed, build. ko file, compiled successfully.

Test buzzer generally use the parameters of I/o command, can sound normally.

Android Deep Explore (Vol. 1) Hal with Driver development Eighth Chapter reading notes

Related Article

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.