Android Deep Exploration (iii)

Source: Internet
Author: User

Eighth Chapter

A hardware device on the buzzer Development Board. You can control the sound emitted by the buzzer by writing a specific value to the register. Down will introduce the use of buzzer principle, and realize the driver of the buzzer. The use of PWM drives differs from the use of LED drivers, which are made up of multiple files, which is the standard way to implement most Linux drives.

Compiled PWM driver, with multiple files composed of drivers. Although the two drivers implement different functions, but the two drivers of the source code is the same, the Linux driver module dependency, code reuse is divided into static and dynamic two kinds. Static reuse a piece of code can be compiled to eventually generate an executable file or library. This section describes a way to share code: module dependencies are also known as export symbols. Forcibly uninstall the Linux driver, if you write a Linux driver is logically correct, then you can load and unload normally. If an exception occurs in an unexpected environment, it cannot be uninstalled properly. is divided into initialization function crashes, initialization function does not return normally. The Unload function is blocked and successfully returned when the Unload function is called to complete smoothly. Otherwise, there will be a blockage.

The buzzer driver is a simple hardware that comes with the Development Board, and it beeps when it is opened. The basic principle is to open and stop the buzzer by means of a pulse control. PWM can be switched on and off via the I/O command. The IOCTL.PWM driver for the test-driven I/o command is similar to the LED driver implementation, and can be simpler. A simpler PWM driver is used to divide the Linux driver into multiple implementation files. Also learned more driver code, the control of the Development Board has a further understanding.

Nineth Chapter

Hal is a set of libraries built on Linux drivers that are not part of the Linux kernel, but that belong to the application layer on top of the Linux kernel layer. Google for Android to join HAL mainly has the following purposes: Unified hardware Call interface, solve the GPL copyright issues. The drive to join the HAL allows the application to interact with the Linux driver without needing to care about how the Linux driver and device files interact, just like accessing a generic API.

The rationale is that only 5 bytes are read or written from the specified register, and the 1th byte is used to specify read-write actions and register types. The latter 4 bytes are the actual data that is read and written. When interacting with the LED driver, the specified register can be read and written to the device file only if it reads or sends 5 bytes of data. Because the LED driver's device file receives not a string, but a byte-type of data, it is necessary to do a separate program to write data to the device file in bytes, or to read the byte-type data from the device file.

The steps and principles of writing a HAL module: defining structs and macros, writing the Open function of the HAL module, defining hw_module_methods_t struct variables, defining hal_module_info_sym variables, writing the close function of the HAL module, Write functions that control LEDs. The HAL module can be automatically called by the Android system and naturally has an interface like the main or init function, except that the interface is not a function but rather a fixed-name struct variable. That is, all HAL programs must have a variable. Linux drivers have two ways of interacting directly with Linux drivers in a traditional way, such as directly reading and writing data from a device file. The other is Android-specific, which is through the HAL module. The HAL module essentially interacts with the Linux driver through a Linux shared library, and then the application accesses the Linux shared library.

Tenth Chapter

For complex Linux drivers and libraries such as HAL, you need to debug them in a variety of ways, such as setting breakpoints, stepping through code, outputting debugging information, and so on. The PRINTK function runs in kernel space, and the printf function runs in user space.

Using the PRINTK function makes it easy to write messages to a log file or console, but using the PRINTK function to manipulate log files or console device files can severely affect the performance of Linux drivers, so this requires the Linux driver to output messages using the PRINTK function only during the development phase. The PRINTK function displays the message in the console through the/dev/console device file, which only works under the console of the character interface, so the PRINTK function is only used on the console of the character interface to output the message normally.

In Linux file systems,/proc is often used as a tool for data interaction between kernel space and user space. /proc is a virtual file system, so reading and writing/proc file systems is much faster than reading/writing/dev file systems. As a result, the/proc file system can also serve as a tool for Linux to interact with user-space programs. In Linux drivers, you can use kernel functions to create and delete virtual files in the/proc directory, as well as to establish and delete virtual directories. The/proc file system, like the/dev file system, also needs to set the action handler function that accesses the file, and the/dev file system through File_operations.read and File_ The Operations.write function pointer variable reads and writes the device file read-write action handler function. The Proc_dir_entry struct represents a virtual directory or file. The Android emulator can only use the Gdbserver debugger through port mapping, but the board can be connected to the Gdbserver in addition to the IP connection via the interface.

Android Deep Exploration (iii)

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.