- Why add HAL to Android
Goggle for Android to join HAL mainly has the following purposes:
The calling interface for unified hardware. Because HAL has a standard calling interface, HAL can be used to mask Linux to drive complex, non-uniform interfaces.
Fixed the GPL copyright issue. Because the Linux kernel is based on the GPL protocol, Android is based on Apache Licence 2. 0 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.
- Android HAL Architecture
- Added HAL for LED driver
- To write a Linux driver that supports HAL:
1th Step: Write the Linux driver; step 2nd: Write the HAL library; step 3rd: Write the Service Library
- Streamlined LED Driver
The rationale is to read or write only 5 bytes from the specified register. The 1th byte is used to specify the read-write action and the register type. The last 4 bytes are the actual data read and write (since the LED driver only involves the operation of a register of type int data, so use 4 bytes to represent an int type of data). When interacting with the LED driver, the specified register can be read and written to the device file (/dev/s3c64io_leds_hal) as long as it reads or sends 5 bytes of data.
- Test read-Write register operation
Each part of the program should be tested in the process of writing Linux drivers and driver-related programs.
Use the following command to execute the build.sh script file in the appropriate directory to test the accuracy of the LED code: SH build.sh
- : Write the HAL module of the chanting point led driver;
The steps and principles for writing the HAL module are as follows:
Step L: Defining structs and Macros: Writing HAL modules requires 3 very important structures (hw_module_t, hw_device_t, and hw _ Module_ method_ t), and in step l you need to define two new structures, the two of which are the first L The data type of a variable must be hw_module_t and bw_device_t. In addition, you need to define an ID for the HAL module. In fact, in this L-step is the code that writes the leds_hal.h header file.
2nd step: Write the HAL module's Open function:
- The Open function is the entry point for the HAL module. The function mainly does the following 3 tasks: Initialize the device_t of HW. Open the device file. Initializes the register.
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
- Writing a Service that calls the HAL module
Invoking the HAL module involves a very important hw_get_ module function. The function can find the LED HAL module by LED_HARDWARE_MODULE_ID macro defined in Leds_hal.h and obtain the led_module_t structure. Then call the LED _module_ T.HW _ Module.methods.open function to initialize the LED driver and return the led_control_device_t structure through the open function. The Led_control_device_ t struct contains the function pointers (set_on and Set_off) defined in the HAL module that control the LED driver.
- Storage path and naming rules for HAL modules:
There are two storage paths for HAL library files:/SYSTEM/LIB/HW and/VENDOR/LIB/HW. The Hw_get_module function looks for the library file from the/SYSTEM/LIB/HW directory based on the library file naming rules. If the library file is not found in the/SYSTEM/LIB/HW directory, the hw_get_ module will look in the/VENDOR/LIB/HW directory as the same rule.
The naming convention for HAL Module library files is ID.suffix.so. Where the ID is specified by the ID parameter of the hw_get_ module function. suffix (suffix) is specified through the properties file.
HW _get_module finds suffix in the properties file of the Android system in turn, based on the 4 keys defined in the Variant_keys array. If suffix is not found, the default suffix is used.
In fact, the properties file for the Android system has the following 4:
/default.prop;/system/build.prop; /system/default.prop; /data/local.prop.
- Writing a Java library that invokes a Service
The Java class that invokes the service library can be individually encapsulated in the jar file, so that any Android application that references the jar file can access the LED driver as if it were a normal Java class.
- Test LED Driver
The test program implemented in this section will control the LEDs by calling the Ledhalservice.seton and Ledhalservice.setoff methods.
Nineth Hardware Abstraction Layer: HAL