Nineth Hardware Abstraction Layer: HAL

Source: Internet
Author: User
Tags naming convention

    1. 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.

    1. Android HAL Architecture
    1. Added HAL for LED driver
      1. 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

    1. 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.

    1. 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

    1. : 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

    1. 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.

    1. 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.

    1. 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.

    1. 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

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.