From 1fc2c15a29c78fdbd0da5f4b0f096ed4a85c362e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 13 Jan 2016 15:06:28 +0100 Subject: [PATCH 1/3] posix-cc2564b: fix compile, use high uart speed --- platforms/posix-cc2564b/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platforms/posix-cc2564b/main.c b/platforms/posix-cc2564b/main.c index e757c1559..b37a630d1 100644 --- a/platforms/posix-cc2564b/main.c +++ b/platforms/posix-cc2564b/main.c @@ -56,7 +56,7 @@ #include "hci.h" #include "hci_dump.h" #include "stdin_support.h" -#include "hal_led.h" +#include #include "bt_control_cc256x.h" int btstack_main(int argc, const char * argv[]); @@ -64,6 +64,7 @@ int btstack_main(int argc, const char * argv[]); static hci_uart_config_t hci_uart_config_cc256x = { NULL, 115200, + 921600 }; static void sigint_handler(int param){ @@ -96,7 +97,7 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port - hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; + hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-A900K0VK"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); From 5472ae221e75e236c32d832e45c85f87cc1be836 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 13 Jan 2016 15:13:52 +0100 Subject: [PATCH 2/3] add chipset-bcm from ble-api-cleanup branch --- chipset-bcm/bt_control_bcm.c | 131 +++++++++++++++++++++++++++++++++++ chipset-bcm/bt_control_bcm.h | 59 ++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 chipset-bcm/bt_control_bcm.c create mode 100644 chipset-bcm/bt_control_bcm.h diff --git a/chipset-bcm/bt_control_bcm.c b/chipset-bcm/bt_control_bcm.c new file mode 100644 index 000000000..e850e6aa8 --- /dev/null +++ b/chipset-bcm/bt_control_bcm.c @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2009-2012 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ + +/* + * bt_control_bcm.c + * + * Adapter to use Broadcom-based chipsets with BTstack + */ + + +#include "btstack-config.h" +#include "bt_control_bcm.h" + +#include /* NULL */ +#include +#include /* memcpy */ + +#include "bt_control.h" +#include "debug.h" + +// actual init script provided by separate bt_firmware_image.c from WICED SDK +extern const uint8_t brcm_patchram_buf[]; +extern const int brcm_patch_ram_length; +extern const char brcm_patch_version[]; + +// +static uint32_t init_script_offset; +static int send_download_command; + +static int bt_control_bcm_on(void *config){ + log_info("Broadcom init script %s, len %u", brcm_patch_version, brcm_patch_ram_length); + init_script_offset = 0; + send_download_command = 1; + return 0; +} + +// @note: Broadcom chips require higher UART clock for baud rate > 3000000 -> limit baud rate in hci.c +static int bcm_baudrate_cmd(void * config, uint32_t baudrate, uint8_t *hci_cmd_buffer){ + hci_cmd_buffer[0] = 0x18; + hci_cmd_buffer[1] = 0xfc; + hci_cmd_buffer[2] = 0x06; + hci_cmd_buffer[3] = 0x00; + hci_cmd_buffer[4] = 0x00; + bt_store_32(hci_cmd_buffer, 5, baudrate); + return 0; +} + +// @note: bd addr has to be set after sending init script (it might just get re-set) +static int bt_control_bcm_set_bd_addr_cmd(void * config, bd_addr_t addr, uint8_t *hci_cmd_buffer){ + hci_cmd_buffer[0] = 0x01; + hci_cmd_buffer[1] = 0xfc; + hci_cmd_buffer[2] = 0x06; + bt_flip_addr(&hci_cmd_buffer[3], addr); + return 0; +} + +static int bt_control_bcm_next_cmd(void *config, uint8_t *hci_cmd_buffer){ + + // send download firmware command + if (send_download_command){ + send_download_command = 0; + hci_cmd_buffer[0] = 0x2e; + hci_cmd_buffer[1] = 0xfc; + hci_cmd_buffer[2] = 0x00; + return 1; + } + + if (init_script_offset >= brcm_patch_ram_length) { + return 0; + } + + // use memcpy with pointer + int cmd_len = 3 + brcm_patchram_buf[init_script_offset+2]; + memcpy(&hci_cmd_buffer[0], &brcm_patchram_buf[init_script_offset], cmd_len); + init_script_offset += cmd_len; + return 1; +} + +// MARK: const structs + +static const bt_control_t bt_control_bcm = { + bt_control_bcm_on, // on + NULL, // off + NULL, // sleep + NULL, // wake + NULL, // valid + NULL, // name + bcm_baudrate_cmd, // baudrate_cmd + bt_control_bcm_next_cmd, // next_cmd + NULL, // register_for_power_notifications + NULL, // hw_error + bt_control_bcm_set_bd_addr_cmd, // set_bd_addr_cmd +}; + +// MARK: public API +bt_control_t * bt_control_bcm_instance(void){ + return (bt_control_t*) &bt_control_bcm; +} diff --git a/chipset-bcm/bt_control_bcm.h b/chipset-bcm/bt_control_bcm.h new file mode 100644 index 000000000..6de9f3370 --- /dev/null +++ b/chipset-bcm/bt_control_bcm.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009-2012 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ + +/* + * bt_control_bcm.h + * + * Adapter to use Broadcom-based chipsets with BTstack + */ + +#ifndef __BT_CONTROL_BCM_H +#define __BT_CONTROL_BCM_H + +#if defined __cplusplus +extern "C" { +#endif + +#include +#include "bt_control.h" + +bt_control_t * bt_control_bcm_instance(void); + +#if defined __cplusplus +} +#endif + +#endif // __BT_CONTROL_BCM_H From 37cb5f0da9f5222d0ac6d2e52d15f1716a36b2df Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 13 Jan 2016 15:15:37 +0100 Subject: [PATCH 3/3] fix indention --- chipset-bcm/bt_control_bcm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/chipset-bcm/bt_control_bcm.c b/chipset-bcm/bt_control_bcm.c index e850e6aa8..8f21f53ec 100644 --- a/chipset-bcm/bt_control_bcm.c +++ b/chipset-bcm/bt_control_bcm.c @@ -62,9 +62,9 @@ static int send_download_command; static int bt_control_bcm_on(void *config){ log_info("Broadcom init script %s, len %u", brcm_patch_version, brcm_patch_ram_length); - init_script_offset = 0; + init_script_offset = 0; send_download_command = 1; - return 0; + return 0; } // @note: Broadcom chips require higher UART clock for baud rate > 3000000 -> limit baud rate in hci.c @@ -112,15 +112,15 @@ static int bt_control_bcm_next_cmd(void *config, uint8_t *hci_cmd_buffer){ // MARK: const structs static const bt_control_t bt_control_bcm = { - bt_control_bcm_on, // on - NULL, // off - NULL, // sleep - NULL, // wake - NULL, // valid - NULL, // name - bcm_baudrate_cmd, // baudrate_cmd - bt_control_bcm_next_cmd, // next_cmd - NULL, // register_for_power_notifications + bt_control_bcm_on, // on + NULL, // off + NULL, // sleep + NULL, // wake + NULL, // valid + NULL, // name + bcm_baudrate_cmd, // baudrate_cmd + bt_control_bcm_next_cmd, // next_cmd + NULL, // register_for_power_notifications NULL, // hw_error bt_control_bcm_set_bd_addr_cmd, // set_bd_addr_cmd };