Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fa94dd871d | |||
| ebd9ac4ba9 | |||
| 80c14b0ff6 | |||
| d80b61d5ba | |||
| 39a16e22c1 |
@@ -15,7 +15,7 @@ It has been tested on the nRF5340 Audio DK, but it should work with any nRF5340
|
||||
### HCI over USB CDC
|
||||
|
||||
```sh
|
||||
west build -b nrf5340dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf
|
||||
west build -b nrf5340dk/nrf5340/cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf
|
||||
```
|
||||
_HCI over UART and timesync not tested._
|
||||
|
||||
@@ -25,7 +25,7 @@ _HCI over UART and timesync not tested._
|
||||
### HCI over USB CDC
|
||||
|
||||
```sh
|
||||
west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf
|
||||
west build -b nrf5340_audio_dk/nrf5340/cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=usb.overlay -DOVERLAY_CONFIG=overlay-usb.conf
|
||||
```
|
||||
|
||||
### HCI over UART 0 connected to Virtual UART in J-Link Probe
|
||||
@@ -38,12 +38,12 @@ west build -b nrf5340_audio_dk_nrf5340_cpuapp
|
||||
|
||||
Release build:
|
||||
```sh
|
||||
west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay
|
||||
west build -b nrf5340_audio_dk/nrf5340/cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay
|
||||
```
|
||||
|
||||
Debug build:
|
||||
```sh
|
||||
west build -b nrf5340_audio_dk_nrf5340_cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay -DOVERLAY_CONFIG=debug.conf
|
||||
west build -b nrf5340_audio_dk/nrf5340/cpuapp -- -DEXTRA_DTC_OVERLAY_FILE=uart1.overlay -DOVERLAY_CONFIG=debug.conf
|
||||
```
|
||||
|
||||
To use UART 1 via Arduino headers, the virtual UART of the J-Link probe needs to be disabled, e.g. with the JLink Configuration Tool.
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
gpios = <&arduino_header 10 GPIO_ACTIVE_HIGH>;
|
||||
label = "Controller to host timesync pin";
|
||||
};
|
||||
};
|
||||
alternate_toggle: pin_1 {
|
||||
gpios = <&arduino_header 11 GPIO_ACTIVE_HIGH>;
|
||||
label = "alternate toggle pin";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&uart0 {
|
||||
|
||||
@@ -41,3 +41,4 @@ CONFIG_BT_BUF_CMD_TX_COUNT=10
|
||||
# for the timesync command
|
||||
CONFIG_BT_HCI_RAW_CMD_EXT=y
|
||||
|
||||
CONFIG_NRFX_TIMER2=y
|
||||
|
||||
+65
-11
@@ -24,13 +24,14 @@
|
||||
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
|
||||
#include <zephyr/net/buf.h>
|
||||
#include <zephyr/net_buf.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/l2cap.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/bluetooth/buf.h>
|
||||
#include <zephyr/bluetooth/hci_raw.h>
|
||||
|
||||
#include <nrfx_timer.h>
|
||||
#include "audio_sync_timer.h"
|
||||
|
||||
#define LOG_MODULE_NAME hci_uart
|
||||
@@ -183,7 +184,7 @@ static void rx_isr(void)
|
||||
if (remaining == 0) {
|
||||
/* Packet received */
|
||||
LOG_DBG("putting RX packet in queue.");
|
||||
net_buf_put(&tx_queue, buf);
|
||||
k_fifo_put(&tx_queue, buf);
|
||||
state = ST_IDLE;
|
||||
}
|
||||
break;
|
||||
@@ -216,7 +217,7 @@ static void tx_isr(void)
|
||||
int len;
|
||||
|
||||
if (!buf) {
|
||||
buf = net_buf_get(&uart_tx_queue, K_NO_WAIT);
|
||||
buf = k_fifo_get(&uart_tx_queue, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
uart_irq_tx_disable(hci_uart_dev);
|
||||
return;
|
||||
@@ -257,15 +258,15 @@ static void tx_thread(void *p1, void *p2, void *p3)
|
||||
int err;
|
||||
|
||||
/* Wait until a buffer is available */
|
||||
buf = net_buf_get(&tx_queue, K_FOREVER);
|
||||
buf = k_fifo_get(&tx_queue, K_FOREVER);
|
||||
/* Pass buffer to the stack */
|
||||
err = bt_send(buf);
|
||||
if (err!=BT_HCI_ERR_SUCCESS) {
|
||||
if (err!=BT_HCI_ERR_EXT_HANDLED) {
|
||||
LOG_ERR("Unable to send (err %d)", err);
|
||||
if (err!=BT_HCI_ERR_SUCCESS) {
|
||||
if (err!=BT_HCI_ERR_EXT_HANDLED) {
|
||||
LOG_ERR("Unable to send (err %d)", err);
|
||||
}
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
/* Give other threads a chance to run if tx_queue keeps getting
|
||||
* new data all the time.
|
||||
@@ -279,7 +280,7 @@ static int h4_send(struct net_buf *buf)
|
||||
LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf),
|
||||
buf->len);
|
||||
|
||||
net_buf_put(&uart_tx_queue, buf);
|
||||
k_fifo_put(&uart_tx_queue, buf);
|
||||
uart_irq_tx_enable(hci_uart_dev);
|
||||
|
||||
return 0;
|
||||
@@ -369,6 +370,13 @@ static const struct gpio_dt_spec timesync_pin = GPIO_DT_SPEC_GET(TIMESYNC_GPIO,
|
||||
#error "No timesync gpio available!"
|
||||
#endif
|
||||
|
||||
#define ALTERNATE_TOGGLE_GPIO DT_NODELABEL(alternate_toggle)
|
||||
#if DT_NODE_HAS_STATUS(ALTERNATE_TOGGLE_GPIO, okay)
|
||||
static const struct gpio_dt_spec alternate_toggle_pin = GPIO_DT_SPEC_GET(ALTERNATE_TOGGLE_GPIO, gpios);
|
||||
#else
|
||||
#warning "No alternate toggle gpio availabe!"
|
||||
#endif
|
||||
|
||||
#define HCI_CMD_ISO_TIMESYNC (0x200)
|
||||
|
||||
struct hci_cmd_iso_timestamp_response {
|
||||
@@ -403,8 +411,50 @@ uint8_t hci_cmd_iso_timesync_cb(struct net_buf *buf)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define TIME_TO_WAIT_MS 1000
|
||||
#define SYNC_TOGGLE_TIMER_INSTANCE_NUMBER 2
|
||||
static const nrfx_timer_t sync_toggle_timer_instance =
|
||||
NRFX_TIMER_INSTANCE(SYNC_TOGGLE_TIMER_INSTANCE_NUMBER);
|
||||
|
||||
static nrfx_timer_config_t cfg = {.frequency = NRFX_MHZ_TO_HZ(1UL),
|
||||
.mode = NRF_TIMER_MODE_TIMER,
|
||||
.bit_width = NRF_TIMER_BIT_WIDTH_32,
|
||||
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
|
||||
.p_context = NULL};
|
||||
|
||||
static void sync_toggle_timer_isr_handler(nrf_timer_event_t event_type, void *p_context)
|
||||
{
|
||||
ARG_UNUSED(p_context);
|
||||
if(event_type == NRF_TIMER_EVENT_COMPARE1)
|
||||
{
|
||||
char * p_msg = p_context;
|
||||
uint32_t remainder_us = nrf_timer_cc_get(NRF_TIMER2,
|
||||
NRF_TIMER_CC_CHANNEL1);
|
||||
|
||||
#if DT_NODE_HAS_STATUS(ALTERNATE_TOGGLE_GPIO, okay)
|
||||
gpio_pin_toggle_dt( &alternate_toggle_pin );
|
||||
#endif
|
||||
|
||||
LOG_INF("%d\n", remainder_us );
|
||||
printf("Timer finished. Context passed to the handler: >%s<", p_msg);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// timer setup
|
||||
nrfx_err_t ret;
|
||||
ret = nrfx_timer_init(&sync_toggle_timer_instance, &cfg, sync_toggle_timer_isr_handler);
|
||||
if (ret - NRFX_ERROR_BASE_NUM) {
|
||||
LOG_ERR("nrfx timer init error: %d", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
uint32_t desired_ticks = nrfx_timer_ms_to_ticks(&sync_toggle_timer_instance, TIME_TO_WAIT_MS);
|
||||
nrfx_timer_compare(&sync_toggle_timer_instance, NRF_TIMER_CC_CHANNEL1, desired_ticks, true);
|
||||
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(SYNC_TOGGLE_TIMER_INSTANCE_NUMBER)), IRQ_PRIO_LOWEST,
|
||||
NRFX_TIMER_INST_HANDLER_GET(SYNC_TOGGLE_TIMER_INSTANCE_NUMBER), 0, 0);
|
||||
nrfx_timer_enable(&sync_toggle_timer_instance);
|
||||
|
||||
/* incoming events and data from the controller */
|
||||
static K_FIFO_DEFINE(rx_queue);
|
||||
int err;
|
||||
@@ -441,6 +491,10 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if DT_NODE_HAS_STATUS(ALTERNATE_TOGGLE_GPIO, okay)
|
||||
gpio_pin_configure_dt(&alternate_toggle_pin, GPIO_OUTPUT_INACTIVE);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AUDIO_SYNC_TIMER_USES_RTC
|
||||
/* Register iso_timesync command */
|
||||
static struct bt_hci_raw_cmd_ext cmd_list = {
|
||||
@@ -477,7 +531,7 @@ int main(void)
|
||||
while (1) {
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = net_buf_get(&rx_queue, K_FOREVER);
|
||||
buf = k_fifo_get(&rx_queue, K_FOREVER);
|
||||
err = h4_send(buf);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to send");
|
||||
|
||||
Reference in New Issue
Block a user