-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] nimble/transport: Add ipc_icbmsg
- Loading branch information
1 parent
caecb2c
commit b5fda2a
Showing
8 changed files
with
290 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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,36 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
pkg.name: nimble/transport/ipc_icbmsg | ||
pkg.description: HCI transport via IPC | ||
pkg.author: "Apache Mynewt <[email protected]>" | ||
pkg.homepage: "http://mynewt.apache.org/" | ||
pkg.keywords: | ||
- ble | ||
- bluetooth | ||
- ipc_icbmsg | ||
|
||
pkg.deps: | ||
- nimble | ||
- nimble/transport/common/hci_ipc | ||
- "@apache-mynewt-core/kernel/os" | ||
- "@apache-mynewt-core/hw/drivers/ipc_icbmsg" | ||
|
||
pkg.apis: | ||
- ble_transport |
This file contains 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,216 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <string.h> | ||
#include <syscfg/syscfg.h> | ||
#include <sysinit/sysinit.h> | ||
#include <nimble/ble.h> | ||
#include <ipc_icbmsg/ipc_icbmsg.h> | ||
#include <nimble/transport.h> | ||
#include <nimble/transport/hci_ipc.h> | ||
|
||
#define BLE_HCI_IPC_ID (0) | ||
|
||
static struct hci_ipc_sm g_hci_ipc_sm; | ||
|
||
static void ble_hci_trans_rx(const void *data, size_t len, void *user_data); | ||
static struct ipc_ept_cfg hci_ept_cfg = { | ||
.name = "nrf_bt_hci", | ||
.cb = { | ||
// .bound = hci_ept_bound, | ||
.received = ble_hci_trans_rx, | ||
}, | ||
}; | ||
static uint8_t hci_ept_local_addr; | ||
|
||
static int | ||
icbmsg_ble_hci_send_mbuf(struct hci_ipc_hdr *hdr, struct os_mbuf *om) | ||
{ | ||
int rc; | ||
struct os_mbuf *x; | ||
struct ipc_icmsg_buf buf; | ||
|
||
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf, | ||
sizeof(*hdr) + OS_MBUF_PKTHDR(om)->omp_len); | ||
assert(rc == 0); | ||
if (rc != 0) { | ||
return BLE_ERR_MEM_CAPACITY; | ||
} | ||
|
||
memcpy(buf.data, hdr, sizeof(*hdr)); | ||
buf.len = sizeof(*hdr); | ||
|
||
x = om; | ||
while (x) { | ||
memcpy(buf.data + buf.len, x->om_data, x->om_len); | ||
buf.len += x->om_len; | ||
x = SLIST_NEXT(x, om_next); | ||
} | ||
|
||
rc = ipc_icbmsg_send_buf(BLE_HCI_IPC_ID, hci_ept_local_addr, &buf); | ||
|
||
os_mbuf_free_chain(om); | ||
|
||
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0; | ||
} | ||
|
||
static int | ||
icbmsg_ble_hci_acl_tx(struct os_mbuf *om) | ||
{ | ||
struct hci_ipc_hdr hdr; | ||
|
||
hdr.type = HCI_IPC_TYPE_ACL; | ||
hdr.length = 4 + get_le16(&om->om_data[2]); | ||
|
||
return icbmsg_ble_hci_send_mbuf(&hdr, om); | ||
} | ||
|
||
#if !MYNEWT_VAL(BLE_CONTROLLER) | ||
static int | ||
icbmsg_ble_hci_iso_tx(struct os_mbuf *om) | ||
{ | ||
struct hci_ipc_hdr hdr; | ||
|
||
hdr.type = HCI_IPC_TYPE_ISO; | ||
hdr.length = 4 + get_le16(&om->om_data[2]); | ||
|
||
return icbmsg_ble_hci_send_mbuf(&hdr, om); | ||
} | ||
#endif | ||
|
||
static void | ||
ble_hci_trans_rx(const void *data, size_t len, void *user_data) | ||
{ | ||
// assert(channel == IPC_RX_CHANNEL); | ||
|
||
hci_ipc_rx(&g_hci_ipc_sm, data, len); | ||
} | ||
|
||
static void | ||
icbmsg_ble_hci_init(void) | ||
{ | ||
os_sr_t sr; | ||
|
||
SYSINIT_ASSERT_ACTIVE(); | ||
|
||
OS_ENTER_CRITICAL(sr); | ||
hci_ept_local_addr = ipc_icmsg_register_ept(BLE_HCI_IPC_ID, &hci_ept_cfg); | ||
OS_EXIT_CRITICAL(sr); | ||
|
||
// OS_ENTER_CRITICAL(sr); | ||
// ble_hci_trans_rx(IPC_RX_CHANNEL, NULL); | ||
// OS_EXIT_CRITICAL(sr); | ||
} | ||
|
||
#if MYNEWT_VAL(BLE_CONTROLLER) | ||
int | ||
ble_transport_to_hs_evt_impl(void *ev_buf) | ||
{ | ||
int rc; | ||
uint8_t *hci_ev = ev_buf; | ||
struct ipc_icmsg_buf buf; | ||
struct hci_ipc_hdr hdr; | ||
|
||
hdr.type = ble_transport_ipc_buf_evt_type_get(ev_buf); | ||
hdr.length = 2 + hci_ev[1]; | ||
|
||
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf, | ||
sizeof(hdr) + hdr.length); | ||
assert(rc == 0); | ||
if (rc != 0) { | ||
return BLE_ERR_MEM_CAPACITY; | ||
} | ||
|
||
memcpy(buf.data, &hdr, sizeof(hdr)); | ||
buf.len = sizeof(hdr); | ||
|
||
memcpy(buf.data + buf.len, hci_ev, hdr.length); | ||
buf.len += hdr.length; | ||
|
||
rc = ipc_icbmsg_send_buf(BLE_HCI_IPC_ID, hci_ept_local_addr, &buf); | ||
|
||
ble_transport_ipc_free(ev_buf); | ||
|
||
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0; | ||
} | ||
|
||
int | ||
ble_transport_to_hs_acl_impl(struct os_mbuf *om) | ||
{ | ||
return icbmsg_ble_hci_acl_tx(om); | ||
} | ||
|
||
void | ||
ble_transport_hs_init(void) | ||
{ | ||
hci_ipc_init(NULL, &g_hci_ipc_sm); | ||
icbmsg_ble_hci_init(); | ||
} | ||
#endif /* BLE_CONTROLLER */ | ||
|
||
#if !MYNEWT_VAL(BLE_CONTROLLER) | ||
int | ||
ble_transport_to_ll_cmd_impl(void *ev_buf) | ||
{ | ||
int rc; | ||
uint8_t *cmd = ev_buf; | ||
struct ipc_icmsg_buf buf; | ||
struct hci_ipc_hdr hdr; | ||
|
||
hdr.type = HCI_IPC_TYPE_CMD; | ||
hdr.length = 3 + cmd[2]; | ||
|
||
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf, | ||
sizeof(hdr) + hdr.length); | ||
assert(rc == 0); | ||
if (rc != 0) { | ||
return BLE_ERR_MEM_CAPACITY; | ||
} | ||
|
||
memcpy(buf.data, &hdr, sizeof(hdr)); | ||
buf.len = sizeof(hdr); | ||
|
||
memcpy(buf.data + buf.len, cmd, hdr.length); | ||
buf.len += hdr.length; | ||
|
||
ble_transport_ipc_free(ev_buf); | ||
|
||
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0; | ||
} | ||
|
||
int | ||
ble_transport_to_ll_acl_impl(struct os_mbuf *om) | ||
{ | ||
return icbmsg_ble_hci_acl_tx(om); | ||
} | ||
|
||
int | ||
ble_transport_to_ll_iso_impl(struct os_mbuf *om) | ||
{ | ||
return icbmsg_ble_hci_iso_tx(om); | ||
} | ||
|
||
void | ||
ble_transport_ll_init(void) | ||
{ | ||
hci_ipc_init(NULL, &g_hci_ipc_sm); | ||
icbmsg_ble_hci_init(); | ||
} | ||
#endif /* !BLE_CONTROLLER */ |
This file contains 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,20 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
syscfg.vals.BLE_MONITOR: | ||
BLE_TRANSPORT_RX_TASK_STACK_SIZE: 120 | ||
BLE_TRANSPORT_RX_TASK_PRIO: 1 |
This file contains 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 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 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