hci: added local version information callback to allow for runtime driver selection

This commit is contained in:
Matthias Ringwald 2016-01-22 20:55:43 +01:00
parent 19084a7dda
commit c0cdcfe728
9 changed files with 114 additions and 13 deletions

View File

@ -49,6 +49,7 @@
#include "btstack_control.h"
#include "btstack_debug.h"
#include "btstack_chipset_bcm.h"
// actual init script provided by separate bt_firmware_image.c from WICED SDK
extern const uint8_t brcm_patchram_buf[];

View File

@ -43,8 +43,8 @@
* Allows to set public BD ADDR
*/
#ifndef __BTSTACK_CHIPSET_EM9301_H
#define __BTSTACK_CHIPSET_EM9301_H
#ifndef __BTSTACK_CHIPSET_STLC2550D_H
#define __BTSTACK_CHIPSET_STLC2550D_H
#if defined __cplusplus
extern "C" {
@ -58,4 +58,4 @@ const btstack_chipset_t * btstack_chipset_stlc2500d_instance(void);
}
#endif
#endif // __BTSTACK_CHIPSET_EM9301_H
#endif // __BTSTACK_CHIPSET_STLC2550D_H

View File

@ -98,7 +98,7 @@ static void chipset_set_bd_addr_command(bd_addr_t addr, uint8_t *hci_cmd_buffer)
}
static const btstack_chipset_t btstack_chipset_tc3566x = {
"TC3556x",
"tc3566x",
NULL, // chipset_init,
NULL, // chipset_next_command,
chipset_set_baudrate_command,

View File

@ -3,19 +3,46 @@ BTSTACK_ROOT = ../..
CORE += main.c stdin_support.c
COMMON += hci_transport_h4_posix.c btstack_run_loop_posix.c remote_device_db_fs.c
COMMON += \
hci_transport_h4_posix.c \
btstack_run_loop_posix.c \
remote_device_db_fs.c \
CORE += \
bluetooth_init_cc2564B_1.2_BT_Spec_4.1.c \
btstack_chipset_cc256x.c \
btstack_chipset_csr.c \
btstack_chipset_em9301.c \
btstack_chipset_stlc2500d.c \
btstack_chipset_tc3566x.c \
# btstack_chipset_bcm.c \
# examples
include ${BTSTACK_ROOT}/example/embedded/Makefile.inc
CFLAGS += -g -Wall \
-I$(BTSTACK_ROOT)/platform/embedded \
-I$(BTSTACK_ROOT)/platform/posix
# fetch and convert TI init scripts
include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc
# CFLAGS += -Werror
CFLAGS += -g -Wall -Werror \
-I$(BTSTACK_ROOT)/platform/embedded \
-I$(BTSTACK_ROOT)/platform/posix \
-I$(BTSTACK_ROOT)/chipset/bcm \
-I$(BTSTACK_ROOT)/chipset/cc256x \
-I$(BTSTACK_ROOT)/chipset/csr \
-I$(BTSTACK_ROOT)/chipset/em9301 \
-I$(BTSTACK_ROOT)/chipset/stlc2500d \
-I$(BTSTACK_ROOT)/chipset/tc3566x \
VPATH += ${BTSTACK_ROOT}/platform/posix
VPATH += ${BTSTACK_ROOT}/platform/embedded
VPATH += ${BTSTACK_ROOT}/chipset/bcm
VPATH += ${BTSTACK_ROOT}/chipset/cc256x
VPATH += ${BTSTACK_ROOT}/chipset/csr
VPATH += ${BTSTACK_ROOT}/chipset/em9301
VPATH += ${BTSTACK_ROOT}/chipset/stlc2500d
VPATH += ${BTSTACK_ROOT}/chipset/tc3566x
ifeq ($(OS),Windows_NT)
LDFLAGS += -lws2_32
endif

View File

@ -57,6 +57,13 @@
#include "btstack_run_loop_posix.h"
#include "stdin_support.h"
#include "btstack_chipset_bcm.h"
#include "btstack_chipset_csr.h"
#include "btstack_chipset_cc256x.h"
#include "btstack_chipset_em9301.h"
#include "btstack_chipset_stlc2500d.h"
#include "btstack_chipset_tc3566x.h"
int btstack_main(int argc, const char * argv[]);
static hci_transport_config_uart_t config = {
@ -87,6 +94,47 @@ void hal_led_toggle(void){
printf("LED State %u\n", led_state);
}
static void local_version_information_callback(uint8_t * packet){
printf("Local version information:\n");
uint16_t hci_version = READ_BT_16(packet, 4);
uint16_t hci_revision = READ_BT_16(packet, 6);
uint16_t lmp_version = READ_BT_16(packet, 8);
uint16_t manufacturer = READ_BT_16(packet, 10);
uint16_t lmp_subversion = READ_BT_16(packet, 12);
printf("- HCI Version 0x%04x\n", hci_version);
printf("- HCI Revision 0x%04x\n", hci_revision);
printf("- LMP Version 0x%04x\n", lmp_version);
printf("- LMP Revision 0x%04x\n", lmp_subversion);
printf("- Manufacturer 0x%04x\n", manufacturer);
switch (manufacturer){
case COMPANY_ID_CAMBRIDGE_SILICON_RADIO:
printf("Cambridge Silicon Radio CSR chipset.\n");
hci_set_chipset(btstack_chipset_csr_instance());
break;
case COMPANY_ID_TEXAS_INSTRUMENTS_INC:
printf("Texas Instruments - CC256x compatible chipset.\n");
printf("Using 921600 baud.\n");
config.baudrate_main = 921600;
hci_set_chipset(btstack_chipset_cc256x_instance());
break;
case COMPANY_ID_BROADCOM_CORPORATION:
printf("Broadcom chipset. Not supported yet\n");
// hci_set_chipset(btstack_chipset_bcm_instance());
break;
case COMPANY_ID_ST_MICROELECTRONICS:
printf("ST Microelectronics - using STLC2500d driver.\n");
hci_set_chipset(btstack_chipset_stlc2500d_instance());
break;
case COMPANY_ID_EM_MICROELECTRONICS_MARIN:
printf("EM Microelectronics - using EM9301 driver.\n");
hci_set_chipset(btstack_chipset_em9301_instance());
break;
default:
printf("Unknown manufacturer / manufacturer not supported yet.\n");
break;
}
}
int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
@ -97,13 +145,16 @@ int main(int argc, const char * argv[]){
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
// pick serial port
config.device_name = "/dev/tty.usbmodem1413";
config.device_name = "/dev/tty.usbserial-A900K0VK";
// init HCI
hci_transport_t * transport = hci_transport_h4_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs;
hci_init(transport, (void*) &config, remote_db);
// setup dynamic chipset driver setup
hci_set_local_version_information_callback(&local_version_information_callback);
// handle CTRL-c
signal(SIGINT, sigint_handler);

View File

@ -8,11 +8,11 @@ COMMON += hci_transport_h4_posix.c btstack_run_loop_posix.c remote_device_db_fs.
include ${BTSTACK_ROOT}/example/embedded/Makefile.inc
CFLAGS += -g -Wall \
-I$(BTSTACK_ROOT)/chipset/tc3556x \
-I$(BTSTACK_ROOT)/chipset/tc3566x \
-I$(BTSTACK_ROOT)/platform/embedded \
-I$(BTSTACK_ROOT)/platform/posix
VPATH += ${BTSTACK_ROOT}/chipset/tc3556x
VPATH += ${BTSTACK_ROOT}/chipset/tc3566x
VPATH += ${BTSTACK_ROOT}/platform/embedded
VPATH += ${BTSTACK_ROOT}/platform/posix

View File

@ -1374,6 +1374,11 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->manufacturer = READ_BT_16(packet, 10);
// hci_stack->lmp_subversion = READ_BT_16(packet, 12);
log_info("Manufacturer: 0x%04x", hci_stack->manufacturer);
// notify app
if (hci_stack->local_version_information_callback){
hci_stack->local_version_information_callback(packet);
}
}
if (COMMAND_COMPLETE_EVENT(packet, hci_read_local_supported_commands)){
hci_stack->local_supported_commands[0] =
@ -3549,6 +3554,14 @@ void hci_set_hardware_error_callback(void (*fn)(void)){
hci_stack->hardware_error_callback = fn;
}
/**
* @brief Set callback for local information from Bluetooth controller right after HCI Reset
* @note Can be used to select chipset driver dynamically during startup
*/
void hci_set_local_version_information_callback(void (*fn)(uint8_t * local_version_information)){
hci_stack->local_version_information_callback = fn;
}
void hci_disconnect_all(void){
btstack_linked_list_iterator_t it;

View File

@ -640,9 +640,12 @@ typedef struct {
bd_addr_t custom_bd_addr;
uint8_t custom_bd_addr_set;
// hardware error handler
// hardware error callback
void (*hardware_error_callback)(void);
// local version information callback
void (*local_version_information_callback)(uint8_t * local_version_information);
} hci_stack_t;
/**
@ -840,6 +843,12 @@ void hci_le_advertisement_address(uint8_t * addr_type, bd_addr_t addr);
*/
void hci_set_hardware_error_callback(void (*fn)(void));
/**
* @brief Set callback for local information from Bluetooth controller right after HCI Reset
* @note Can be used to select chipset driver dynamically during startup
*/
void hci_set_local_version_information_callback(void (*fn)(uint8_t * local_version_information));
/**
* @brief Configure Voice Setting for use with SCO data in HSP/HFP
*/