From 954bfcf3dceb9ea9f6056a96f174a49aa567fc2c Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Wed, 17 Jan 2018 13:13:14 -0500 Subject: [PATCH] Fixes memory link on ACK packet and fixes for bootloader --- CMakeLists.txt | 1 - c3.conf | 8 ++--- nrf52_c3waironet.overlay | 11 +++++++ nrf52_sparkfun.overlay | 7 +++++ src/main.c | 66 +++++++++------------------------------- 5 files changed, 36 insertions(+), 57 deletions(-) create mode 100644 nrf52_c3waironet.overlay diff --git a/CMakeLists.txt b/CMakeLists.txt index db6e83a..667fb61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ set(CONF_FILE c3.conf) -set(BOARD nrf52_sparkfun) include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(NONE) diff --git a/c3.conf b/c3.conf index a58d05a..22ef17d 100644 --- a/c3.conf +++ b/c3.conf @@ -6,10 +6,7 @@ CONFIG_UART_CONSOLE=n CONFIG_GPIO=y CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_UART_NRF5_BAUD_RATE=1000000 -CONFIG_UART_NRF5_FLOW_CONTROL=n -CONFIG_CLOCK_CONTROL_NRF5_K32SRC_RC=y -CONFIG_CLOCK_CONTROL_NRF5_K32SRC_250PPM=y +CONFIG_UART_NRF5_BAUD_RATE=115200 CONFIG_MAIN_STACK_SIZE=512 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 CONFIG_BT=y @@ -18,3 +15,6 @@ CONFIG_BT_MAX_CONN=16 CONFIG_BT_TINYCRYPT_ECC=n CONFIG_BT_CTLR_DTM_HCI=y CONFIG_BT_CTLR_ASSERT_HANDLER=y + +# Bootloader stuff +CONFIG_TEXT_SECTION_OFFSET=0x200 diff --git a/nrf52_c3waironet.overlay b/nrf52_c3waironet.overlay new file mode 100644 index 0000000..d9e29a1 --- /dev/null +++ b/nrf52_c3waironet.overlay @@ -0,0 +1,11 @@ +&uart0 { + compatible = "nordic,nrf-uart"; + current-speed = <115200>; + status = "ok"; +}; + +/ { + chosen { + zephyr,code-partition = &slot0_partition; + }; +}; \ No newline at end of file diff --git a/nrf52_sparkfun.overlay b/nrf52_sparkfun.overlay index 19a3fa3..0b9926d 100644 --- a/nrf52_sparkfun.overlay +++ b/nrf52_sparkfun.overlay @@ -3,3 +3,10 @@ current-speed = <115200>; status = "ok"; }; + + +/ { + chosen { + zephyr,code-partition = &slot0_partition; + }; +}; diff --git a/src/main.c b/src/main.c index 66efb8b..0b525d8 100644 --- a/src/main.c +++ b/src/main.c @@ -403,7 +403,6 @@ void bt_uart_isr(struct device *unused) bt_uart_drain(hci_uart_dev); break; } - SYS_LOG_DBG("ALLOC %p", buf); } if (!uart_fifo_read(hci_uart_dev, &byte, sizeof(byte))) { @@ -463,7 +462,7 @@ static void unproc_thread(void) { rx_buf = net_buf_alloc(&acl_tx_pool, K_NO_WAIT); if (!rx_buf) { SYS_LOG_WRN("No available data buffers"); - return; + goto next; } bt_buf_set_type(rx_buf, BT_BUF_ACL_OUT); break; @@ -471,21 +470,26 @@ static void unproc_thread(void) { rx_buf = net_buf_alloc(&cmd_tx_pool, K_NO_WAIT); if (!rx_buf) { SYS_LOG_WRN("No available data buffers"); - return; + goto next; } bt_buf_set_type(rx_buf, BT_BUF_CMD); break; - case HCI_3WIRE_LINK_PKT: case HCI_3WIRE_ACK_PKT: + SYS_LOG_DBG("ACK PACKET"); + h5.rx_ack = H5_HDR_ACK(hdr); + goto next; + break; + case HCI_3WIRE_LINK_PKT: rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT); if (!rx_buf) { SYS_LOG_WRN("No available signal buffers"); return; } + SYS_LOG_DBG("ALLOC %p", rx_buf); break; default: SYS_LOG_ERR("Wrong packet type from host: %u", H5_HDR_PKT_TYPE(hdr)); - return; + goto next; } int byte; @@ -539,7 +543,6 @@ static void unproc_thread(void) { break; } next: - SYS_LOG_DBG("UNREF: %p", buf); net_buf_unref(buf); } } @@ -551,12 +554,12 @@ static void tx_thread(void) while (true) { struct net_buf *buf; - SYS_LOG_DBG("link_state %u", h5.link_state); - switch (h5.link_state) { case UNINIT: + h5_send_sync(); + k_sleep(250); case INIT: - /* FIXME: send conf */ + h5_send_config(); k_sleep(250); break; case ACTIVE: @@ -647,47 +650,6 @@ static int h5_open(struct device *unused) void bt_ctlr_assert_handle(char *file, u32_t line) { printk("Assert %s:%u", file, line); - /*u32_t len = 0, pos = 0; - - // Disable interrupts, this is unrecoverable - (void)irq_lock(); - - uart_irq_rx_disable(hci_uart_dev); - uart_irq_tx_disable(hci_uart_dev); - - if (file) { - while (file[len] != '\0') { - if (file[len] == '/') { - pos = len + 1; - } - len++; - } - file += pos; - len -= pos; - } - - uart_poll_out(hci_uart_dev, H4_EVT); */ - /* Vendor-Specific debug event */ - /*uart_poll_out(hci_uart_dev, 0xff); - 0xAA + strlen + \0 + 32-bit line number - uart_poll_out(hci_uart_dev, 1 + len + 1 + 4); - uart_poll_out(hci_uart_dev, 0xAA); - - if (len) { - while (*file != '\0') { - uart_poll_out(hci_uart_dev, *file); - file++; - } - uart_poll_out(hci_uart_dev, 0x00); - } - - uart_poll_out(hci_uart_dev, line >> 0 & 0xff); - uart_poll_out(hci_uart_dev, line >> 8 & 0xff); - uart_poll_out(hci_uart_dev, line >> 16 & 0xff); - uart_poll_out(hci_uart_dev, line >> 24 & 0xff);*/ - - while (1) { - } } #endif /* CONFIG_BT_CTLR_ASSERT_HANDLER */ @@ -738,9 +700,9 @@ void main(void) // Adds controller output to host output queue bt_enable_raw(&h5.host_queue); - while (1) { - struct net_buf *buf; + struct net_buf *buf = NULL; + while (true) { buf = net_buf_get(&h5.host_queue, K_FOREVER); if (packet_is_sync(buf)) {