Android Deep Exploration (iii)

Source: Internet
Author: User

Eighth Chapter

This chapter will introduce the implementation of the buzzer to the original plow and achieve a complete buzzer drive (can turn the buzzer on and off). Linux-driven code reuse, you can use the standard C program method to put the code that will be reused in other files. If you want to use some features, include the corresponding header file, it can also be another way of dynamic reuse, but also a Linux driver can use the resources in another Linux drive. The buzzer is a hardware device on the s3c6410 Development Board.  You can control the buzzer by writing a specific value to the register. PWM time-driven implementation is different from the LED driver, the PWM driver will be composed of several files. This is also the standard implementation of most Linux drivers. These files are co-compiled when the Linux driver is compiled. This section describes how to divide a Linux drive into multiple files. The data structure, function code in these files can also be used by several different drivers, so this is also an important method of code reuse. The PWM drive is similar to the LED driver implementation process and may be simpler. In this chapter it is only to demonstrate how to divide a Linux driver into multiple implementation files before using a relatively simple PWM driver. Through the study of this chapter, we can master the common code reuse mode of Linux driver.

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.

Enable the LED driver to read and write the specified registers in the read and write functions of the device file. 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 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-body variable hal_module_info_ SYM. In other words, all HAL programs must have a HAL_MODULE_INFO_SYM variable. 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, Writing functions to control LEDs

There are two ways to use Linux drivers in an Android system, and one is to interact 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.

Initializing Linux drivers

Static int _init printk_demo_init (void)

Uninstalling Linux Drivers

Static void _exit printk_demo_exit (void)

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.