HAL

1) libhardware_legacy

是将 .so 文件当作shared library来使用,在runtime(JNI 部份)以 direct function call 使用 HAL module。通过直接函数调用的方式,来操作驱动程序。当然,应用程序也可以不需要通过 JNI 的方式进行,直接加载 .so (dlopen)的做法调用*.so 里的符号(symbol)也是一种方式。总而言之是没有经过封装,上层可以直接操作硬件。

2) libhardware

HAL stub 是一种代理人(proxy)的概念,stub 虽然仍是以 .so檔的形式存在,但HAL已经将 .so 档隐藏起来了。
这些硬件模块都编译成xxx.xxx.so,目标位置为/system/lib/hw目录
上层仅仅链接libhardware.so, 调用hw_get_modules 获取相应的模块,加载相应的库。

1. HAL 硬件抽象层规范
HAL_MODULE_INFO_SYM
hw_module_t
HARDWARE_MODULE_TAG

1) 所有的hal模块都要有一个以HAL_MODULE_INFO_SYM命名的结构,而且这个结构要以hw_module_t开始,即要继承hw_module_t这个结构,比如sensor:

struct hw_module_t HAL_MODULE_INFO_SYM={};

2) 实例变量名必须为HAL_MODULE_INFO_SYM,tag也必须为HARDWARE_MODULE_TAG.

struct sensors_module_t {
 struct hw_module_t common;
int (*get_sensors_list)(struct sensors_module_t* module,
            struct sensor_t const** list);
};
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;
/** Identifier of 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; //硬件模块的方法
/** module's dso */
void* dso;
 /** padding to 128 bytes, reserved for future use */
uint32_t reserved[
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值