Merge branch 'develop' of https://github.com/bluekitchen/btstack into develop

This commit is contained in:
Matthias Ringwald 2017-02-02 12:03:57 +01:00
commit 1b637061a3
10 changed files with 67 additions and 20 deletions

View File

@ -73,8 +73,8 @@ port-daemon-develop) | daemon: TCP and Unix domain named socket client-serve
Chipset | Type | HCI Transport | SCO over HCI (2) | BTstack folder | Comment
-------------------- |-----------| ----------------|------------------|----------------|---------
Broadcom UART | Dual mode | H4, H5 | No (didn't work) | bcm | Max UART baudrate 3 mbps
Broadcom USB Dongles | Dual mode | USB | No (didn't work) | bcm |
Broadcom UART | Dual mode | H4, H5 | Probably | bcm | Max UART baudrate 2 mbps
Broadcom USB Dongles | Dual mode | USB | Yes | bcm |
CSR UART | Dual mode | H4, H5 | No (didn't work) | csr |
CSR USB Dongles | Dual mode | USB | Yes | csr |
EM 9301 | LE | SPI | n.a. | em9301 | Custom HCI SPI implementation

View File

@ -33,7 +33,7 @@ CSR, which has been acquired by Qualcomm, provides all relevant information on t
Chipset | Type | HCI Transport | BD_ADDR (1) | SCO over HCI (2) | LE DLE | Multiple LE Roles | BTstack folder | Comment
-------------------- |-----------| ---------------|--------------|------------------|--------|----------------------|----------------|---------
Broadcom UART | Dual mode | H4, H5 | rarely | Maybe | No | Maybe (3) | bcm | Max UART baudrate 3 mbps
Broadcom UART | Dual mode | H4, H5 | rarely | Probably (2) | No | Maybe (3) | bcm | Max UART baudrate 2 mbps
Broadcom USB Dongles | Dual mode | USB | Yes | Yes | No | No | bcm |
CSR UART | Dual mode | H4, H5 | rarely | No (didn't work) | No | No | csr |
CSR USB Dongles | Dual mode | USB | Mostly | Yes | No | No | csr |
@ -65,17 +65,17 @@ Broadcom USB dongles do not require special configuration, however SCO data is n
To find the correct file, Broadcom chipsets return their model number when asked for their local name.
BTstack supports uploading of the init script in two variants: using .hcd files looked up by name in the posix-h4 port and by linking against the init script in the WICED port.
BTstack supports uploading of the init script in two variants: using .hcd files looked up by name in the posix-h4 port and by linking against the init script in the WICED port. While the init script is processed, the chipsets RTS line goes high, but only 2 ms after the command complete event for the last command from the init script was sent. BTstack waits for 10 ms after receiving the command complete event for the last command to avoid sending before RTS goes high and the command fails.
**BD Addr** can be set with a custom command. A fixed addres is provided on some modules, e.g. the AP6212A, but not on others.
**SCO data** can be configured with a custom command found in the bluez sources. We haven't been able to route SCO data over HCI yet.
**SCO data** can be configured with a custom command found in the bluez sources. It works with USB chipsets. The chipsets don't implement the SCO Flow Control that is used by BTstack for UART connected devices. A forum suggests to send SCO packets as fast as they are received since both directions have the same constant speed.
**Baud rate** can be set with custom command. The baud rate resets during the warm start after uploading the init script. So, the overall scheme is this: start at default baud rate, get local version info, send custom Broadcom baud rate change command, wait for response, set local UART to high baud rate, and then send init script. After sending the last command from the init script, reset the local UART. Finally, send custom baud rate change command, wait for response, and set local UART to high baud rate.
**BTstack integration**: The common code for all Broadcom chipsets is provided by *btstack_chipset_bcm.c*. During the setup, *btstack_chipset_bcm_instance* function is used to get a *btstack_chipset_t* instance and passed to *hci_init* function.
SCO Data can not be routed over HCI via USB or UART, so HFP Wide-Band Speech is not supported currently. HSP and HFP Narrow Band Speech is supported via I2C/PCM pins.
SCO Data can be routed over HCI for both USB dongles and UART connections, however BTstack does not provide any form of flow control for UART connections. HSP and HFP Narrow Band Speech is supported via I2C/PCM pins.
## CSR

View File

@ -137,6 +137,8 @@ static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
log_info("chipset-bcm: end of file, size %u", init_script_offset);
close(hcd_fd);
// TODO: should not be needed anymore - fixed for embedded below and tested on RedBear Duo
// wait for firmware patch to be applied - shorter delay possible
#ifdef _WIN32
Sleep(1000);
@ -269,6 +271,13 @@ static btstack_chipset_result_t chipset_next_command(uint8_t * hci_cmd_buffer){
}
if (init_script_offset >= brcm_patch_ram_length) {
// It takes up to 2 ms for the BCM to raise its RTS line
// If we send the next command right away, the raise of the RTS will fall happen during
// it and causing the next command to fail (at least on RedBear Duo with manual CTS/RTS)
//
// -> Work around implemented in hci.c
return BTSTACK_CHIPSET_DONE;
}

View File

@ -72,9 +72,11 @@
// number of sco packets until 'report' on console
#define SCO_REPORT_PERIOD 100
#ifdef HAVE_POSIX_FILE_IO
// length and name of wav file on disk
#define SCO_WAV_DURATION_IN_SECONDS 15
#define SCO_WAV_FILENAME "sco_input.wav"
#endif
// name of sbc test files
#define SCO_MSBC_OUT_FILENAME "sco_output.msbc"
@ -420,7 +422,9 @@ static void sco_demo_receive_mSBC(uint8_t * packet, uint16_t size){
static void sco_demo_init_CVSD(void){
printf("SCO Demo: Init CVSD\n");
#if defined(SCO_WAV_FILENAME) || defined(USE_PORTAUDIO)
btstack_cvsd_plc_init(&cvsd_plc_state);
#endif
#ifdef SCO_WAV_FILENAME
num_samples_to_write = CVSD_SAMPLE_RATE * SCO_WAV_DURATION_IN_SECONDS;
@ -452,7 +456,9 @@ static void sco_demo_receive_CVSD(uint8_t * packet, uint16_t size){
audio_frame_in[i] = little_endian_read_16(packet, 3 + i * 2);
}
#if defined(SCO_WAV_FILENAME) || defined(USE_PORTAUDIO)
btstack_cvsd_plc_process_data(&cvsd_plc_state, audio_frame_in, num_samples, audio_frame_out);
#endif
#ifdef SCO_WAV_FILENAME
// Samples in CVSD SCO packet are in little endian, ready for wav files (take shortcut)
@ -735,7 +741,7 @@ void sco_demo_receive(uint8_t * packet, uint16_t size){
data_received += size - 3;
packets++;
if (data_received > 100000){
printf("Summary: data %07u, packets %04u, packet with crc errors %0u, byte errors %04u\n", data_received, packets, crc_errors, byte_errors);
printf("Summary: data %07u, packets %04u, packet with crc errors %0u, byte errors %04u\n", (unsigned int) data_received, (unsigned int) packets, (unsigned int) crc_errors, (unsigned int) byte_errors);
crc_errors = 0;
byte_errors = 0;
data_received = 0;

View File

@ -178,14 +178,8 @@ static wiced_result_t h4_rx_worker_receive_packet(void * arg){
// executed on tx worker thread
static wiced_result_t h4_tx_worker_send_packet(void * arg){
#ifdef WICED_BT_UART_MANUAL_CTS_RTS
int cts_was_raised = 0;
while (platform_gpio_input_get(wiced_bt_uart_pins[WICED_BT_PIN_UART_CTS]) == WICED_TRUE){
printf(".");
wiced_rtos_delay_milliseconds(100);
cts_was_raised = 1;
}
if (cts_was_raised){
printf("\n");
}
#endif
// blocking send

View File

@ -54,7 +54,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
static const hci_transport_config_uart_t hci_transport_config_uart = {
HCI_TRANSPORT_CONFIG_UART,
115200,
0,
2000000, // 300000+ didn't work reliably, the 48 MHz UART config might be needed for this
1,
NULL,
};
@ -78,6 +78,23 @@ void application_start(void){
printf("BTstack on WICED\n");
#if 0
// init GPIOs D0-D5 for debugging - not used
wiced_gpio_init(D0, OUTPUT_PUSH_PULL);
wiced_gpio_init(D1, OUTPUT_PUSH_PULL);
wiced_gpio_init(D2, OUTPUT_PUSH_PULL);
wiced_gpio_init(D3, OUTPUT_PUSH_PULL);
wiced_gpio_init(D4, OUTPUT_PUSH_PULL);
wiced_gpio_init(D5, OUTPUT_PUSH_PULL);
wiced_gpio_output_low(D0);
wiced_gpio_output_low(D1);
wiced_gpio_output_low(D2);
wiced_gpio_output_low(D3);
wiced_gpio_output_low(D4);
wiced_gpio_output_low(D5);
#endif
// start with BTstack init - especially configure HCI Transport
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_wiced_get_instance());

View File

@ -17,9 +17,13 @@ $(NAME)_SOURCES += \
../../src/ble/att_dispatch.c \
../../src/ble/att_server.c \
../../src/ble/le_device_db_memory.c \
../../src/ble/gatt-service/battery_service_server.c \
../../src/ble/sm.c \
../../src/classic/hfp.c \
../../src/classic/hfp_ag.c \
../../src/classic/hfp_hf.c \
../../src/classic/hsp_hs.c \
../../src/classic/hsp_hs.c \
../../src/classic/btstack_link_key_db_memory.c \
../../src/classic/rfcomm.c \
../../src/classic/sdp_server.c \
../../src/classic/sdp_client.c \
@ -36,6 +40,7 @@ $(NAME)_SOURCES += \
../../src/hci_dump.c \
../../src/l2cap.c \
../../src/l2cap_signaling.c \
../../example/sco_demo_util.c \
# WICED port incl. support for Broadcom chipset
$(NAME)_SOURCES += \

View File

@ -833,7 +833,7 @@ static void hfp_run_for_context(hfp_connection_t * hfp_connection){
hfp_connection->ok_pending = 1;
hfp_connection->generic_status_update_bitmap = store_bit(hfp_connection->generic_status_update_bitmap, i, 0);
char buffer[30];
sprintf(buffer, "AT%s=%u,%u\r\n", HFP_TRANSFER_HF_INDICATOR_STATUS, hfp_indicators[i], hfp_indicators_value[i]);
sprintf(buffer, "AT%s=%u,%u\r\n", HFP_TRANSFER_HF_INDICATOR_STATUS, hfp_indicators[i], (unsigned int) hfp_indicators_value[i]);
send_str_over_rfcomm(hfp_connection->rfcomm_cid, buffer);
} else {
log_info("Not sending HF indicator %u as it is disabled", hfp_indicators[i]);

View File

@ -972,6 +972,11 @@ static void hci_initialization_timeout_handler(btstack_timer_source_t * ds){
hci_run();
}
break;
case HCI_INIT_W4_CUSTOM_INIT_BCM_DELAY:
// otherwise continue
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
hci_send_cmd(&hci_read_local_supported_commands);
break;
default:
break;
}
@ -1080,9 +1085,10 @@ static void hci_initializing_run(void){
break;
}
log_info("Init script done");
// Init script download causes baud rate to reset on Broadcom chipsets, restore UART baud rate if needed
// Init script download on Broadcom chipsets causes:
if (hci_stack->manufacturer == COMPANY_ID_BROADCOM_CORPORATION){
// - baud rate to reset, restore UART baud rate if needed
int need_baud_change = hci_stack->config
&& hci_stack->chipset
&& hci_stack->chipset->set_baudrate_command
@ -1093,8 +1099,17 @@ static void hci_initializing_run(void){
log_info("Local baud rate change to %"PRIu32" after init script (bcm)", baud_rate);
hci_stack->hci_transport->set_baudrate(baud_rate);
}
}
}
// - RTS will raise during update, but manual RTS/CTS in WICED port on RedBear Duo cannot handle this
// -> Work around: wait a few milliseconds here.
log_info("BCM delay after init script");
hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_BCM_DELAY;
btstack_run_loop_set_timer(&hci_stack->timeout, 10);
btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler);
btstack_run_loop_add_timer(&hci_stack->timeout);
break;
}
}
// otherwise continue
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
hci_send_cmd(&hci_read_local_supported_commands);

View File

@ -507,6 +507,7 @@ typedef enum hci_init_state{
HCI_INIT_SEND_RESET_CSR_WARM_BOOT,
HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT,
HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT_LINK_RESET,
HCI_INIT_W4_CUSTOM_INIT_BCM_DELAY,
HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS,
HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS,