hci: reduce init code (skip baud rate and bd addr changes) for SoC ports

This commit is contained in:
Matthias Ringwald 2017-01-10 11:39:50 +01:00
parent c83b02157f
commit 06b9e82047

View File

@ -45,9 +45,11 @@
#include "btstack_config.h"
#ifdef ENABLE_CLASSIC
#ifdef HAVE_EMBEDDED_TICK
#include "btstack_run_loop_embedded.h"
#endif
#endif
#ifdef HAVE_PLATFORM_IPHONE_OS
#include "../port/ios/src/btstack_control_iphone.h"
@ -814,10 +816,12 @@ uint16_t hci_max_acl_data_packet_length(void){
return hci_stack->acl_data_packet_length;
}
#ifdef ENABLE_CLASSIC
int hci_extended_sco_link_supported(void){
// No. 31, byte 3, bit 7
return (hci_stack->local_supported_features[3] & (1 << 7)) != 0;
}
#endif
int hci_non_flushable_packet_boundary_flag_supported(void){
// No. 54, byte 6, bit 6
@ -888,6 +892,8 @@ void le_handle_advertisement_report(uint8_t *packet, int size){
}
#endif
#ifndef HAVE_HOST_CONTROLLER_API
static uint32_t hci_transport_uart_get_main_baud_rate(void){
if (!hci_stack->config) return 0;
uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main;
@ -936,6 +942,7 @@ static void hci_initialization_timeout_handler(btstack_timer_source_t * ds){
break;
}
}
#endif
static void hci_initializing_next_state(void){
hci_stack->substate = (hci_substate_t )( ((int) hci_stack->substate) + 1);
@ -948,7 +955,7 @@ static void hci_initializing_run(void){
case HCI_INIT_SEND_RESET:
hci_state_reset();
#ifndef HAVE_PLATFORM_IPHONE_OS
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
// prepare reset if command complete not received in 100ms
btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS);
btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler);
@ -966,6 +973,8 @@ static void hci_initializing_run(void){
hci_send_cmd(&hci_read_local_name);
hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_NAME;
break;
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
case HCI_INIT_SEND_RESET_CSR_WARM_BOOT:
hci_state_reset();
// prepare reset if command complete not received in 100ms
@ -1056,11 +1065,6 @@ static void hci_initializing_run(void){
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
hci_send_cmd(&hci_read_local_supported_commands);
break;
case HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS:
log_info("Resend hci_read_local_supported_commands after CSR Warm Boot double reset");
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
hci_send_cmd(&hci_read_local_supported_commands);
break;
case HCI_INIT_SET_BD_ADDR:
log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr));
hci_stack->chipset->set_bd_addr_command(hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer);
@ -1068,6 +1072,13 @@ static void hci_initializing_run(void){
hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR;
hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]);
break;
#endif
case HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS:
log_info("Resend hci_read_local_supported_commands after CSR Warm Boot double reset");
hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS;
hci_send_cmd(&hci_read_local_supported_commands);
break;
case HCI_INIT_READ_BD_ADDR:
hci_stack->substate = HCI_INIT_W4_READ_BD_ADDR;
hci_send_cmd(&hci_read_bd_addr);
@ -1202,6 +1213,8 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
}
}
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
// Vendor == CSR
if (hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT && hci_event_packet_get_type(packet) == HCI_EVENT_VENDOR_SPECIFIC){
// TODO: track actual command
@ -1265,20 +1278,28 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
}
}
#endif
if (!command_completed) return;
int need_baud_change = hci_stack->config
int need_baud_change = 0;
int need_addr_change = 0;
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
need_baud_change = hci_stack->config
&& hci_stack->chipset
&& hci_stack->chipset->set_baudrate_command
&& hci_stack->hci_transport->set_baudrate
&& ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main;
int need_addr_change = hci_stack->custom_bd_addr_set
need_addr_change = hci_stack->custom_bd_addr_set
&& hci_stack->chipset
&& hci_stack->chipset->set_bd_addr_command;
#endif
switch(hci_stack->substate){
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
case HCI_INIT_SEND_RESET:
// on CSR with BCSP/H5, resend triggers resend of HCI Reset and leads to substate == HCI_INIT_SEND_RESET
// fix: just correct substate and behave as command below
@ -1315,6 +1336,12 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
// repeat custom init
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
return;
#else
case HCI_INIT_W4_SEND_RESET:
hci_stack->substate = HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS;
return ;
#endif
case HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS:
if (need_baud_change && hci_stack->manufacturer == COMPANY_ID_BROADCOM_CORPORATION){
hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE_BCM;
@ -1326,6 +1353,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
}
hci_stack->substate = HCI_INIT_READ_BD_ADDR;
return;
#if !defined(HAVE_PLATFORM_IPHONE_OS) && !defined (HAVE_HOST_CONTROLLER_API)
case HCI_INIT_W4_SEND_BAUD_CHANGE_BCM:
if (need_baud_change){
uint32_t baud_rate = hci_transport_uart_get_main_baud_rate();
@ -1350,6 +1378,7 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
case HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT:
hci_stack->substate = HCI_INIT_READ_BD_ADDR;
return;
#endif
case HCI_INIT_W4_READ_BD_ADDR:
// only read buffer size if supported
if (hci_stack->local_supported_commands[0] & 0x01) {
@ -1456,6 +1485,7 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->num_cmd_packets = packet[2] ? 1 : 0;
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_name)){
if (packet[5]) break;
// terminate, name 248 chars
packet[6+248] = 0;
log_info("local name: %s", &packet[6]);
@ -3253,6 +3283,7 @@ static void hci_emit_discoverable_enabled(uint8_t enabled){
hci_emit_event(event, sizeof(event), 1);
}
#ifdef ENABLE_CLASSIC
// query if remote side supports eSCO
int hci_remote_esco_supported(hci_con_handle_t con_handle){
hci_connection_t * connection = hci_connection_for_handle(con_handle);
@ -3270,6 +3301,7 @@ int hci_remote_ssp_supported(hci_con_handle_t con_handle){
int gap_ssp_supported_on_both_sides(hci_con_handle_t handle){
return hci_local_ssp_activated() && hci_remote_ssp_supported(handle);
}
#endif
// GAP API
/**