東川印記

一本東川,笑看爭龍斗虎;寰茫兦者,度橫佰昧人生。

android源码编译之06XXXServicesFramework编写之可行性试验03硬件抽象层(HAL)及硬件服务接口

2015年4月10日星期五



1,增加硬件抽象层(HAL)模块访问linux内核驱动程序
①创建相关文件
  1. senrsl@senrsl-ubuntu:~$ cd android/source/WORKING_DIRECTORY/
  2. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY$ cd hardware/libhardware/include/hardware/
  3. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/include/hardware$ vi senrsl.h
  4. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/include/hardware$ cd ..
  5. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/include$ cd ..
  6. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware$ cd modules/
  7. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules$ mkdir senrsl
  8. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules$ cd senrsl/
  9. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules/senrsl$ touch senrsl.c
  10. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules/senrsl$ gedit senrsl.c
  11. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules/senrsl$ touch Android.mk
  12. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/hardware/libhardware/modules/senrsl$
1)/home/senrsl/android/source/WORKING_DIRECTORY/hardware/libhardware/include/hardware/senrsl.h
  1. /**
  2. * 这里按照Android硬件抽象层规范的要求,分别定义模块ID、模块结构体以及硬件接口结构体。在硬件接口结构体中,fd表示设备文件描述符,对应我们 将要处理的设备文件"/dev/senrsl",set_val和get_val为该HAL对上提供的函数接口。
  3. */
  4. #ifndef ANDROID_SENRSL_INTERFACE_H
  5. #define ANDROID_SENRSL_INTERFACE_H
  6. #include <hardware/hardware.h>
  7. __BEGIN_DECLS
  8. /*定义模块ID*/
  9. #define SENRSL_HARDWARE_MODULE_ID "senrsl"
  10. /*硬件模块结构体*/
  11. struct senrsl_module_t {
  12.     struct hw_module_t common;
  13. };
  14. /*硬件接口结构体*/
  15. struct senrsl_device_t {
  16.     struct hw_device_t common;
  17.     int fd;
  18.     int (*set_val)(struct senrsl_device_t* dev, int val);
  19.     int (*get_val)(struct senrsl_device_t* dev, int* val);
  20. };
  21. __END_DECLS

没有评论 :

发表评论