正文 字体大小:

Android4.2关于bluetooth在HAL层的分析(1)

(2013-09-10 14:58:58)

标签:

hal

bluedroid

android

jni

分类: Bluetooth
1.一些常用的数据结构

hardware/libhardware/include/hardware.h中
定义了三个重要的结构:
struct hw_module_t; //模块类型
struct hw_module_methods_t;   //模块方法
struct hw_device_t;   //设备类型
 
hw_module_t中包含结构hw_module_methods_t
hw_module_methods_t只有一个唯一的Open方法,如下:
 
int (*open)(const struct hw_module_t* module, const char* id,struct hw_device_t** device);
struct hw_device_t中包含hw_module_t结构和一个close方法如下:
 
int (*close)(struct hw_device_t* device);
这几个结构十分关键,是HAL层向上暴露的接口。
 
2.定义蓝牙HAL层结构
在hardware/libhardware/include/bluetooth.h中定义以下关键结构
首先是定义的蓝牙模块ID
#define BT_HARDWARE_MODULE_ID "bluetooth"
#define BT_STACK_MODULE_ID "bluetooth"
#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
 
其次是定义的蓝牙硬件设备接口
//要求自定义xxx_device_t的第一个成员必须是hw_device_t类型,其次才是其它的一些接口信息.   
typedef struct {
    struct hw_device_t common;
    const bt_interface_t* (*get_bluetooth_interface)();
} bluetooth_device_t;
 
除了这个结构,还必须定义关hw_module_t类型的实例HAL_MODULE_INFO_SYM。这个结构在Bluedroid的bluetooth.c中定义。
//变量名必须为HAL_MODULE_INFO_SYM,这是强制要求的,你要写Android的HAL就得遵循这个游戏规则
struct hw_module_t HAL_MODULE_INFO_SYM = {
    .tag = HARDWARE_MODULE_TAG,
    .version_major = 1,
    .version_minor = 0,
    .id = BT_HARDWARE_MODULE_ID,
    .name = "Bluetooth Stack",
    .author = "The Android Open Source Project",
    .methods = &bt_stack_module_methods 
};
定义的bt_stack_module_methods如下:
static int open_bluetooth_stack (const struct hw_module_t* module, char const* name, struct hw_device_t** abstraction)
{
    bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) ); 
    memset(stack, 0, sizeof(bluetooth_device_t) );
    stack->common.tag = HARDWARE_DEVICE_TAG;
    stack->common.version = 0;
    stack->common.module = (struct hw_module_t*)module;
    stack->common.close = close_bluetooth_stack;
    stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface; 
    *abstraction = (struct hw_device_t*)stack;  //GJ:强制转换,bluetooth_device_t的第一个成员为hw_device_t,传到上层
    return 0;
}
static struct hw_module_methods_t bt_stack_module_methods = {
    .open = open_bluetooth_stack,
};
 
在/packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp中实现的是bluetooth的JNI代码,是上层Java与下层Bluedroid的接口。
在static void classInitNative(JNIEnv* env, jclass clazz)函数中有以下部分code:
    char value[PROPERTY_VALUE_MAX];
    property_get("bluetooth.mock_stack", value, ""); //
    const char *id = (strcmp(value, "1")? BT_STACK_MODULE_ID : BT_STACK_TEST_MODULE_ID);
    //JNI获取HAL层模块的通用方式,根据模块ID获得hw_module_t对象
    err = hw_get_module(id, (hw_module_t const**)&module); 
    if (err == 0) 
    {
        hw_device_t* abstraction;
        err = module->methods->open(module, id, &abstraction);
        if (err == 0)
       { 
    //强制转换,bluetooth_module_t的第一个成员为abstraction
            bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction; 
            sBluetoothInterface = btStack->get_bluetooth_interface();  //GJ:JAVA层的sBuletooth获得bluedroid中实现的bluetoothInterface
        } 
 
 
分享:

 

0

喜欢

阅读(363) 评论 (0) 收藏(0) 转载(0) 喜欢 打印举报
已投稿到:

ZT Android4.2关于bluetooth在HAL层的分析(1)的更多相关文章

  1. 51全志R58平台Android4.4下Camera的HAL层修改

    51全志R58平台Android4.4下Camera的HAL层修改 2018/11/7 15:20 版本:V1.0 开发板:SC5806 1.系统编译: (略) 2.全志R58平台Android4.4 ...

  2. Android Hal层简要分析

    Android Hal层简要分析 Android Hal层(即 Hardware Abstraction Layer)是Google开发的Android系统里上层应用对底层硬件操作屏蔽的一个软件层次, ...

  3. 【Android】Sensor框架HAL层解读

    Android sensor构建 Android4.1 系统内置对传感器的支持达13种,他们分别是:加速度传感器(accelerometer).磁力传感器(magnetic field).方向传感器( ...

  4. 如何在 kernel 和 hal 层读取同一个标志

    很多时候我们需要从 HAL 层(Hardware Abstract Layer)传一个标志给 kernel 层.一般这种传递是不能直接通过定义全局变量来实现的. 此时可以通过读写文件来实现该标志. 譬 ...

  5. 高通HAL层之Sensor HAL

    高通的HAL层其实分为两种,一种是直接从kernel这边报数据上来的,由sensor HAL层来监听,另一种是走ADSP的模式,HAL层是通过qmi的形式进行监听的: 走ADSP架构的可以看下面的博客 ...

  6. 〖Android〗OK6410a的Android HAL层代码编写笔记

    一.编写LED灯的Linux驱动程序代码 之所以使用存在HAL层,是为了保护对硬件驱动过程的逻辑与原理: 所以,残留在Linux驱动层的代码,只保留了基本的读写操作,而不含有关键的逻辑思维: 1. l ...

  7. Android HAL层与Linux Kernel层驱动开发简介

    近日稍微对Android中的驱动开发做了一些简要的了解. HAL:Hardware Abstract Layer 硬件抽象层,由于Linux Kernel需要遵循GPL开源协议,硬件厂商为了保护自己硬 ...

  8. Android native进程间通信实例-binder篇之——HAL层访问JAVA层的服务

    有一天在群里聊天的时候,有人提出一个问题,怎样才能做到HAL层访问JAVA层的接口?刚好我不会,所以做了一点研究. 之前的文章末尾部分说过了service call 可以用来调试系统的binder服务 ...

  9. 深入浅出 - Android系统移植与平台开发(八)- HAL Stub框架分析

    作者:唐老师,华清远见嵌入式学院讲师. 1. HAL Stub框架分析 HAL stub的框架比较简单,三个结构体.两个常量.一个函数,简称321架构,它的定义在:@hardware/libhardw ...

随机推荐

  1. UTF-8编码

    UTF-8是UNICODE的一种变长度的编码表达方式<一般UNICODE为双字节(指UCS2)>,它由Ken Thompson于1992年创建,现在已经标准化为RFC 3629.UTF-8 ...

  2. ashx 绝对路径得到物理路径

    //先得到模板页所在的路径 string phyPath = context.Server.MapPath("/p02style.html"); //得到模板的所有内容 strin ...

  3. 第9天:原型、继承、函数使用推荐以及this的指向

    原型 javascript原型指向改变如何添加方法和访问 <!DOCTYPE html> <html lang="en"> <head> < ...

  4. 十三、curator recipes之SharedCounter

    简介 我们可以通过curator实现对一个分布式环境下共享变量的访问,zookeeper将共享变量维护在同一个路径下. 官方文档:http://curator.apache.org/curator-r ...

  5. yum卸载

    完全卸载依赖 -- 正常安装 yum install sl -- 列出操作 yum history list sl -- 根据显示install操作的id进行删除 yum history undo { ...

  6. Spring Boot学习笔记(五)整合mybatis

    pom文件里添加依赖 <!-- 数据库需要的依赖 --> <dependency> <groupId>org.mybatis.spring.boot</gro ...

  7. JAVA jar 和 war 包的区别

    一. jar 包 JAR(Java Archive,Java 归档文件)是与平台无关的文件格式,它允许将许多文件组合成一个压缩文件.JavaSE程序可以打包成Jar包(J其实可以理解为Java了). ...

  8. 设计模式入门,策略模式,c++代码实现

    // test01.cpp : Defines the entry point for the console application.////第一章,设计模式入门,策略模式#include &quo ...

  9. json的省市联动

    1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 < ...

  10. PoPo数据可视化周刊第4期

    PoPo数据可视化 聚焦于Web数据可视化与可视化交互领域,发现可视化领域有意思的内容.不想错过可视化领域的精彩内容, 就快快关注我们吧 :) 微信号:popodv_com   由于国庆节的原因,累计 ...