From 8d29070e3bc6d342c6a97a707a28e0cfcd1aa390 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 8 May 2015 22:19:45 +0200 Subject: [PATCH] Send hci reset after setting bd addr on stlc2500d --- src/hci.c | 35 +++++++++++++++++++++++++++-------- src/hci.h | 8 ++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/hci.c b/src/hci.c index 317588419..6d30bbd1a 100644 --- a/src/hci.c +++ b/src/hci.c @@ -854,7 +854,7 @@ static void hci_initializing_run(){ case HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION: hci_send_cmd(&hci_read_local_version_information); hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION; - break; + break; case HCI_INIT_SEND_RESET_CSR_WARM_BOOT: hci_state_reset(); // prepare reset if command complete not received in 100ms @@ -865,6 +865,18 @@ static void hci_initializing_run(){ hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT; hci_send_cmd(&hci_reset); break; + case HCI_INIT_SEND_RESET_ST_WARM_BOOT: + hci_state_reset(); + hci_stack->substate = HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT; + hci_send_cmd(&hci_reset); + 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->control->set_bd_addr_cmd(hci_stack->config, hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer); + hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0); + 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; case HCI_INIT_SEND_BAUD_CHANGE: hci_stack->control->baudrate_cmd(hci_stack->config, ((hci_uart_config_t *)hci_stack->config)->baudrate_main, hci_stack->hci_packet_buffer); hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0); @@ -877,13 +889,6 @@ static void hci_initializing_run(){ run_loop_add_timer(&hci_stack->timeout); } 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->control->set_bd_addr_cmd(hci_stack->config, hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer); - hci_stack->last_cmd_opcode = READ_BT_16(hci_stack->hci_packet_buffer, 0); - 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; case HCI_INIT_CUSTOM_INIT: log_info("Custom init"); // Custom initialization @@ -1057,6 +1062,20 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ hci_stack->substate = HCI_INIT_CUSTOM_INIT; return; case HCI_INIT_W4_SET_BD_ADDR: + // for STLC2500D, bd addr change only gets active after sending reset command + if (hci_stack->manufacturer == 0x0030){ + hci_stack->substate = HCI_INIT_SEND_RESET_ST_WARM_BOOT; + return; + } + // skipping warm boot on STLC2500D + if (need_baud_change){ + hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE; + return; + } + // skipping baud change + hci_stack->substate = HCI_INIT_CUSTOM_INIT; + return; + case HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT: if (need_baud_change){ hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE; return; diff --git a/src/hci.h b/src/hci.h index 55ac9cffc..0563b3692 100644 --- a/src/hci.h +++ b/src/hci.h @@ -534,10 +534,14 @@ typedef enum hci_init_state{ HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION, HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION, - HCI_INIT_SEND_BAUD_CHANGE, - HCI_INIT_W4_SEND_BAUD_CHANGE, HCI_INIT_SET_BD_ADDR, HCI_INIT_W4_SET_BD_ADDR, + + HCI_INIT_SEND_RESET_ST_WARM_BOOT, + HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT, + + HCI_INIT_SEND_BAUD_CHANGE, + HCI_INIT_W4_SEND_BAUD_CHANGE, HCI_INIT_CUSTOM_INIT, HCI_INIT_W4_CUSTOM_INIT, HCI_INIT_SEND_RESET_CSR_WARM_BOOT,