蓝牙系列五:开源蓝牙协议BTStack框架代码阅读(1)
蓝牙学习系列,借鉴卫东上老师的蓝牙视频教程。
(图片来源网络,侵删)
BTStack协议栈学习。首先来看一下,对于硬件操作,它是如何来进行处理的。在上篇文章中曾说过,在main函数里面它会调用硬件相关的代码,调用操作系统相关的代码。在BTStack中,可以搜索一下main.c,将会发现有很多main.c,都是为于port目录下面。
Main.c (port\esp32\components\btstack) Main.c (port\ez430-rf2560\src) Main.c (port\libusb) Main.c (port\libusb-intel) Main.c (port\max32630-fthr\src) Main.c (port\msp-exp430f5438-cc2564b\src) Main.c (port\msp430f5229lp-cc2564b\src) Main.c (port\nrf5-zephyr) Main.c (port\nrf5x) Main.c (port\pic32-harmony\src) Main.c (port\posix-h4) Main.c (port\posix-h4-atwilc3000) Main.c (port\posix-h4-da14581) Main.c (port\posix-h4-da14585) Main.c (port\posix-h4-zephyr) Main.c (port\posix-h5) Main.c (port\posix-h5-bcm) Main.c (port\raspi) Main.c (port\samv71-xplained-atwilc3000) Main.c (port\stm32-f103rb-nucleo) Main.c (port\stm32-f4discovery-cc256x\eclipse-template\src) Main.c (port\stm32-l053r8-em9304\cubemx-l053r8-em9304\src) Main.c (port\wiced-h4) Main.c (port\wiced-h5) Main.c (port\windows-h4) Main.c (port\windows-h4-zephyr) Main.c (port\windows-winusb) Main.c (port\windows-winusb-intel)
看一下windows,有Main.c (port\windows-h4)、Main.c (port\windows-winusb),使用的是usb口的蓝牙模块。注意后h4表示5线串口的蓝牙模块。
分析Main.c 中的main函数,按照上一篇文章中总结出来的框架,首先找到硬件操作的相关代码,然后再看操作系统先关的代码
1. 硬件相关的代码:
a.使用usb口
分析Main.c (port\windows-winusb)
// setup USB Transport
transport = hci_transport_usb_instance();
const hci_transport_t * hci_transport_usb_instance(void) {
return &hci_transport_usb; //返回hci_transport_usb的结构体
}
hci_transport_usb的结构体定义如下:
// get usb singleton static const hci_transport_t hci_transport_usb = { /* const char * name; */ "H2_WINUSB", /* void (*init) (const void *transport_config); */ &usb_init, /* int (*open)(void); */ &usb_open, /* int (*close)(void); */ &usb_close, /* void (*register_packet_handler)(void (*handler)(...); */ &usb_register_packet_handler, /* int (*can_send_packet_now)(uint8_t packet_type); */ &usb_can_send_packet_now, /* int (*send_packet)(...); */ &usb_send_packet, /* int (*set_baudrate)(uint32_t baudrate); */ NULL, /* void (*reset_link)(void); */ NULL, #ifdef ENABLE_SCO_OVER_HCI /* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ usb_set_sco_config, #else /* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL, #endif };
在hci_transport
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。