Skip to content

Commit b5fda2a

Browse files
committed
[wip] nimble/transport: Add ipc_icbmsg
1 parent caecb2c commit b5fda2a

File tree

8 files changed

+290
-4
lines changed

8 files changed

+290
-4
lines changed

nimble/transport/common/hci_ipc/include/nimble/transport/hci_ipc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ struct hci_ipc_shm {
5555
void hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm);
5656
int hci_ipc_rx(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len);
5757

58+
#if 0
5859
extern void hci_ipc_atomic_put(volatile uint16_t *num);
5960
extern uint16_t hci_ipc_atomic_get(volatile uint16_t *num);
6061

6162
/* Just to optimize static inlines below, do not use directly! */
6263
extern volatile struct hci_ipc_shm *g_ipc_shm;
64+
#endif
6365

6466
static inline int
6567
hci_ipc_get(uint8_t type)
6668
{
69+
return 1;
70+
#if 0
6771
volatile struct hci_ipc_shm *shm = g_ipc_shm;
6872

6973
switch (type) {
@@ -76,11 +80,13 @@ hci_ipc_get(uint8_t type)
7680
}
7781

7882
return 0;
83+
#endif
7984
}
8085

8186
static inline void
8287
hci_ipc_put(uint8_t type)
8388
{
89+
#if 0
8490
volatile struct hci_ipc_shm *shm = g_ipc_shm;
8591

8692
switch (type) {
@@ -94,6 +100,7 @@ hci_ipc_put(uint8_t type)
94100
hci_ipc_atomic_put(&shm->n2a_num_evt_disc);
95101
break;
96102
}
103+
#endif
97104
}
98105

99106
#endif /* _HCI_IPC_H_ */

nimble/transport/common/hci_ipc/src/hci_ipc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ hci_ipc_rx(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len)
225225
void
226226
hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm)
227227
{
228+
memset(sm, 0, sizeof(*sm));
229+
#if 0
228230
assert(g_ipc_shm == NULL);
229231

230232
g_ipc_shm = shm;
231-
memset(sm, 0, sizeof(*sm));
232233

233234
#if MYNEWT_VAL(BLE_CONTROLLER)
234235
while (shm->n2a_num_evt_disc == 0) {
@@ -239,4 +240,5 @@ hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm)
239240
shm->n2a_num_evt = MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT);
240241
shm->n2a_num_evt_disc = MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT);
241242
#endif
243+
#endif
242244
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: nimble/transport/ipc_icbmsg
21+
pkg.description: HCI transport via IPC
22+
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
- ble
26+
- bluetooth
27+
- ipc_icbmsg
28+
29+
pkg.deps:
30+
- nimble
31+
- nimble/transport/common/hci_ipc
32+
- "@apache-mynewt-core/kernel/os"
33+
- "@apache-mynewt-core/hw/drivers/ipc_icbmsg"
34+
35+
pkg.apis:
36+
- ble_transport
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include <assert.h>
21+
#include <string.h>
22+
#include <syscfg/syscfg.h>
23+
#include <sysinit/sysinit.h>
24+
#include <nimble/ble.h>
25+
#include <ipc_icbmsg/ipc_icbmsg.h>
26+
#include <nimble/transport.h>
27+
#include <nimble/transport/hci_ipc.h>
28+
29+
#define BLE_HCI_IPC_ID (0)
30+
31+
static struct hci_ipc_sm g_hci_ipc_sm;
32+
33+
static void ble_hci_trans_rx(const void *data, size_t len, void *user_data);
34+
static struct ipc_ept_cfg hci_ept_cfg = {
35+
.name = "nrf_bt_hci",
36+
.cb = {
37+
// .bound = hci_ept_bound,
38+
.received = ble_hci_trans_rx,
39+
},
40+
};
41+
static uint8_t hci_ept_local_addr;
42+
43+
static int
44+
icbmsg_ble_hci_send_mbuf(struct hci_ipc_hdr *hdr, struct os_mbuf *om)
45+
{
46+
int rc;
47+
struct os_mbuf *x;
48+
struct ipc_icmsg_buf buf;
49+
50+
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf,
51+
sizeof(*hdr) + OS_MBUF_PKTHDR(om)->omp_len);
52+
assert(rc == 0);
53+
if (rc != 0) {
54+
return BLE_ERR_MEM_CAPACITY;
55+
}
56+
57+
memcpy(buf.data, hdr, sizeof(*hdr));
58+
buf.len = sizeof(*hdr);
59+
60+
x = om;
61+
while (x) {
62+
memcpy(buf.data + buf.len, x->om_data, x->om_len);
63+
buf.len += x->om_len;
64+
x = SLIST_NEXT(x, om_next);
65+
}
66+
67+
rc = ipc_icbmsg_send_buf(BLE_HCI_IPC_ID, hci_ept_local_addr, &buf);
68+
69+
os_mbuf_free_chain(om);
70+
71+
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0;
72+
}
73+
74+
static int
75+
icbmsg_ble_hci_acl_tx(struct os_mbuf *om)
76+
{
77+
struct hci_ipc_hdr hdr;
78+
79+
hdr.type = HCI_IPC_TYPE_ACL;
80+
hdr.length = 4 + get_le16(&om->om_data[2]);
81+
82+
return icbmsg_ble_hci_send_mbuf(&hdr, om);
83+
}
84+
85+
#if !MYNEWT_VAL(BLE_CONTROLLER)
86+
static int
87+
icbmsg_ble_hci_iso_tx(struct os_mbuf *om)
88+
{
89+
struct hci_ipc_hdr hdr;
90+
91+
hdr.type = HCI_IPC_TYPE_ISO;
92+
hdr.length = 4 + get_le16(&om->om_data[2]);
93+
94+
return icbmsg_ble_hci_send_mbuf(&hdr, om);
95+
}
96+
#endif
97+
98+
static void
99+
ble_hci_trans_rx(const void *data, size_t len, void *user_data)
100+
{
101+
// assert(channel == IPC_RX_CHANNEL);
102+
103+
hci_ipc_rx(&g_hci_ipc_sm, data, len);
104+
}
105+
106+
static void
107+
icbmsg_ble_hci_init(void)
108+
{
109+
os_sr_t sr;
110+
111+
SYSINIT_ASSERT_ACTIVE();
112+
113+
OS_ENTER_CRITICAL(sr);
114+
hci_ept_local_addr = ipc_icmsg_register_ept(BLE_HCI_IPC_ID, &hci_ept_cfg);
115+
OS_EXIT_CRITICAL(sr);
116+
117+
// OS_ENTER_CRITICAL(sr);
118+
// ble_hci_trans_rx(IPC_RX_CHANNEL, NULL);
119+
// OS_EXIT_CRITICAL(sr);
120+
}
121+
122+
#if MYNEWT_VAL(BLE_CONTROLLER)
123+
int
124+
ble_transport_to_hs_evt_impl(void *ev_buf)
125+
{
126+
int rc;
127+
uint8_t *hci_ev = ev_buf;
128+
struct ipc_icmsg_buf buf;
129+
struct hci_ipc_hdr hdr;
130+
131+
hdr.type = ble_transport_ipc_buf_evt_type_get(ev_buf);
132+
hdr.length = 2 + hci_ev[1];
133+
134+
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf,
135+
sizeof(hdr) + hdr.length);
136+
assert(rc == 0);
137+
if (rc != 0) {
138+
return BLE_ERR_MEM_CAPACITY;
139+
}
140+
141+
memcpy(buf.data, &hdr, sizeof(hdr));
142+
buf.len = sizeof(hdr);
143+
144+
memcpy(buf.data + buf.len, hci_ev, hdr.length);
145+
buf.len += hdr.length;
146+
147+
rc = ipc_icbmsg_send_buf(BLE_HCI_IPC_ID, hci_ept_local_addr, &buf);
148+
149+
ble_transport_ipc_free(ev_buf);
150+
151+
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0;
152+
}
153+
154+
int
155+
ble_transport_to_hs_acl_impl(struct os_mbuf *om)
156+
{
157+
return icbmsg_ble_hci_acl_tx(om);
158+
}
159+
160+
void
161+
ble_transport_hs_init(void)
162+
{
163+
hci_ipc_init(NULL, &g_hci_ipc_sm);
164+
icbmsg_ble_hci_init();
165+
}
166+
#endif /* BLE_CONTROLLER */
167+
168+
#if !MYNEWT_VAL(BLE_CONTROLLER)
169+
int
170+
ble_transport_to_ll_cmd_impl(void *ev_buf)
171+
{
172+
int rc;
173+
uint8_t *cmd = ev_buf;
174+
struct ipc_icmsg_buf buf;
175+
struct hci_ipc_hdr hdr;
176+
177+
hdr.type = HCI_IPC_TYPE_CMD;
178+
hdr.length = 3 + cmd[2];
179+
180+
rc = ipc_icbmsg_alloc_tx_buf(BLE_HCI_IPC_ID, &buf,
181+
sizeof(hdr) + hdr.length);
182+
assert(rc == 0);
183+
if (rc != 0) {
184+
return BLE_ERR_MEM_CAPACITY;
185+
}
186+
187+
memcpy(buf.data, &hdr, sizeof(hdr));
188+
buf.len = sizeof(hdr);
189+
190+
memcpy(buf.data + buf.len, cmd, hdr.length);
191+
buf.len += hdr.length;
192+
193+
ble_transport_ipc_free(ev_buf);
194+
195+
return (rc < 0) ? BLE_ERR_MEM_CAPACITY : 0;
196+
}
197+
198+
int
199+
ble_transport_to_ll_acl_impl(struct os_mbuf *om)
200+
{
201+
return icbmsg_ble_hci_acl_tx(om);
202+
}
203+
204+
int
205+
ble_transport_to_ll_iso_impl(struct os_mbuf *om)
206+
{
207+
return icbmsg_ble_hci_iso_tx(om);
208+
}
209+
210+
void
211+
ble_transport_ll_init(void)
212+
{
213+
hci_ipc_init(NULL, &g_hci_ipc_sm);
214+
icbmsg_ble_hci_init();
215+
}
216+
#endif /* !BLE_CONTROLLER */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
syscfg.vals.BLE_MONITOR:
19+
BLE_TRANSPORT_RX_TASK_STACK_SIZE: 120
20+
BLE_TRANSPORT_RX_TASK_PRIO: 1

nimble/transport/nrf5340/pkg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pkg.deps:
3030
- nimble
3131
- nimble/transport/common/hci_ipc
3232
- "@apache-mynewt-core/kernel/os"
33-
- "@apache-mynewt-core/hw/drivers/ipc_nrf5340"
33+
- "@apache-mynewt-core/hw/drivers/ipc_icbmsg"
3434

3535
pkg.apis:
3636
- ble_transport

nimble/transport/pkg.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pkg.keywords:
2828
pkg.apis:
2929
- ble_transport
3030

31+
pkg.deps:
32+
- nimble/transport/ipc_icbmsg
3133
pkg.deps.'BLE_TRANSPORT_HS == "native"':
3234
- nimble/host
3335
pkg.deps.'BLE_TRANSPORT_LL == "native"':
@@ -36,8 +38,9 @@ pkg.deps.'BLE_TRANSPORT_LL == "emspi"':
3638
- nimble/transport/emspi
3739
pkg.deps.'BLE_TRANSPORT_HS == "dialog_cmac" || BLE_TRANSPORT_LL == "dialog_cmac"':
3840
- nimble/transport/dialog_cmac
39-
pkg.deps.'BLE_TRANSPORT_HS == "nrf5340" || BLE_TRANSPORT_LL == "nrf5340"':
40-
- nimble/transport/nrf5340
41+
pkg.deps.'BLE_TRANSPORT_HS == "ipc_icbmsg" || BLE_TRANSPORT_LL == "ipc_icbmsg"':
42+
- nimble/transport/ipc_icbmsg
43+
# - nimble/transport/nrf5340
4144
pkg.deps.'BLE_TRANSPORT_LL == "socket"':
4245
- nimble/transport/socket
4346
pkg.deps.'BLE_TRANSPORT_HS == "uart"':

nimble/transport/syscfg.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ syscfg.defs:
2929
- native
3030
- dialog_cmac
3131
- nrf5340
32+
- ipc_icbmsg
3233
- uart
3334
- usb
3435
- cdc
@@ -44,6 +45,7 @@ syscfg.defs:
4445
- emspi
4546
- dialog_cmac
4647
- nrf5340
48+
- ipc_icbmsg
4749
- socket
4850
- apollo3
4951
- uart_ll

0 commit comments

Comments
 (0)