From 084ad01c1a9e12f0da3d2691f48405bf30ddf87a Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 20 Apr 2016 23:18:15 +0200 Subject: [PATCH] hci_transport/btstack_uart_block: create btstack_uart_block_embedded on top of hal_uart_dma. Pass in uart driver to H4/H5 instances --- platform/daemon/src/daemon.c | 2 +- .../embedded/btstack_uart_block_embedded.c | 153 ++++++++++++++++++ .../hci_transport_h4_ehcill_embedded.c | 2 +- platform/embedded/hci_transport_h4_embedded.c | 2 +- platform/posix/btstack_uart_block_posix.c | 9 +- platform/posix/hci_transport_h4_posix.c | 23 +-- platform/posix/hci_transport_h5_posix.c | 27 ++-- port/arduino/BTstack.cpp | 2 +- port/arduino/Makefile | 4 +- port/ez430-rf2560/Makefile | 11 +- port/ez430-rf2560/src/main.c | 2 +- port/ios/src/Makefile | 1 + port/ios/src/hci_transport_h4_iphone.c | 2 +- port/msp-exp430f5438-cc2564b/Makefile | 1 + .../example/hid_demo.c | 2 +- port/msp-exp430f5438-cc2564b/src/main.c | 2 +- port/msp430f5229lp-cc2564b/Makefile | 1 + port/msp430f5229lp-cc2564b/src/main.c | 2 +- port/pic32-harmony/src/btstack_port.c | 2 +- port/posix-h4/main.c | 3 +- port/stm32-f103rb-nucleo/Makefile | 3 + port/stm32-f103rb-nucleo/main.c | 2 +- port/wiced/hci_transport_h4_wiced.c | 2 +- port/wiced/main.c | 2 +- port/wiced/wiced.mk | 7 +- src/btstack_uart_block.h | 12 +- src/hci_transport.h | 11 +- 27 files changed, 232 insertions(+), 60 deletions(-) create mode 100644 platform/embedded/btstack_uart_block_embedded.c diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index 00fc0b8a6..7adf89489 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -1970,7 +1970,7 @@ int main (int argc, char * const * argv){ hci_transport_config_uart.baudrate_main = 0; hci_transport_config_uart.flowcontrol = 1; hci_transport_config_uart.device_name = UART_DEVICE; - transport = hci_transport_h4_instance(); + transport = hci_transport_h4_instance(btstack_uart_block_posix_instance()); #ifdef HAVE_PLATFORM_IPHONE_OS // use default (max) UART baudrate over netgraph interface diff --git a/platform/embedded/btstack_uart_block_embedded.c b/platform/embedded/btstack_uart_block_embedded.c new file mode 100644 index 000000000..63dcfc130 --- /dev/null +++ b/platform/embedded/btstack_uart_block_embedded.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2016 BlueKitchen GmbH + * + * 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 BLUEKITCHEN GMBH 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 + * contact@bluekitchen-gmbh.com + * + */ + +/* + * btstack_uart_block_embedded.c + * + * Common code to access UART via asynchronous block read/write commands on top of hal_uart_dma.h + * + */ + +#include "btstack_debug.h" +#include "btstack_uart_block.h" +#include "btstack_run_loop_embedded.h" +#include "hal_uart_dma.h" + +// uart config +static const btstack_uart_config_t * uart_config; + +// data source for integration with BTstack Runloop +static btstack_data_source_t transport_data_source; + +static int send_complete; +static int receive_complete; + +// callbacks +static void (*block_sent)(void); +static void (*block_received)(void); + + +static void btstack_uart_block_received(void){ + receive_complete = 1; + btstack_run_loop_embedded_trigger(); +} + +static void btstack_uart_block_sent(void){ + send_complete = 1; + btstack_run_loop_embedded_trigger(); +} + +static int btstack_uart_embedded_init(const btstack_uart_config_t * config){ + uart_config = config; + hal_uart_dma_set_block_received(&btstack_uart_block_received); + hal_uart_dma_set_block_sent(&btstack_uart_block_sent); + return 0; +} + +static void btstack_uart_embedded_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) { + switch (callback_type){ + case DATA_SOURCE_CALLBACK_POLL: + if (send_complete){ + send_complete = 0; + block_sent(); + } + if (block_received){ + block_received = 0; + block_received(); + } + break; + default: + break; + } +} + +static int btstack_uart_embedded_open(void){ + hal_uart_dma_init(); + hal_uart_dma_set_baud(uart_config->baudrate); + + // set up polling data_source + btstack_run_loop_set_data_source_handler(&transport_data_source, &btstack_uart_embedded_process); + btstack_run_loop_enable_data_source_callbacks(&transport_data_source, DATA_SOURCE_CALLBACK_POLL); + btstack_run_loop_add_data_source(&transport_data_source); + return 0; +} + +static int btstack_uart_embedded_close(void){ + return 0; +} + +static void btstack_uart_embedded_set_block_received( void (*block_handler)(void)){ + block_received = block_handler; +} + +static void btstack_uart_embedded_set_block_sent( void (*block_handler)(void)){ + block_sent = block_handler; +} + +static int btstack_uart_embedded_set_parity(int parity){ + return 0; +} + +static void btstack_uart_embedded_send_block(const uint8_t *data, uint16_t size){ + hal_uart_dma_send_block(data, size); +} + +static void btstack_uart_embedded_receive_block(uint8_t *buffer, uint16_t len){ + hal_uart_dma_receive_block(buffer, len); +} + +// static void btstack_uart_embedded_set_sleep(uint8_t sleep){ +// } + +// static void btstack_uart_embedded_set_csr_irq_handler( void (*csr_irq_handler)(void)){ +// } + +static const btstack_uart_block_t btstack_uart_embedded = { + /* int (*init)(hci_transport_config_uart_t * config); */ &btstack_uart_embedded_init, + /* int (*open)(void); */ &btstack_uart_embedded_open, + /* int (*close)(void); */ &btstack_uart_embedded_close, + /* void (*set_block_received)(void (*handler)(void)); */ &btstack_uart_embedded_set_block_received, + /* void (*set_block_sent)(void (*handler)(void)); */ &btstack_uart_embedded_set_block_sent, + /* int (*set_baudrate)(uint32_t baudrate); */ &hal_uart_dma_set_baud, + /* int (*set_parity)(int parity); */ &btstack_uart_embedded_set_parity, + /* void (*receive_block)(uint8_t *buffer, uint16_t len); */ &btstack_uart_embedded_receive_block, + /* void (*send_block)(const uint8_t *buffer, uint16_t length); */ &btstack_uart_embedded_send_block +}; + +const btstack_uart_block_t * btstack_uart_block_embedded_instance(void){ + return &btstack_uart_embedded; +} \ No newline at end of file diff --git a/platform/embedded/hci_transport_h4_ehcill_embedded.c b/platform/embedded/hci_transport_h4_ehcill_embedded.c index 2738367f0..1347e5c71 100644 --- a/platform/embedded/hci_transport_h4_ehcill_embedded.c +++ b/platform/embedded/hci_transport_h4_ehcill_embedded.c @@ -168,7 +168,7 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } // get h4 singleton -const hci_transport_t * hci_transport_h4_instance(void){ +const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver){ return &hci_transport_h4_ehcill_dma.transport; } diff --git a/platform/embedded/hci_transport_h4_embedded.c b/platform/embedded/hci_transport_h4_embedded.c index ba81da933..5fc034eac 100644 --- a/platform/embedded/hci_transport_h4_embedded.c +++ b/platform/embedded/hci_transport_h4_embedded.c @@ -297,6 +297,6 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } // get h4 singleton -const hci_transport_t * hci_transport_h4_instance(void){ +const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver){ return &hci_transport_h4_dma.transport; } diff --git a/platform/posix/btstack_uart_block_posix.c b/platform/posix/btstack_uart_block_posix.c index ae92cced8..15bad3eb3 100644 --- a/platform/posix/btstack_uart_block_posix.c +++ b/platform/posix/btstack_uart_block_posix.c @@ -43,6 +43,7 @@ */ #include "btstack_uart_block.h" +#include "btstack_run_loop.h" #include "btstack_debug.h" #include /* POSIX terminal control definitions */ @@ -50,10 +51,10 @@ #include /* UNIX standard function definitions */ // uart config -static const hci_transport_config_uart_t * uart_config; +static const btstack_uart_config_t * uart_config; // data source for integration with BTstack Runloop -static btstack_data_source_t transport_data_source; +static btstack_data_source_t transport_data_source; // block write static int write_bytes_len; @@ -68,7 +69,7 @@ static void (*block_sent)(void); static void (*block_received)(void); -static int btstack_uart_posix_init(const hci_transport_config_uart_t * config){ +static int btstack_uart_posix_init(const btstack_uart_config_t * config){ uart_config = config; return 0; } @@ -215,7 +216,7 @@ static int btstack_uart_posix_open(void){ const char * device_name = uart_config->device_name; const int flowcontrol = uart_config->flowcontrol; - const uint32_t baudrate = uart_config->baudrate_init; + const uint32_t baudrate = uart_config->baudrate; struct termios toptions; int flags = O_RDWR | O_NOCTTY | O_NONBLOCK; diff --git a/platform/posix/hci_transport_h4_posix.c b/platform/posix/hci_transport_h4_posix.c index 7811aa0b2..01dd32263 100644 --- a/platform/posix/hci_transport_h4_posix.c +++ b/platform/posix/hci_transport_h4_posix.c @@ -76,7 +76,9 @@ typedef enum { H4_W4_PAYLOAD, } H4_STATE; -const btstack_uart_block_t * btstack_uart; +// UART Driver + Config +static const btstack_uart_block_t * btstack_uart; +static btstack_uart_config_t uart_config; // write mutex static int uart_write_active; @@ -84,9 +86,6 @@ static int uart_write_active; // single instance static hci_transport_t * hci_transport_h4 = NULL; - -static hci_transport_config_uart_t * hci_transport_config_uart = NULL; - static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler; // packet reader state machine @@ -191,13 +190,14 @@ static void hci_transport_h4_init(const void * transport_config){ return; } - hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; + // extract UART config from transport config + hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; + uart_config.baudrate = hci_transport_config_uart->baudrate_init; + uart_config.flowcontrol = hci_transport_config_uart->flowcontrol; + uart_config.device_name = hci_transport_config_uart->device_name; - // TODO: move btstack_uart_block_t into hci_transport_config_uart - - // use fixed uart block posix implementation for now - btstack_uart = btstack_uart_block_posix_instance(); - btstack_uart->init(hci_transport_config_uart); + // setup UART driver + btstack_uart->init(&uart_config); btstack_uart->set_block_received(&hci_transport_h4_block_read); btstack_uart->set_block_sent(&hci_transport_h4_block_sent); } @@ -242,7 +242,7 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } // get h4 singleton -const hci_transport_t * hci_transport_h4_instance(void) { +const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver) { if (hci_transport_h4 == NULL) { hci_transport_h4 = (hci_transport_t*)malloc( sizeof(hci_transport_t)); memset(hci_transport_h4, 0, sizeof(hci_transport_t)); @@ -255,5 +255,6 @@ const hci_transport_t * hci_transport_h4_instance(void) { hci_transport_h4->send_packet = hci_transport_h4_send_packet; hci_transport_h4->set_baudrate = hci_transport_h4_set_baudrate; } + btstack_uart = uart_driver; return hci_transport_h4; } diff --git a/platform/posix/hci_transport_h5_posix.c b/platform/posix/hci_transport_h5_posix.c index 69e6bf3bd..0735931df 100644 --- a/platform/posix/hci_transport_h5_posix.c +++ b/platform/posix/hci_transport_h5_posix.c @@ -124,9 +124,6 @@ static uint8_t hci_packet_type; static uint16_t hci_packet_size; static uint8_t * hci_packet; -// device -static hci_transport_config_uart_t * hci_transport_config_uart; - // hci_transport_t instance static hci_transport_t * hci_transport_h5; @@ -135,7 +132,9 @@ static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t si static int hci_transport_link_actions; -const btstack_uart_block_t * btstack_uart; +// UART Driver + Config +static const btstack_uart_block_t * btstack_uart; +static btstack_uart_config_t uart_config; static int uart_write_active; @@ -583,15 +582,14 @@ static void hci_transport_h5_posix_init(const void * transport_config){ return; } - // TODO: move btstack_uart_block_t into hci_transport_config_uart - - // use fixed uart block posix implementation for now - btstack_uart = btstack_uart_block_posix_instance(); - - btstack_uart->init((hci_transport_config_uart_t*) transport_config); - - hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; + // extract UART config from transport config + hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config; + uart_config.baudrate = hci_transport_config_uart->baudrate_init; + uart_config.flowcontrol = hci_transport_config_uart->flowcontrol; + uart_config.device_name = hci_transport_config_uart->device_name; + // setup UART driver + btstack_uart->init(&uart_config); btstack_uart->set_block_received(&hci_transport_h5_block_received); btstack_uart->set_block_sent(&hci_transport_h5_block_sent); } @@ -603,7 +601,7 @@ static int hci_transport_h5_posix_open(void){ } // setup resend timeout - hci_transport_link_update_resend_timeout(hci_transport_config_uart->baudrate_init); + hci_transport_link_update_resend_timeout(uart_config.baudrate); // init slip parser state machine hci_transport_slip_init(); @@ -677,7 +675,7 @@ static void hci_transport_h5_posix_reset_link(void){ } // get h5 singleton -const hci_transport_t * hci_transport_h5_instance(void) { +const hci_transport_t * hci_transport_h5_instance(const btstack_uart_block_t * uart_driver) { if (hci_transport_h5 == NULL) { hci_transport_h5 = (hci_transport_t*) malloc(sizeof(hci_transport_t)); memset(hci_transport_h5, 0, sizeof(hci_transport_t)); @@ -691,5 +689,6 @@ const hci_transport_t * hci_transport_h5_instance(void) { hci_transport_h5->set_baudrate = &hci_transport_h5_posix_set_baudrate; hci_transport_h5->reset_link = &hci_transport_h5_posix_reset_link; } + btstack_uart = uart_driver; return (const hci_transport_t *) hci_transport_h5; } diff --git a/port/arduino/BTstack.cpp b/port/arduino/BTstack.cpp index ea704ac0b..c0accdb9f 100644 --- a/port/arduino/BTstack.cpp +++ b/port/arduino/BTstack.cpp @@ -745,7 +745,7 @@ void BTstackManager::setup(void){ btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); - const hci_transport_t * transport = hci_transport_h4_instance(); + const hci_transport_t * transport = hci_transport_h4_instance(btstack_uart_block_embedded_instance()); hci_init(transport, NULL); hci_set_chipset(btstack_chipset_em9301_instance()); diff --git a/port/arduino/Makefile b/port/arduino/Makefile index 7f2ea7623..982df217f 100644 --- a/port/arduino/Makefile +++ b/port/arduino/Makefile @@ -9,12 +9,12 @@ VERSION=`sed -n -e 's/^.*BTSTACK_VERSION \"\(.*\)\"/\1/p' ${BTSTACK_ROOT}/platfo BTSTACK_PACKAGE=/tmp/btstack ARCHIVE=btstack-arduino-${VERSION}.zip -SRC_FILES = btstack_memory.c btstack_linked_list.c btstack_memory_pool.c btstack_run_loop.c +SRC_FILES = btstack_memory.c btstack_linked_list.c btstack_memory_pool.c btstack_run_loop.c SRC_FILES += hci_dump.c hci.c hci_cmd.c btstack_util.c l2cap.c BLE_FILES = ad_parser.c att_db.c att_server.c att_dispatch.c att_db_util.c le_device_db_memory.c gatt_client.c BLE_FILES += sm.c ancs_client.h ancs_client.c PORT_FILES = btstack_config.h bsp_arduino_em9301.cpp BTstack.cpp BTstack.h -EMBEDDED_FILES = btstack_run_loop_embedded.c hci_transport_h4_embedded.c +EMBEDDED_FILES = btstack_run_loop_embedded.c hci_transport_h4_embedded.c btstack_uart_block_embedded.c PATHS = $(addprefix ${BTSTACK_ROOT}/src/, ${SRC_FILES}) PATHS += $(wildcard ${BTSTACK_ROOT}/src/*.h) diff --git a/port/ez430-rf2560/Makefile b/port/ez430-rf2560/Makefile index 77d908adf..b53f0136a 100644 --- a/port/ez430-rf2560/Makefile +++ b/port/ez430-rf2560/Makefile @@ -50,12 +50,13 @@ CORE = \ btstack_util.c \ COMMON = \ - hal_uart_dma.c \ - btstack_chipset_cc256x.c \ - hci.c \ - hci_cmd.c \ + hal_uart_dma.c \ + btstack_chipset_cc256x.c \ + hci.c \ + hci_cmd.c \ hci_transport_h4_ehcill_embedded.c \ - btstack_link_key_db_memory.c \ + btstack_uart_block_embedded.c \ + btstack_link_key_db_memory.c \ SPP = \ l2cap.c \ diff --git a/port/ez430-rf2560/src/main.c b/port/ez430-rf2560/src/main.c index 643d8ac6c..6b7d62e8c 100644 --- a/port/ez430-rf2560/src/main.c +++ b/port/ez430-rf2560/src/main.c @@ -107,7 +107,7 @@ int main(void) btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - hci_init(hci_transport_h4_instance(), &config); + hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); diff --git a/port/ios/src/Makefile b/port/ios/src/Makefile index d9b7d1de1..220d592a3 100644 --- a/port/ios/src/Makefile +++ b/port/ios/src/Makefile @@ -43,6 +43,7 @@ BTdaemon_FILES = \ daemon.c \ hci.c \ hci_transport_h4_iphone.c \ + btstack_uart_block_posix.c \ l2cap.c \ l2cap_signaling.c \ platform_iphone.m \ diff --git a/port/ios/src/hci_transport_h4_iphone.c b/port/ios/src/hci_transport_h4_iphone.c index 160d82f28..eac89ab59 100644 --- a/port/ios/src/hci_transport_h4_iphone.c +++ b/port/ios/src/hci_transport_h4_iphone.c @@ -384,7 +384,7 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } // get h4 singleton -const hci_transport_t * hci_transport_h4_instance(void) { +const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver) { if (hci_transport_h4 == NULL) { hci_transport_h4 = (hci_transport_h4_t*)malloc( sizeof(hci_transport_h4_t)); memset(hci_transport_h4, 0, sizeof(hci_transport_h4_t)); diff --git a/port/msp-exp430f5438-cc2564b/Makefile b/port/msp-exp430f5438-cc2564b/Makefile index 6a1ce7056..470e8cc74 100644 --- a/port/msp-exp430f5438-cc2564b/Makefile +++ b/port/msp-exp430f5438-cc2564b/Makefile @@ -54,6 +54,7 @@ COMMON = \ btstack_chipset_cc256x.c \ hci.c \ hci_cmd.c \ + btstack_uart_block_embedded.c \ hci_transport_h4_ehcill_embedded.c \ btstack_link_key_db_memory.c \ diff --git a/port/msp-exp430f5438-cc2564b/example/hid_demo.c b/port/msp-exp430f5438-cc2564b/example/hid_demo.c index 1a3019ee5..886626653 100644 --- a/port/msp-exp430f5438-cc2564b/example/hid_demo.c +++ b/port/msp-exp430f5438-cc2564b/example/hid_demo.c @@ -378,7 +378,7 @@ int main(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); + const hci_transport_t * transport = hci_transport_h4_instance(btstack_uart_block_embedded_instance()); btstack_link_key_db_t * link_key_db = btstack_link_key_db_memory_instance(); hci_init(transport, &config); hci_set_link_key_db(link_key_db); diff --git a/port/msp-exp430f5438-cc2564b/src/main.c b/port/msp-exp430f5438-cc2564b/src/main.c index 0dcf4c0a8..08f02adbc 100644 --- a/port/msp-exp430f5438-cc2564b/src/main.c +++ b/port/msp-exp430f5438-cc2564b/src/main.c @@ -107,7 +107,7 @@ static void btstack_setup(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - hci_init(hci_transport_h4_instance(), &config); + hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); diff --git a/port/msp430f5229lp-cc2564b/Makefile b/port/msp430f5229lp-cc2564b/Makefile index 79386bf54..9b0d95e94 100644 --- a/port/msp430f5229lp-cc2564b/Makefile +++ b/port/msp430f5229lp-cc2564b/Makefile @@ -56,6 +56,7 @@ COMMON = \ btstack_chipset_cc256x.c \ hci.c \ hci_cmd.c \ + btstack_uart_block_embedded.c \ hci_transport_h4_ehcill_embedded.c \ btstack_link_key_db_memory.c \ diff --git a/port/msp430f5229lp-cc2564b/src/main.c b/port/msp430f5229lp-cc2564b/src/main.c index e6eebae33..7928b9e83 100644 --- a/port/msp430f5229lp-cc2564b/src/main.c +++ b/port/msp430f5229lp-cc2564b/src/main.c @@ -114,7 +114,7 @@ static void btstack_setup(void){ btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - hci_init(hci_transport_h4_instance(), &config); + hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), &config); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); diff --git a/port/pic32-harmony/src/btstack_port.c b/port/pic32-harmony/src/btstack_port.c index a4504d2b8..983096505 100644 --- a/port/pic32-harmony/src/btstack_port.c +++ b/port/pic32-harmony/src/btstack_port.c @@ -237,7 +237,7 @@ void BTSTACK_Initialize ( void ) hci_dump_open(NULL, HCI_DUMP_STDOUT); - const hci_transport_t * transport = hci_transport_h4_instance(); + const hci_transport_t * transport = hci_transport_h4_instance(btstack_uart_block_embedded_instance); hci_init(transport, &config); hci_set_chipset(btstack_chipset_csr_instance()); diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index ea18c9b24..ae4bd0dcb 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -172,7 +172,8 @@ int main(int argc, const char * argv[]){ config.device_name = "/dev/tty.usbserial-A900K0VK"; // init HCI - const hci_transport_t * transport = hci_transport_h4_instance(); + const btstack_uart_block_t * uart_driver = btstack_uart_block_posix_instance(); + const hci_transport_t * transport = hci_transport_h4_instance(uart_driver); const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance(); hci_init(transport, (void*) &config); hci_set_link_key_db(link_key_db); diff --git a/port/stm32-f103rb-nucleo/Makefile b/port/stm32-f103rb-nucleo/Makefile index c757f2094..4e78f7df2 100644 --- a/port/stm32-f103rb-nucleo/Makefile +++ b/port/stm32-f103rb-nucleo/Makefile @@ -33,6 +33,7 @@ COMMON = \ hci.c \ hci_cmd.c \ hci_dump.c \ + btstack_uart_block_embedded.c \ hci_transport_h4_ehcill_embedded.c \ l2cap.c \ l2cap_signaling.c \ @@ -69,6 +70,8 @@ include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc clean: rm -f *.map *.o *.d *.out *.elf *.bin *.hex + +distclean: clean make -C libopencm3 clean # git clone and compile libopencm3 diff --git a/port/stm32-f103rb-nucleo/main.c b/port/stm32-f103rb-nucleo/main.c index cc7253de9..e09e8aa5d 100644 --- a/port/stm32-f103rb-nucleo/main.c +++ b/port/stm32-f103rb-nucleo/main.c @@ -434,7 +434,7 @@ int main(void) btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); // init HCI - hci_init(hci_transport_h4_instance(), (void*) &config); + hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), (void*) &config); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_cc256x_instance()); diff --git a/port/wiced/hci_transport_h4_wiced.c b/port/wiced/hci_transport_h4_wiced.c index 998619797..f8fb1b562 100644 --- a/port/wiced/hci_transport_h4_wiced.c +++ b/port/wiced/hci_transport_h4_wiced.c @@ -330,7 +330,7 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } // get h4 singleton -const hci_transport_t * hci_transport_h4_instance(void) { +const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver) { if (hci_transport_h4 == NULL) { hci_transport_h4 = (hci_transport_h4_t*)malloc( sizeof(hci_transport_h4_t)); memset(hci_transport_h4, 0, sizeof(hci_transport_h4_t)); diff --git a/port/wiced/main.c b/port/wiced/main.c index 5d3219b4c..2fa4667f2 100644 --- a/port/wiced/main.c +++ b/port/wiced/main.c @@ -82,7 +82,7 @@ void application_start(void){ // hci_dump_open(NULL, HCI_DUMP_STDOUT); // init HCI - hci_init(hci_transport_h4_instance(), (void*) &hci_transport_config_uart); + hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), (void*) &hci_transport_config_uart); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_bcm_instance()); diff --git a/port/wiced/wiced.mk b/port/wiced/wiced.mk index dcac0deb4..817b56f53 100644 --- a/port/wiced/wiced.mk +++ b/port/wiced/wiced.mk @@ -37,8 +37,9 @@ $(NAME)_SOURCES += \ # WICED port incl. support for Broadcom chipset $(NAME)_SOURCES += \ - main.c \ - btstack_run_loop_wiced.c \ - hci_transport_h4_wiced.c \ + main.c \ + btstack_run_loop_wiced.c \ + btstack_uart_block_embedded.c \ + hci_transport_h4_wiced.c \ ../../chipset/bcm/btstack_chipset_bcm.c \ ../../../drivers/bluetooth/firmware/$(BT_CHIP)$(BT_CHIP_REVISION)/bt_firmware_image.c \ diff --git a/src/btstack_uart_block.h b/src/btstack_uart_block.h index 3faa4c03e..5cd834c7a 100644 --- a/src/btstack_uart_block.h +++ b/src/btstack_uart_block.h @@ -46,14 +46,19 @@ #define __BTSTACK_UART_BLOCK_H #include -#include "hci_transport.h" + +typedef struct { + uint32_t baudrate; + int flowcontrol; + const char *device_name; +} btstack_uart_config_t; typedef struct { /** * init transport - * @param transport_config + * @param uart_config */ - int (*init)(const hci_transport_config_uart_t * config); + int (*init)(const btstack_uart_config_t * uart_config); /** * open transport connection @@ -102,5 +107,6 @@ typedef struct { // common implementations const btstack_uart_block_t * btstack_uart_block_posix_instance(void); +const btstack_uart_block_t * btstack_uart_block_embedded_instance(void); #endif diff --git a/src/hci_transport.h b/src/hci_transport.h index 66986edb1..f50234a72 100644 --- a/src/hci_transport.h +++ b/src/hci_transport.h @@ -47,6 +47,7 @@ #define __HCI_TRANSPORT_H #include +#include "btstack_uart_block.h" #include "btstack_run_loop.h" #if defined __cplusplus @@ -126,14 +127,16 @@ typedef struct { // inline various hci_transport_X.h files /* - * @brief + * @brief Setup H4 instance with uart_driver + * @param uart_driver to use */ -extern const hci_transport_t * hci_transport_h4_instance(void); +extern const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver); /* - * @brief + * @brief Setup H5 instance with uart_driver + * @param uart_driver to use */ -extern const hci_transport_t * hci_transport_h5_instance(void); +extern const hci_transport_t * hci_transport_h5_instance(const btstack_uart_block_t * uart_driver); /* * @brief