Skip to content

Commit 403ae02

Browse files
committed
transport: Add bridge transport
blehci application is for controller only build with external interface. In case of dual-core MCUs (NRF5340, DA1469x) controller runs on second core that may not be able to operate on external interface. To be able to run blehci like application on dual-core systems, application side has to route traffic from external interface transport to internal transport. So far only one transport package was used, for bridge configuration application must include two transport packages. To facilitate this: - transport package has BLE_HCI_BRIDGE that is set to 1 for dual-core bridge configuration - common syscfg values defined for in all transports are moved to transport package (BLE_HCI_EVT_HI_BUF_COUNT..) - syscfg definitions present in all transport packages are converted to syscfg values - DA1469x and NRF5340 transports in bridge configuration will NOT create buffers for commands and events they relay on external transport provided buffers
1 parent 30370ff commit 403ae02

File tree

21 files changed

+167
-197
lines changed

21 files changed

+167
-197
lines changed

nimble/transport/da1469x/syscfg.yml

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,12 @@
1616
# under the License.
1717
#
1818

19-
syscfg.defs:
20-
BLE_HCI_EVT_HI_BUF_COUNT:
21-
description: 'Number of high-priority event buffers.'
22-
value: 2
19+
syscfg.vals.'!BLE_HCI_BRIDGE && !BLE_EXT_ADV':
20+
BLE_HCI_EVT_HI_BUF_COUNT: 2
21+
BLE_HCI_EVT_LO_BUF_COUNT: 8
22+
BLE_HCI_EVT_BUF_SIZE: 70
23+
BLE_ACL_BUF_COUNT: 4
24+
BLE_ACL_BUF_SIZE: 255
2325

24-
BLE_HCI_EVT_LO_BUF_COUNT:
25-
description: 'Number of low-priority event buffers.'
26-
value: 8
27-
28-
BLE_HCI_EVT_BUF_SIZE:
29-
description: 'Size of each event buffer, in bytes.'
30-
value: 70
31-
32-
BLE_ACL_BUF_COUNT:
33-
description: 'The number of ACL data buffers'
34-
value: 4
35-
36-
BLE_ACL_BUF_SIZE:
37-
description: >
38-
This is the maximum size of the data portion of HCI ACL data
39-
packets. It does not include the HCI data header (of 4 bytes).
40-
value: 255
41-
42-
syscfg.vals.BLE_EXT_ADV:
26+
syscfg.vals.'!BLE_HCI_BRIDGE && BLE_EXT_ADV':
4327
BLE_HCI_EVT_BUF_SIZE: 274

nimble/transport/dialog_cmac/cmac_driver/diag/src/cmac_diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "syscfg/syscfg.h"
2121
#include "mcu/mcu.h"
2222

23-
#if MYNEWT_VAL(BLE_HOST)
23+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
2424
void
2525
cmac_diag_setup_host(void)
2626
{

nimble/transport/dialog_cmac/cmac_driver/include/cmac_driver/cmac_shared.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct cmac_shared_data {
131131
uint8_t mbox_c2s_buf[ MYNEWT_VAL(CMAC_MBOX_SIZE_C2S) ];
132132
};
133133

134-
#if MYNEWT_VAL(BLE_HOST)
134+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
135135
extern volatile struct cmac_shared_data *g_cmac_shared_data;
136136
#elif MYNEWT_VAL(BLE_CONTROLLER)
137137
extern volatile struct cmac_shared_data g_cmac_shared_data;
@@ -161,7 +161,7 @@ void cmac_rand_set_isr_cb(cmac_rand_isr_cb_t cb);
161161
void cmac_shared_init(void);
162162
void cmac_shared_sync(void);
163163

164-
#if MYNEWT_VAL(BLE_HOST)
164+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
165165
#define CMAC_SHARED_LOCK_VAL 0x40000000
166166
#elif MYNEWT_VAL(BLE_CONTROLLER)
167167
#define CMAC_SHARED_LOCK_VAL 0xc0000000

nimble/transport/dialog_cmac/cmac_driver/pkg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ pkg.post_link_cmds.BLE_CONTROLLER:
3737

3838
pkg.pre_link_cmds.BLE_HOST:
3939
scripts/build_libcmac.sh: 100
40+
41+
pkg.pre_link_cmds.BLE_HCI_BRIDGE:
42+
scripts/build_libcmac.sh: 100

nimble/transport/dialog_cmac/cmac_driver/src/cmac_mbox.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cmac_mbox_set_write_notif_cb(cmac_mbox_write_notif_cb *cb)
4949
int
5050
cmac_mbox_read(void)
5151
{
52-
#if MYNEWT_VAL(BLE_HOST)
52+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
5353
volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_c2s;
5454
uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_c2s_buf;
5555
const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_C2S);
@@ -96,7 +96,7 @@ cmac_mbox_read(void)
9696
int
9797
cmac_mbox_write(const void *data, uint16_t len)
9898
{
99-
#if MYNEWT_VAL(BLE_HOST)
99+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
100100
volatile struct cmac_mbox *mbox = &g_cmac_shared_data->mbox_s2c;
101101
uint8_t *mbox_buf = (uint8_t *)&g_cmac_shared_data->mbox_s2c_buf;
102102
const uint16_t mbox_size = MYNEWT_VAL(CMAC_MBOX_SIZE_S2C);

nimble/transport/dialog_cmac/cmac_driver/src/cmac_rand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "os/os_arch.h"
2727
#include "os/os.h"
2828

29-
#if MYNEWT_VAL(BLE_HOST)
29+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
3030
int
3131
cmac_rand_is_active(void)
3232
{

nimble/transport/dialog_cmac/cmac_driver/src/cmac_shared.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
3535
#endif
3636

37-
#if MYNEWT_VAL(BLE_HOST)
37+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
3838
volatile struct cmac_shared_data *g_cmac_shared_data;
3939
#include "mcu/da1469x_clock.h"
4040
#define MCU_DIAG_SER(_x)
@@ -45,7 +45,7 @@ volatile struct cmac_shared_data g_cmac_shared_data __attribute__((section("
4545
void
4646
cmac_shared_init(void)
4747
{
48-
#if MYNEWT_VAL(BLE_HOST)
48+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
4949
g_cmac_shared_data = (void *)(MCU_MEM_SYSRAM_START_ADDRESS +
5050
MEMCTRL->CMI_SHARED_BASE_REG);
5151

@@ -77,7 +77,7 @@ cmac_shared_sync(void)
7777
* to wait until CMAC finished initialization as otherwise host may start
7878
* sending HCI packets which will timeout as there is no one to read them.
7979
*/
80-
#if MYNEWT_VAL(BLE_HOST)
80+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
8181
assert(g_cmac_shared_data->magic_sys == 0);
8282

8383
while (g_cmac_shared_data->magic_cmac != CMAC_SHARED_MAGIC_CMAC);

nimble/transport/dialog_cmac/src/ble_hci_cmac_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
BLE_MBUF_MEMBLOCK_OVERHEAD + \
4242
BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT)
4343

44+
#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
4445
static uint8_t ble_hci_pool_cmd_mempool_buf[
4546
OS_MEMPOOL_BYTES(HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ)];
4647
static struct os_mempool ble_hci_pool_cmd_mempool;
@@ -54,6 +55,7 @@ static uint8_t ble_hci_pool_evt_lo_mempool_buf[
5455
OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT),
5556
MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE))];
5657
static struct os_mempool ble_hci_pool_evt_lo_mempool;
58+
#endif
5759

5860
static uint8_t ble_hci_pool_acl_mempool_buf[
5961
OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_ACL_BUF_COUNT),
@@ -66,6 +68,7 @@ __attribute__((weak)) void ble_hci_trans_notify_free(void);
6668
static os_mempool_put_fn *g_ble_hci_pool_acl_mempool_put_cb;
6769
static void *g_ble_hci_pool_acl_mempool_put_arg;
6870

71+
#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
6972
int
7073
ble_hci_trans_reset(void)
7174
{
@@ -117,6 +120,7 @@ ble_hci_trans_buf_free(uint8_t *buf)
117120

118121
ble_hci_trans_notify_free();
119122
}
123+
#endif
120124

121125
struct os_mbuf *
122126
ble_hci_cmac_alloc_acl_mbuf(void)
@@ -147,6 +151,7 @@ ble_hci_cmac_free_acl_cb(struct os_mempool_ext *mpe, void *data, void *arg)
147151
}
148152

149153

154+
#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
150155
int
151156
ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
152157
{
@@ -155,6 +160,7 @@ ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
155160

156161
return 0;
157162
}
163+
#endif
158164

159165
void
160166
ble_hci_cmac_init(void)
@@ -163,6 +169,7 @@ ble_hci_cmac_init(void)
163169

164170
SYSINIT_ASSERT_ACTIVE();
165171

172+
#if !MYNEWT_VAL(BLE_HCI_BRIDGE)
166173
rc = os_mempool_init(&ble_hci_pool_cmd_mempool,
167174
HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ,
168175
ble_hci_pool_cmd_mempool_buf, "ble_hci_cmd");
@@ -179,6 +186,7 @@ ble_hci_cmac_init(void)
179186
MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE),
180187
ble_hci_pool_evt_lo_mempool_buf, "ble_hci_evt_lo");
181188
SYSINIT_PANIC_ASSERT(rc == 0);
189+
#endif
182190

183191
rc = os_mempool_ext_init(&ble_hci_pool_acl_mempool,
184192
MYNEWT_VAL(BLE_ACL_BUF_COUNT), POOL_ACL_BLOCK_SIZE,

nimble/transport/dialog_cmac/src/ble_hci_cmac_hs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <string.h>
2222
#include "syscfg/syscfg.h"
2323

24-
#if MYNEWT_VAL(BLE_HOST)
24+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
2525

2626
#include "cmac_driver/cmac_shared.h"
2727
#include "cmac_driver/cmac_host.h"

nimble/transport/dialog_cmac/src/ble_hci_trans_h4.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ble_hci_trans_h4_rxs_start(struct ble_hci_trans_h4_rx_state *rxs, uint8_t pkt_ty
6464
case BLE_HCI_TRANS_H4_PKT_TYPE_ACL:
6565
rxs->min_len = 4;
6666
break;
67-
#if MYNEWT_VAL(BLE_HOST)
67+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
6868
case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
6969
rxs->min_len = 2;
7070
break;
@@ -95,7 +95,7 @@ static int
9595
ble_hci_trans_h4_rx_state_w4_header(struct ble_hci_trans_h4_rx_state *rxs,
9696
struct input_buffer *ib)
9797
{
98-
#if MYNEWT_VAL(BLE_HOST)
98+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
9999
int pool;
100100
#endif
101101
int rc;
@@ -127,7 +127,7 @@ ble_hci_trans_h4_rx_state_w4_header(struct ble_hci_trans_h4_rx_state *rxs,
127127
os_mbuf_append(rxs->om, rxs->hdr, rxs->len);
128128
rxs->expected_len = get_le16(&rxs->hdr[2]) + 4;
129129
break;
130-
#if MYNEWT_VAL(BLE_HOST)
130+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
131131
case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
132132
pool = BLE_HCI_TRANS_BUF_EVT_HI;
133133
if (rxs->hdr[0] == BLE_HCI_EVCODE_LE_META) {
@@ -194,7 +194,7 @@ ble_hci_trans_h4_rx_state_w4_payload(struct ble_hci_trans_h4_rx_state *rxs,
194194
#if MYNEWT_VAL(BLE_CONTROLLER)
195195
case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
196196
#endif
197-
#if MYNEWT_VAL(BLE_HOST)
197+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
198198
case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
199199
#endif
200200
if (rxs->buf) {
@@ -240,7 +240,7 @@ ble_hci_trans_h4_rx_state_completed(struct ble_hci_trans_h4_rx_state *rxs,
240240
#if MYNEWT_VAL(BLE_CONTROLLER)
241241
case BLE_HCI_TRANS_H4_PKT_TYPE_CMD:
242242
#endif
243-
#if MYNEWT_VAL(BLE_HOST)
243+
#if MYNEWT_VAL(BLE_HOST) || MYNEWT_VAL(BLE_HCI_BRIDGE)
244244
case BLE_HCI_TRANS_H4_PKT_TYPE_EVT:
245245
#endif
246246
if (rxs->buf) {

0 commit comments

Comments
 (0)