Skip to content

Commit 0979452

Browse files
committed
nimble/transport: Add support for IPC ICBMsg transport
Support for nRF5340.
1 parent caecb2c commit 0979452

File tree

12 files changed

+429
-1
lines changed

12 files changed

+429
-1
lines changed

nimble/controller/src/ble_ll.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,9 @@ void
20062006
ble_transport_ll_init(void)
20072007
{
20082008
/* Tell the host that we are ready to receive packets */
2009+
#if MYNEWT_VAL(BLE_LL_HCI_NOOP_AFTER_INIT)
20092010
ble_ll_hci_send_noop();
2011+
#endif
20102012
}
20112013

20122014
int

nimble/controller/syscfg.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ syscfg.defs:
226226
Enables LLCP tracing using HCI vendor-specific events.
227227
value: '0'
228228

229+
BLE_LL_HCI_NOOP_AFTER_INIT:
230+
description: >
231+
Enables sending the NO-OP opcode HCI event after LL init.
232+
value: '1'
233+
229234
# Configuration for LL supported features.
230235
#
231236
# There are a total 8 features that the LL can support. These can be found
@@ -643,6 +648,9 @@ syscfg.vals.BLE_LL_ISO_BROADCASTER:
643648
syscfg.vals.'!BLE_HOST && !BABBLESIM':
644649
BLE_LL_HCI_VS_EVENT_ON_ASSERT: 1
645650

651+
syscfg.vals.'BLE_TRANSPORT_HS=="ipc"':
652+
BLE_LL_HCI_NOOP_AFTER_INIT: 0
653+
646654
syscfg.restrictions:
647655
- BLE_TRANSPORT_LL == "native"
648656
- BLE_LL_PUBLIC_DEV_ADDR <= 0xffffffffffff

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,26 @@
2121
#define _HCI_IPC_H_
2222

2323
#include <stdint.h>
24+
#include <syscfg/syscfg.h>
2425

26+
#if MYNEWT_VAL(IPC_ICBMSG)
27+
#include "nimble/hci_common.h"
28+
#define HCI_IPC_TYPE_CMD 0x01
29+
#define HCI_IPC_TYPE_ACL 0x02
30+
/* #define HCI_IPC_TYPE_SCO 0x03 */
31+
#define HCI_IPC_TYPE_EVT 0x04
32+
#define HCI_IPC_TYPE_ISO 0x05
33+
/* These two are not used actually */
34+
#define HCI_IPC_TYPE_EVT_DISCARDABLE 0x06
35+
#define HCI_IPC_TYPE_EVT_IN_CMD 0x07
36+
#else
2537
#define HCI_IPC_TYPE_CMD 0x01
2638
#define HCI_IPC_TYPE_ACL 0x02
2739
#define HCI_IPC_TYPE_EVT 0x04
2840
#define HCI_IPC_TYPE_EVT_DISCARDABLE 0x05
2941
#define HCI_IPC_TYPE_EVT_IN_CMD 0x06
3042
#define HCI_IPC_TYPE_ISO 0x07
43+
#endif
3144

3245
struct __attribute__((packed)) hci_ipc_hdr {
3346
uint8_t type;
@@ -55,15 +68,20 @@ struct hci_ipc_shm {
5568
void hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm);
5669
int hci_ipc_rx(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len);
5770

71+
#if !MYNEWT_VAL(IPC_ICBMSG)
5872
extern void hci_ipc_atomic_put(volatile uint16_t *num);
5973
extern uint16_t hci_ipc_atomic_get(volatile uint16_t *num);
6074

6175
/* Just to optimize static inlines below, do not use directly! */
6276
extern volatile struct hci_ipc_shm *g_ipc_shm;
77+
#endif
6378

6479
static inline int
6580
hci_ipc_get(uint8_t type)
6681
{
82+
#if MYNEWT_VAL(IPC_ICBMSG)
83+
return 1;
84+
#else
6785
volatile struct hci_ipc_shm *shm = g_ipc_shm;
6886

6987
switch (type) {
@@ -76,11 +94,13 @@ hci_ipc_get(uint8_t type)
7694
}
7795

7896
return 0;
97+
#endif
7998
}
8099

81100
static inline void
82101
hci_ipc_put(uint8_t type)
83102
{
103+
#if !MYNEWT_VAL(IPC_ICBMSG)
84104
volatile struct hci_ipc_shm *shm = g_ipc_shm;
85105

86106
switch (type) {
@@ -94,6 +114,7 @@ hci_ipc_put(uint8_t type)
94114
hci_ipc_atomic_put(&shm->n2a_num_evt_disc);
95115
break;
96116
}
117+
#endif
97118
}
98119

99120
#endif /* _HCI_IPC_H_ */

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ hci_ipc_alloc(struct hci_ipc_sm *sm)
8787
static bool
8888
hci_ipc_has_hdr(struct hci_ipc_sm *sm)
8989
{
90+
#if MYNEWT_VAL(IPC_ICBMSG)
91+
return sm->hdr_len == sizeof(sm->hdr.type);
92+
#else
9093
return sm->hdr_len == sizeof(sm->hdr);
94+
#endif
9195
}
9296

9397
static void
@@ -137,9 +141,33 @@ hci_ipc_frame(struct hci_ipc_sm *sm)
137141
sm->buf = NULL;
138142
}
139143

144+
#if MYNEWT_VAL(IPC_ICBMSG)
145+
static uint16_t
146+
hci_ipc_get_pkt_size(const uint8_t *buf, uint8_t type)
147+
{
148+
switch (type) {
149+
case HCI_IPC_TYPE_ACL:
150+
return sizeof(struct hci_data_hdr) + get_le16(&((struct hci_data_hdr *)buf)->hdh_len);
151+
case HCI_IPC_TYPE_EVT:
152+
return sizeof(struct ble_hci_ev) + ((struct ble_hci_ev *)buf)->length;
153+
case HCI_IPC_TYPE_CMD:
154+
return sizeof(struct ble_hci_cmd) + ((struct ble_hci_cmd *)buf)->length;
155+
case HCI_IPC_TYPE_ISO:
156+
return sizeof(struct ble_hci_iso) + get_le16(&((struct ble_hci_iso *)buf)->length);
157+
}
158+
159+
return 0;
160+
}
161+
#endif
162+
140163
static uint16_t
141164
hci_ipc_copy_to_hdr(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len)
142165
{
166+
#if MYNEWT_VAL(IPC_ICBMSG)
167+
len = 1;
168+
sm->hdr.type = buf[0];
169+
sm->hdr.length = hci_ipc_get_pkt_size(buf + 1, sm->hdr.type);
170+
#else
143171
uint16_t rem_hdr_len;
144172
uint8_t *p;
145173

@@ -152,6 +180,7 @@ hci_ipc_copy_to_hdr(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len)
152180

153181
p = (void *)&sm->hdr;
154182
memcpy(p + sm->hdr_len, buf, len);
183+
#endif
155184

156185
sm->hdr_len += len;
157186

@@ -225,10 +254,11 @@ hci_ipc_rx(struct hci_ipc_sm *sm, const uint8_t *buf, uint16_t len)
225254
void
226255
hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm)
227256
{
257+
memset(sm, 0, sizeof(*sm));
258+
#if !MYNEWT_VAL(IPC_ICBMSG)
228259
assert(g_ipc_shm == NULL);
229260

230261
g_ipc_shm = shm;
231-
memset(sm, 0, sizeof(*sm));
232262

233263
#if MYNEWT_VAL(BLE_CONTROLLER)
234264
while (shm->n2a_num_evt_disc == 0) {
@@ -239,4 +269,5 @@ hci_ipc_init(volatile struct hci_ipc_shm *shm, struct hci_ipc_sm *sm)
239269
shm->n2a_num_evt = MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT);
240270
shm->n2a_num_evt_disc = MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT);
241271
#endif
272+
#endif
242273
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.defs:
19+
IPC_ICBMSG:
20+
description: 'Enables ICBMsg backend for IPC.'
21+
value: 0
22+
23+
syscfg.vals.'BLE_TRANSPORT_LL=="ipc" || BLE_TRANSPORT_HS=="ipc"':
24+
IPC_ICBMSG: 1

nimble/transport/ipc/icbmsg/pkg.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 with ICBMsg backend
22+
pkg.author: "Apache Mynewt <[email protected]>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
- ble
26+
- bluetooth
27+
- ipc
28+
- icbmsg
29+
30+
pkg.deps:
31+
- nimble
32+
- nimble/transport/common/hci_ipc
33+
- "@apache-mynewt-core/hw/drivers/ipc/icbmsg"
34+
- "@apache-mynewt-core/kernel/os"
35+
- "@apache-mynewt-core/hw/drivers/ipc"
36+
37+
pkg.apis:
38+
- ble_transport

0 commit comments

Comments
 (0)