android hal学习

1、分层图

              Framework and Applications
                                  |
              External Libraries and Runtime
                                 |
                        Android Hal
User Space               |
---------------------------------------------------
Kerne Space   linux Device Driver

 

2、目录和文件

hardware/telechips/tcc92xx/module/sensors

out/target/product/tcc8900/system/lib/hw/sensors.tcc92xx.so

 

3、数据结构

struct sensors_module_t {
    struct hw_module_t common;

    /**
     * Enumerate all available sensors. The list is returned in "list".
     * @return number of sensors in the list
     */
    int (*get_sensors_list)(struct sensors_module_t* module,
            struct sensor_t const** list);
};

 

//实例

const struct sensors_module_t HAL_MODULE_INFO_SYM = {
    .common = {
        .tag = HARDWARE_MODULE_TAG,
        .version_major = 1,
        .version_minor = 0,
        .id = SENSORS_HARDWARE_MODULE_ID,
        .name = "BMA220 & AK8975C Sensors TCC Module",
        .author = "Telechips, Inc.",
        .methods = &sensors_module_methods,
    },
    .get_sensors_list = sensors__get_sensors_list
};

 

 

4、函数调用

static jint android_init(JNIEnv *env, jclass clazz)
{
    sensors_module_t* module;
    /*
    *module相关信息
    */
    if (hw_get_module(SENSORS_HARDWARE_MODULE_ID, (const hw_module_t**)&module) == 0) {
        if (sensors_control_open(&module->common, &sSensorDevice) == 0) {
            const struct sensor_t* list;
            int count = module->get_sensors_list(module, &list);
            return count;
        }
    }
    return 0;
}

 

 

hw_get_module通过属性系统最后打开system/lib/hw/sensors.tcc92xx.so文件

 

/**
 * Name of the hal_module_info
 */
#define HAL_MODULE_INFO_SYM         HMI

#define HAL_MODULE_INFO_SYM_AS_STR  "HMI"

 

/*
*通过查找HAL_MODULE_INFO_SYM_AS_STR来找到HAL_MODULE_INFO_SYM数据结构

*因为每个hal_module都是作为一个so存在,所以变量名字是一样不会有冲突
*/
static int load(const char *id,
        const char *path,
        const struct hw_module_t **pHmi)
{
    struct hw_module_t *hmi;


    /* Get the address of the struct hal_module_info. */
    const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
    hmi = (struct hw_module_t *)dlsym(handle, sym);/*找到对应的数据结构*/
    if (hmi == NULL) {
        LOGE("load: couldn't find symbol %s", sym);
        status = -EINVAL;
        goto done;
    }
}

 

HAL最总是通过文件系统或者socket等方式和linux device driver进行通信,如分层图所示,HAL运行在用户空间。

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值