-
Notifications
You must be signed in to change notification settings - Fork 8.2k
nRF53: HCI driver & sample #20467
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
Merged
Merged
nRF53: HCI driver & sample #20467
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0e17225
CODEOWNERS: add code owners for nRFx IPM driver
ioannisg d788b90
drivers: ipm: add nRFx IPM driver
kl-cruz 3916949
soc: arm: nordic: adding ipc aliases for nRF53
bb94dbc
scripts: dts: Add new chosen declaration for the IPC shared memory
arnopo da75764
boards: arm: nrf5340_dk_nrf5340: bind shared memory with ipc shim in dts
kapi-no ba5e30f
Bluetooth: hci_raw: Add support for specifying buffer headroom
a9083b5
samples: bluetooth: adding hci_rpmsg sample
kapi-no df63dd8
drivers: bluetooth: hci: driver based on RPMsg transport
kapi-no fcfabdb
boards: nrf5340_dk_nrf5340: enable VS commands if building with BT
kapi-no d9daa8c
boards: nrf5340_dk_nrf5340: enable ECC if building with BT
kapi-no 2553316
boards: nrf5340_dk_nrf5340: use RPMsg as default HCI driver for BLE
kapi-no File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| /* | ||
ioannisg marked this conversation as resolved.
Outdated
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.
Outdated
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.
Outdated
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); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.