Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nRF53: HCI driver & sample #20467

Merged
merged 11 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
/drivers/ieee802154/ @jukkar @tbursztyka
/drivers/interrupt_controller/ @andrewboie
/drivers/ipm/ipm_mhu* @karl-zh
/drivers/ipm/Kconfig.nrfx @masz-nordic @ioannisg
/drivers/ipm/Kconfig.nrfx_ipc_channel @masz-nordic @ioannisg
/drivers/ipm/ipm_nrfx_ipc.c @masz-nordic @ioannisg
/drivers/ipm/ipm_nrfx_ipc.h @masz-nordic @ioannisg
/drivers/ipm/ipm_stm32_ipcc.c @arnop2
/drivers/*/vexriscv_litex.c @mateusz-holenko @kgugala @pgielda
/drivers/led/ @Mani-Sadhasivam
Expand Down
13 changes: 13 additions & 0 deletions boards/arm/nrf5340_dk_nrf5340/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ config BOARD_ENABLE_DCDC_HV
select SOC_DCDC_NRF53X_HV
default y

choice BT_HCI_BUS_TYPE
default BT_RPMSG if BT
endchoice

config HEAP_MEM_POOL_SIZE
default 4096 if BT_RPMSG

config BT_HAS_HCI_VS
default y if BT

endif # BOARD_NRF5340_DK_NRF5340_CPUAPP || BOARD_NRF5340_DK_NRF5340_CPUAPPNS

if BOARD_NRF5340_DK_NRF5340_CPUNET
Expand All @@ -29,4 +39,7 @@ if BOARD_NRF5340_DK_NRF5340_CPUNET
config BT_CTLR
default y if BT

config BT_ECC
default y if BT

endif # BOARD_NRF5340_DK_NRF5340_CPUNET
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/

/ {
chosen {
/* shared memory reserved for the inter-processor communication */
zephyr,ipc_shm = &sram0_shared;
};

/* SRAM allocated to shared memory */
sram0_shared: memory@20010000 {
device_type = "memory";
Expand Down
4 changes: 3 additions & 1 deletion drivers/bluetooth/hci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
zephyr_sources_ifdef(CONFIG_BT_H4 h4.c)
zephyr_sources_ifdef(CONFIG_BT_H5 h5.c)
zephyr_sources_ifdef(CONFIG_BT_SPI spi.c)
zephyr_sources_ifdef(CONFIG_BT_STM32_IPM ipm_stm32wb.c)
zephyr_sources_ifdef(CONFIG_BT_RPMSG rpmsg.c)
zephyr_sources_ifdef(CONFIG_BT_RPMSG_NRF53 rpmsg_nrf53.c)
zephyr_sources_ifdef(CONFIG_BT_STM32_IPM ipm_stm32wb.c)
ioannisg marked this conversation as resolved.
Show resolved Hide resolved
zephyr_sources_ifdef(CONFIG_BT_USERCHAN userchan.c)
36 changes: 36 additions & 0 deletions drivers/bluetooth/hci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ config BT_H5
Bluetooth three-wire (H:5) UART driver. Implementation of HCI
Three-Wire UART Transport Layer.

config BT_RPMSG
bool "HCI using RPMsg"
help
Bluetooth HCI driver for communication with another CPU
using RPMsg framework.

config BT_SPI
bool "SPI HCI"
depends on SPI
Expand Down Expand Up @@ -92,3 +98,33 @@ config BT_SPI_BLUENRG
Stack. Current driver supports: ST BLUENRG-MS.

endif # BT_SPI

if BT_RPMSG

config BT_RPMSG_NRF53
ioannisg marked this conversation as resolved.
Show resolved Hide resolved
bool "nRF53 configuration of RPMsg"
default y if BOARD_NRF5340_DK_NRF5340_CPUAPP
select IPM
select IPM_NRFX
select IPM_MSG_CH_1_ENABLE
select IPM_MSG_CH_0_ENABLE
select IPM_MSG_CH_0_TX
select IPM_MSG_CH_1_RX
select OPENAMP
help
Enable RPMsg configuration for nRF53. Two channels of the IPM driver
are used in the HCI driver: channel 0 for TX and channel 1 for RX.

if BT_RPMSG_NRF53

config BT_RPMSG_NRF53_RX_STACK_SIZE
int "RPMsg stack size for RX thread"
default 1024

config BT_RPMSG_NRF53_RX_PRIO
int "RPMsg RX thread priority"
default 8

endif # BT_RPMSG_NRF53

endif # BT_RPMSG
2 changes: 1 addition & 1 deletion drivers/bluetooth/hci/h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static const u8_t conf_rsp[] = { 0x04, 0x7b };
/* H5 signal buffers pool */
#define MAX_SIG_LEN 3
#define SIGNAL_COUNT 2
#define SIG_BUF_SIZE (CONFIG_BT_HCI_RESERVE + MAX_SIG_LEN)
#define SIG_BUF_SIZE (BT_BUF_RESERVE + MAX_SIG_LEN)
NET_BUF_POOL_DEFINE(h5_pool, SIGNAL_COUNT, SIG_BUF_SIZE, 0, NULL);

static struct device *h5_dev;
Expand Down
185 changes: 185 additions & 0 deletions drivers/bluetooth/hci/rpmsg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
ioannisg marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <init.h>
#include <sys/byteorder.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_driver.h>

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_hci_driver
#include "common/log.h"

#define RPMSG_CMD 0x01
#define RPMSG_ACL 0x02
#define RPMSG_SCO 0x03
#define RPMSG_EVT 0x04

int bt_rpmsg_platform_init(void);
int bt_rpmsg_platform_send(struct net_buf *buf);

static struct net_buf *bt_rpmsg_evt_recv(u8_t *data, size_t remaining,
bool *prio)
{
struct bt_hci_evt_hdr hdr;
struct net_buf *buf;

if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for event header");
return NULL;
}

memcpy((void *)&hdr, data, sizeof(hdr));
data += sizeof(hdr);
remaining -= sizeof(hdr);

if (remaining != hdr.len) {
BT_ERR("Event payload length is not correct");
return NULL;
}
BT_DBG("len %u", hdr.len);

buf = bt_buf_get_evt(hdr.evt, false, K_NO_WAIT);
if (!buf) {
BT_ERR("No available event buffers!");
return buf;
}

net_buf_add_mem(buf, &hdr, sizeof(hdr));
*prio = bt_hci_evt_is_prio(hdr.evt);

net_buf_add_mem(buf, data, remaining);

return buf;
}

static struct net_buf *bt_rpmsg_acl_recv(u8_t *data, size_t remaining)
{
struct bt_hci_acl_hdr hdr;
struct net_buf *buf;

if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for ACL header");
return NULL;
}

buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_NO_WAIT);
if (buf) {
memcpy((void *)&hdr, data, sizeof(hdr));
data += sizeof(hdr);
remaining -= sizeof(hdr);

net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else {
BT_ERR("No available ACL buffers!");
return NULL;
}

if (remaining != sys_le16_to_cpu(hdr.len)) {
BT_ERR("ACL payload length is not correct");
net_buf_unref(buf);
return NULL;
ioannisg marked this conversation as resolved.
Show resolved Hide resolved
}

BT_DBG("len %u", remaining);
net_buf_add_mem(buf, data, remaining);

return buf;
}

void bt_rpmsg_rx(u8_t *data, size_t len)
{
u8_t pkt_indicator;
bool prio = false;
struct net_buf *buf = NULL;
size_t remaining = len;

BT_HEXDUMP_DBG(data, len, "RPMsg data:");

pkt_indicator = *data++;
remaining -= sizeof(pkt_indicator);

switch (pkt_indicator) {
case RPMSG_EVT:
buf = bt_rpmsg_evt_recv(data, remaining, &prio);
break;

case RPMSG_ACL:
buf = bt_rpmsg_acl_recv(data, remaining);
break;

default:
BT_ERR("Unknown HCI type %u", pkt_indicator);
return;
}

if (buf) {
BT_DBG("Calling bt_recv(%p)", buf);
if (prio) {
bt_recv_prio(buf);
} else {
bt_recv(buf);
}

BT_HEXDUMP_DBG(buf->data, buf->len, "RX buf payload:");
}
}

static int bt_rpmsg_send(struct net_buf *buf)
{
int err;
u8_t pkt_indicator;

BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);

switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT:
pkt_indicator = RPMSG_ACL;
break;
case BT_BUF_CMD:
pkt_indicator = RPMSG_CMD;
break;
default:
BT_ERR("Unknown type %u", bt_buf_get_type(buf));
goto done;
}
net_buf_push_u8(buf, pkt_indicator);

BT_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:");
err = bt_rpmsg_platform_send(buf);
if (err < 0) {
BT_ERR("Failed to send (err %d)", err);
}

done:
net_buf_unref(buf);
return 0;
}

static int bt_rpmsg_open(void)
{
BT_DBG("");

return bt_rpmsg_platform_init();
}

static const struct bt_hci_driver drv = {
.name = "RPMsg",
.open = bt_rpmsg_open,
.send = bt_rpmsg_send,
kapi-no marked this conversation as resolved.
Show resolved Hide resolved
.bus = BT_HCI_DRIVER_BUS_IPM,
};

static int bt_rpmsg_init(struct device *unused)
{
ARG_UNUSED(unused);

return bt_hci_driver_register(&drv);
}

SYS_INIT(bt_rpmsg_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
Loading