Eighth Chapter
Make the Development Board sound: Buzzer driver
Buzzer is s3c6410 a hardware device on the Development Board. You can control the buzzer by writing a specific value to the register. The introduction of the buzzer to realize the original plow, and the realization of a complete buzzer drive, can open and close the buzzer when the drive is implemented differently than the LED PWM Drive will be composed of multiple files. This is also the standard implementation of most Linux drivers, which means that a complex driver is unlikely to put all the code in a file. It is a good idea to put the closed code in the appropriate file. 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, which is also an important method of code reuse.
Linux There are many ways to drive code reuse. It is divided into static reuse and dynamic reuse, and static reuse is code-level reuse, which is to compile the code that needs to be reused and the use of the code, and eventually generate an executable file or library (. Ko and . So , etc.). Code sharing is the use of symbols (constants, variables, functions, etc.) that are exported from another driver module in one drive module.
If you write a Linux The driver is correct, then it can be loaded and unloaded normally, but in some cases, some programs may have abnormal conditions, Linux The driver may not uninstall properly. If you test the Linux driver in a way that dynamically loads . Ko files on the emulator or board, even if the Linux driver cannot be uninstalled properly , As soon as you restart the emulator or board, the dynamic Linux module is unloaded from memory.
Nineth Chapter
Hardware Abstraction Layer : HAL
The
HAL Hardware Abstraction layer is a set of libraries built on the Linux Drive. This library is not part of the Linux kernel, but belongs to the application tier on the Linux kernel layer. In the traditional Linux system, Linux drivers generally have two types of code. Google for Android join HAL has the following main purpose: to unify the calling interface of the hardware. Because the Hal has a standard calling interface, you can use Hal to block Linux Drive Complex, non-uniform interfaces; resolved GPL The protocol, for some special requirements. For some hardware, you may need access to some user-space resources, or work that is inconvenient in kernel space and special needs. In this case, you can use the HAL code located in the space to help Linux do some work.
Hal is built on Linux a set of libraries on top of the driver. This library is not part of the Linux kernel but is the application layer on top of the Linux kernel layer.
Google to be Android Join Hal The main objectives are as follows: 1 , and a unified hardware calling interface. 2, solve the GPL copyright issue. 3, for a number of special requirements.
Write a support Hal of the Linux Driver steps: 1 , writing Linux Drive 2 , writing Hal Library3 , writing Service Library .
Write HAL the steps and principles of the module are as follows: define structures and macros; Write HAL module's Open function; definition hw_module_methods_t structure variables; definition Hal_module_info_sym variables; Write HAL module's Close function;
Write Control LED the function;
Support HAL of the Linux The driver steps are as follows: 1. write Linux drivers;2. Write HAL Library ; 3. writing Service Library;
HAL The module is essentially through Linux Shared Libraries ( . so ) and Linux the driver interacts, and then the application re-accesses Linux shared libraries and Linux the driver interacts, and then the application re-accesses Linux shared libraries. Each HAL Shared library specifies an IDand then uses this ID to match certain rules to find Linux shared libraries.
Tenth Chapter
Embedded Linux The Debugging Technology
for the complex Linux Drive and HAL libraries, you need to debug them using a variety of methods. For example, setting breakpoints, stepping through code, outputting debugging information, and so on.
PRINTK the use of functions and printf function is similar, except PRINTK function runs in kernel space, printf The function runs in user space. In other words, linux kernel programs like Linux drivers can only output debugging information using the PRINTK function. The PRINTK function is implemented in the printk.c file.
while using PRINTK the function can easily write messages to the log file or to the console. However, heavy use of the printk function to frequently manipulate log files or console device files (/dev/console) can severely affect Linux Drive Performance (so the write disk is much faster than reading and writing memory), so this requires the Linux driver to use PRINTK only during the development phase function output information to remove the printk function that may affect performance when the Linux driver is officially released .
Kgdb consists of two parts, Kgdb the kernel and a set of connections mouth. Although it is easy to write messages to the log file or console using the PRINTK function. However, heavy use of the PRINTK function to frequently manipulate log files or console device files (/dev/console) can severely affect Linux Drive performance (so the write disk is much faster than reading and writing memory), so this requires Linux drivers are used only during the development phase PRINTK function output information, in the official release Linux may affect performance when driven. PRINTK function is removed.
Android Deep Explore Reading notes