日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

android系统开发(六)-HAL层开发基础

發(fā)布時(shí)間:2023/12/20 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android系统开发(六)-HAL层开发基础 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Android HAL層,即硬件抽象層,是Google響應(yīng)廠(chǎng)家“希望不公開(kāi)源碼”的要求推出的新概念
1,源代碼和目標(biāo)位置
源代碼: /hardware/libhardware目錄,該目錄的目錄結(jié)構(gòu)如下:
/hardware/libhardware/hardware.c編譯成libhardware.so,目標(biāo)位置為/system/lib目錄
/hardware/libhardware/include/hardware目錄下包含如下頭文件:
hardware.h 通用硬件模塊頭文件
copybit.h copybit模塊頭文件
gralloc.h gralloc模塊頭文件
lights.h 背光模塊頭文件
overlay.h overlay模塊頭文件
qemud.h qemud模塊頭文件
sensors.h 傳感器模塊頭文件
/hardware/libhardware/modules目錄下定義了很多硬件模塊
這些硬件模塊都編譯成xxx.xxx.so,目標(biāo)位置為/system/lib/hw目錄

2,HAL層的實(shí)現(xiàn)方式
JNI->通用硬件模塊->硬件模塊->內(nèi)核驅(qū)動(dòng)接口
具體一點(diǎn):JNI->libhardware.so->xxx.xxx.so->kernel
具體來(lái)說(shuō):android frameworks中JNI調(diào)用/hardware/libhardware/hardware.c中定義的hw_get_module函數(shù)來(lái)獲取硬件模塊,
然后調(diào)用硬件模塊中的方法,硬件模塊中的方法直接調(diào)用內(nèi)核接口完成相關(guān)功能

3,通用硬件模塊(libhardware.so)
(1)頭文件為:/hardware/libhardware/include/hardware/hardware.h
頭文件中主要定義了通用硬件模塊結(jié)構(gòu)體hw_module_t,聲明了JNI調(diào)用的接口函數(shù)hw_get_module
hw_module_t定義如下:
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[32-7];

} hw_module_t;
硬件模塊方法結(jié)構(gòu)體hw_module_methods_t定義如下:
typedef struct hw_module_methods_t {
/* Open a specific device /
int (open)(const struct hw_module_t module, const char* id,
struct hw_device_t** device);

} hw_module_methods_t;
只定義了一個(gè)open方法,其中調(diào)用的設(shè)備結(jié)構(gòu)體參數(shù)hw_device_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;
hw_get_module函數(shù)聲明如下:
int hw_get_module(const char *id, const struct hw_module_t **module);
參數(shù)id為模塊標(biāo)識(shí),定義在/hardware/libhardware/include/hardware目錄下的硬件模塊頭文件中,
參數(shù)module是硬件模塊地址,定義了/hardware/libhardware/include/hardware/hardware.h中

(2)hardware.c中主要是定義了hw_get_module函數(shù)如下:

#define HAL_LIBRARY_PATH "/system/lib/hw"

static const char *variant_keys[] = {
“ro.hardware”,
“ro.product.board”,
“ro.board.platform”,
“ro.arch”
};
static const int HAL_VARIANT_KEYS_COUNT =
(sizeof(variant_keys)/sizeof(variant_keys[0]));

int hw_get_module(const char *id, const struct hw_module_t **module)
{
int status;
int i;
const struct hw_module_t *hmi = NULL;
char prop[PATH_MAX];
char path[PATH_MAX];
for (i=0 ; i

#define HAL_MODULE_INFO_SYM HMI #define HAL_MODULE_INFO_SYM_AS_STR "HMI"

4,硬件模塊
硬件模塊的開(kāi)發(fā)主要是完成/hardware/libhardware/include/hardware目錄下對(duì)應(yīng)的頭文件中的內(nèi)容,主要是硬件模塊頭文件和hardware.h中
的結(jié)構(gòu)體中定義了一些函數(shù)指針,調(diào)用內(nèi)核提供的接口將具體的函數(shù)實(shí)現(xiàn),然后編譯成指定名稱(chēng)的動(dòng)態(tài)鏈接庫(kù)放到/system/lib/hw目錄下即可。
用一句話(huà)來(lái)概括:硬件模塊的開(kāi)發(fā)就是定義一個(gè)hardware.h中定義的hw_module_t結(jié)構(gòu)體,結(jié)構(gòu)體名稱(chēng)為宏HAL_MODULE_INFO_SYM,然后實(shí)現(xiàn)結(jié)構(gòu)體
的相關(guān)內(nèi)容即可。

5,內(nèi)核驅(qū)動(dòng)
主要是要向用戶(hù)層開(kāi)放接口,讓硬件模塊和內(nèi)核可以交互。

總結(jié)

以上是生活随笔為你收集整理的android系统开发(六)-HAL层开发基础的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。