9th chapter: Hardware Abstraction Layer HAL
1.HAL (Hardware abstraction layers, Hardware abstraction layer) is a set of flip fonts built on Linux drivers. This library is not part of the Linux kernel, but rather belongs to the application layer on top of the Linux kernel layer.
2. Steps to write a Linux driver that supports HAL
Writing a Linux driver that supports HAL is a bit more complicated than writing a normal Linux driver, and joining HAL makes the parts of the Library that make up the Linux drive more independent and easier to maintain.
1th Step: Writing Linux drivers
"Writing Linux drivers" is nonsense from the show, but if you want to add HAL to the Linux driver and want to protect sensitive data as much as possible. Linux-driven code needs to be as concise as possible to put business logic into hallibrary. 2nd step: Writing the HAL Library
The HAL library is an ordinary Linux library (*.so) file. However, this type of library file has an interface. Implemented by the HAL _module_info _ SYM variable. The Service Library locates the HAL library by the ID defined in this interface.
3rd Step: Writing the Service Library
The Service library is also a Linux library. This step is more flexible. The Service Library can be a generic Linux library, or it can be an I library. In this chapter, the LED driver example combined the Service Library with the JNI library. In other words, the Service library is the JNI library. In fact, this step should include a service management class (ServiceManager) written in Java, in addition to the *.so library file that is implemented in C/C + +. The Service Library is called by the ServiceManager. The APK program calls the ServiceManager class to access the Service Library.
3. Write the HAL module that calls the LED driver
The steps and principles for writing the HAL module are as follows.
1th Step: Defining structs and macros
2nd step: Writing the HAL module's Open function
3rd Step: Define HW_ module _methods_ t struct variable
4th step: Define the HAL_MODULE_INFO_SYM variable
5th step: Write the close function of the HAL module
6th step: Write the function that controls the LED
4. Write a Service that calls the HAL module missing
5. Write the Java library that invokes the Service
In fact, the HAL-based LED driver has been written so far, and the service library implemented earlier can be invoked through the NDK in an Android application. But to make the program easier to use, the Java class that invokes the service library can be packaged separately in the jar file, so that any Android application that references the Yang file can access the LED driver as if it were a normal Java class.
There are two ways to use Linux in an Android system. One is to interact directly with Linux drivers in a traditional way. For example, directly read and write data from a device file. Another is unique to Android, that is, through the HAL module, the HAL module essentially interacts with Linux drivers through a Linux shared library (. So) and then the application accesses the Linux shared library. Early HAL modules were called by the application directly by accessing the Linux common font. The higher version of the Android system adds a stub to HAL. In other words, specify an ID for each HAL shared library, and then use that ID to match a certain rule to find the Linux shared library. This allows the Linux shared library to replace the file name and move it conveniently (because neither the path nor the file name of the HAL shared library is dead).
9th chapter: Hardware Abstraction Layer HAL