Android HAL原理实现& GPS HAL实现


1 android HAL
框架

Android HALgoogle应厂商不希望公开源码的要求所推出的新概念。它能以封闭源码的形式提供硬件驱动模块,其目的是把Android Framework linux kernel隔开,让Android不至于过度以来linux kernelHAL提供了简单的设备驱动程序接口,应用程序使用设备驱动程序与底层硬件通信



     从上图看出,HAL位于linux KernellibrariesAndroid Runtime之间,也就是说HAL是底层硬件设备驱动程序提供给Framework的一个接口层,它将直接和底层的设备驱动程序挂接。因此当我们需要将Android移植到其他硬件上时,或者给Android系统添加新的硬件支持时,需要对AndroidHAL层进行移植或者实现。Android HAL层实现位于源码中的路径如下:

n         hardware/libhardware_legacy

n         hardware/libhardware/

n         hardware/ril/

2 Android HAL的实现

2.1 重要结构体定义

HAL的实现是一个硬件抽象层的框架,其硬件设备的具体操作由对应的stub进行间接的回调。HAL框架位于如下两个文件:

n         hardware/libhardware/include/hardware/hardware.h

n         hardware/libhardware/hardware.c

hardware.h中定义了三个重要的结构体:

n         struct hw_device_t

n         struct hw_module_t

n         struct hw_module_methods_t

下面分别介绍这三个重要的结构体。

结构体hw_device_t表示硬件设备,存储了各种硬件设备的公共属性和方法,其定义如下:

typedef struct hw_device_t {

    // 标记 HARDWARE_DEVICE_TAG */

    uint32_t tag;

    // 版本号 for hw_device_t */

    uint32_t version;

    // 该硬件属于哪一个module*/

    struct hw_module_t* module;

   //padding reserved for future use */

    uint32_t reserved[12];

    // 关闭设备操作

    int (*close)(struct hw_device_t* device);

} hw_device_t;

 

如果要移植或者添加新的硬件,那么都需要实用该结构体进行注册,其中tag必须初始化,结构体hw_module_t在进行加载的时候用于判断属于哪一个module,其定义代码如下:

typedef struct hw_module_t {

    //tag must be initialized to HARDWARE_MODULE_TAG */

    uint32_t tag;

    //major version number for the module */

    uint16_t version_major;

    //minor version number of the module */

    uint16_t version_minor;

    //module id,通过这个id找到相应的so文件和module*/

    const char *id;

  // Name of this module */

    const char *name;

    // Author/owner/implementor of the module */

    const char *author;

    // Modules methods */

    struct hw_module_methods_t* methods;

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值