【Android系列1.2 HAL---硬件抽象层- 驱动规范 】

6 篇文章 0 订阅

HAL

hardware module(硬件模块、驱动)的规范

HAL 对比 应用开发(驱动开发)

  • 就是FrameWork层(内核)
  • Activity(hw_module_t)
  • Activity.onCreate (*open)

规范

  • 必须”继承“自hw_module_t
    • 作者、版本等描述
    • 实现 hw_module_methods_t 结构体(内 有个函数指针 open)

/hardware/libhardware/include/hardware/Hardware.h

typedef struct hw_module_t {
	struct hw_module_methods_t* methods;
	...
} hw_module_t

typedef struct hw_module_methods_t {
	int (*open) (const struct hw_module_t* module, const char( id, struct hw_device_t** device);
} hw_module_methods_t

typedef struct hw_device_t {
    /** tag must be initialized to HARDWARE_DEVICE_TAG */
    uint32_t tag;
    /** version number for hw_device_t */
    uint32_t version;
    /** reference to the module this device belongs to */
    struct hw_module_t* module;
    /** padding reserved for future use */
    uint32_t reserved[12];
    /** Close this device */
    int (*close)(struct hw_device_t* device);
} hw_device_t;

gralloc_module_t是 hw_module_t的”子类“

  • 所谓"继承"(c语言没有继承),”子类“第一个成员变量 是”父类“
typedef struct gralloc_module_t {
struct hw_module_t common;
int (*registerBuffer)(***)
int (unregisterBuffer)(***)
//还有 lock、unlock、perform、reserved_proc
  1. HAL通过hw_get_module函数获取hw_module_t
  2. HAL通过hw_module_t->methods->open获取hw_device_t指针,并在此open函数中初始化hw_device_t的包装结构中的函数及hw_device_t中的close函数,如gralloc_device_open。
  3. 三个重要的数据结构:
    • struct hw_device_t: 表示硬件设备,存储了各种硬件设备的公共属性和方法
    • struct hw_module_t: 可用hw_get_module进行加载的module
    • struct hw_module_methods_t: 用于定义操作设备的方法,其中只定义了一个

举例

针对图像相关的硬件模块 Malloc

声明Gralloc硬件模块

typedef struct gralloc_module_t {
    struct hw_module_t common;
    ....

调用Gralloc 硬件模块

hw_module_t const* module;
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值