Skip to content

Commit

Permalink
nimble/transport/nrf53: Move RX from interrupt to task
Browse files Browse the repository at this point in the history
This adds option to move RX from interrupt to task. This is enforced if
monitor is used since montor code cannot be used from interrupts.
  • Loading branch information
andrzej-kaczmarek committed Oct 26, 2023
1 parent de00d44 commit 23b9324
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
31 changes: 23 additions & 8 deletions nimble/transport/nrf5340/src/nrf5340_ble_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@

static struct hci_ipc_sm g_hci_ipc_sm;

static void
rx_func(void *arg)
{
uint8_t *buf;
int len;

len = ipc_nrf5340_available_buf(IPC_RX_CHANNEL, (void **)&buf);
while (len > 0) {
len = hci_ipc_rx(&g_hci_ipc_sm, buf, len);
ipc_nrf5340_consume(IPC_RX_CHANNEL, len);
len = ipc_nrf5340_available_buf(IPC_RX_CHANNEL, (void **)&buf);
}
}

static int
nrf5340_ble_hci_acl_tx(struct os_mbuf *om)
{
Expand Down Expand Up @@ -95,22 +109,23 @@ nrf5340_ble_hci_iso_tx(struct os_mbuf *om)
static void
nrf5340_ble_hci_trans_rx(int channel, void *user_data)
{
uint8_t *buf;
int len;
assert(channel == IPC_RX_CHANNEL);

len = ipc_nrf5340_available_buf(channel, (void **)&buf);
while (len > 0) {
len = hci_ipc_rx(&g_hci_ipc_sm, buf, len);
ipc_nrf5340_consume(channel, len);
len = ipc_nrf5340_available_buf(channel, (void **)&buf);
}
#if MYNEWT_VAL(BLE_TRANSPORT_NRF5340_RX_TASK)
ble_transport_rx();
#else
rx_func(NULL);
#endif
}

static void
nrf5340_ble_hci_init(void)
{
SYSINIT_ASSERT_ACTIVE();

#if MYNEWT_VAL(BLE_TRANSPORT_NRF5340_RX_TASK)
ble_transport_rx_register(rx_func, NULL);
#endif
ipc_nrf5340_recv(IPC_RX_CHANNEL, nrf5340_ble_hci_trans_rx, NULL);
}

Expand Down
28 changes: 28 additions & 0 deletions nimble/transport/nrf5340/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.defs:
BLE_TRANSPORT_NRF5340_RX_TASK:
description: >
Use separate task for RX. This is required and enabled by default
if monitor is used, optional otherwise.
value: 0

syscfg.vals.BLE_MONITOR:
BLE_TRANSPORT_NRF5340_RX_TASK: 1
BLE_TRANSPORT_RX_PRIO: 1
BLE_TRANSPORT_RX_STACK_SIZE: 120

0 comments on commit 23b9324

Please sign in to comment.