在前面几篇文章中,我们把kernel中bluetooth stack相关的初始化分析完成,今天晓东带大家来一起分析uart接口的bluetooth
driver的初始化。首先,我们来到kernel/drivers/bluetooth目录,看hci_ldisc.c文件。又见到我们熟悉的module_init:
module_init(hci_uart_init);好吧,动手来看吧:
static int __init hci_uart_init(void)
{
static struct tty_ldisc_ops hci_uart_ldisc;
int err;
BT_INFO("HCI UART driver ver %s", VERSION);
/* Register the tty discipline */
memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
hci_uart_ldisc.name = "n_hci";
hci_uart_ldisc.open = hci_uart_tty_open;
hci_uart_ldisc.close = hci_uart_tty_close;
hci_uart_ldisc.read = hci_uart_tty_read;
hci_uart_ldisc.write = hci_uart_tty_write;
hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
hci_uart_ldisc.poll = hci_uart_tty_poll;
hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
hci_uart_ldisc.owner = THIS_MODULE;
//注册了一个tty的新的线路规程,为N_HCI,并定义了他的一系列的操作
/*线路规程有什么作用呢,我们可以这样理解,tty向应用层注册了一系列的通用接口,这些接口(比如写数据)被调用后会根据对应的线路规程去找对应的driver,然后driver会对数据做一些处理发送到硬件中去。
这个通路反过来也是成立。
大概的模型如下:
-----tty层----------
-----线路规程-----
-----driver层-------
-----硬件层---------
*/
if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
BT_ERR("HCI line discipline registration failed. (%d)", err);
return err;
}
//以h4为例来进行讲解
h4_init();
…… return 0;
}
int __init h4_init(void)
{
//就是向uart protol中注册对应的driver,详细分析见下面。
int err = hci_uart_register_proto(&h4p);
if (!err)
BT_INFO("HCI H4 protocol initialized");
else
BT_ERR("HCI H4 protocol registration failed");
return err;
}
static struct hci_uart_proto h4p = {
.id = HCI_UART_H4,
.open = h4_open,
.close = h4_close,
.recv = h4_recv,
.enqueue = h4_enqueue,
.dequeue = h4_dequeue,
.flush = h4_flush,
};
int hci_uart_register_proto(struct hci_uart_proto *p)
{
if (p->id >= HCI_UART_MAX_PROTO)
return -EINVAL;
if (hup[p->id])
return -EEXIST;
//其实说白了就是初始化hup数组(hci uart proto)
//在这之后的open,write,read什么的就可以通过这个数组找到对应proto的相应的调用接口中去
hup[p->id] = p;
return 0;
}
所以,总的来说,uart这边的脉络还是很清楚的,就是首先注册线路规程,所有和蓝牙相关的数据将会选择HCI这个线路规程,然后根据各家的方案设计不同,注册对应的proto,数据最终会根据proto选择对应的driver去做处理后发送到对应的硬件(蓝牙controller中)。
分享到:
相关推荐
C8051fXXX中UART0,UART1详细初始化(已经调试了).txt
3、初始化程序(以后使用可直接调用此初始化函数)。SYSCLK与BAUDRATE参数修改即可 void UART0_Init (void) { SCON0 = 0x10; // SCON0: 8-bit variable bit rate // level of STOP bit is // 使能RX接收 //...
RN8209初始化UART通讯参考程序,包含SPI示例程序和UART程序
STM32中UART初始化函数,发送字符串函数以及重定向printf
LINUX KERNEL4.x spi和uart测试
基于xilinx公司的KC705开发板,设计了一套基于FPGA的UART接口,亲测收发无误
主要介绍接口知识当然包括UART,注意版权归原作者所有,请遵守相关法律!
RN8209C及D初始化及UART通讯参考程序
Uart driver for PowerQUICC MPC 860
uart初始化ARM7 使用LCP2131 UARTO 初始化操作
lm3s1968uart初始化
USB to UART Driver CH340_CH341 的目录 2019/01/15 08:57 <DIR> . 2019/01/15 08:57 <DIR> .. 2014/10/09 11:54 233,018 ch341ser.exe 1 个文件 233,018 字节 PL2303 的目录 2019/01/15 08:57 <DIR> . 2019/01/...
基于Arm S3c2410的uart接口开发和LED显示测试示例
win2000下的与下位机UART的串口通信程序
介绍UART接口的ppt资料,很详细,具有一定的参考价值。
FT230XS UART to USB Driver,FT230XS芯片 串口转usb驱动程序。
USB转UART接口模块采用专用的USB转UART接口芯片,输出为TTL电平,可以和单片机的内置串口(UART)直接连接,使单片机通过USB口和计算机通讯,方便、快捷。 UART,是一种异步收发传输器,是电脑硬件的一部分。将资料由...
USB to UART Driver驱动软件程序
ft230x basic uart 驱动 FT230XS UART to USB Driver
uart接口,使用Verilog编写,适用于各类FPGA