1、分层图
Framework and Applications | External Libraries and Runtime | Android HalUser 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运行在用户空间。