Skip to content

Commit

Permalink
Bluetooth: controller: Refactor use of SWI
Browse files Browse the repository at this point in the history
Refactor to abstract the use of software interrupts in nRF5
Series.

Also, reduce the number of SWI used when interrupt priority
level configured is same for ULL High and ULL Low contexts.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
  • Loading branch information
cvinayak authored and carlescufi committed Sep 16, 2019
1 parent ee85f24 commit 78b461a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 67 deletions.
7 changes: 7 additions & 0 deletions subsys/bluetooth/controller/hal/swi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "hal/swi_vendor_hal.h"
7 changes: 0 additions & 7 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/irq_vendor_hal.h

This file was deleted.

19 changes: 10 additions & 9 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/mayfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include <zephyr/types.h>
#include <soc.h>

#include "hal/nrf5/swi.h"

#include "util/memq.h"
#include "util/mayfly.h"

#define LOG_MODULE_NAME bt_ctlr_nrf5_mayfly
#include "common/log.h"
#include "hal/debug.h"
#include "hal/nrf5/nrf5_sw_irqs.h"

#if defined(CONFIG_BT_LL_SW_LEGACY)
#define MAYFLY_CALL_ID_WORKER MAYFLY_CALL_ID_0
Expand All @@ -35,9 +36,9 @@ void mayfly_enable_cb(u8_t caller_id, u8_t callee_id, u8_t enable)
LL_ASSERT(callee_id == MAYFLY_CALL_ID_JOB);

if (enable) {
irq_enable(HAL_RADIO_SW_IRQ);
irq_enable(HAL_SWI_JOB_IRQ);
} else {
irq_disable(HAL_RADIO_SW_IRQ);
irq_disable(HAL_SWI_JOB_IRQ);
}
}

Expand All @@ -48,14 +49,14 @@ u32_t mayfly_is_enabled(u8_t caller_id, u8_t callee_id)
switch (callee_id) {
#if defined(CONFIG_BT_LL_SW_SPLIT)
case MAYFLY_CALL_ID_LLL:
return irq_is_enabled(HAL_RADIO_LLL_IRQ);
return irq_is_enabled(HAL_SWI_RADIO_IRQ);
#endif /* CONFIG_BT_LL_SW_SPLIT */

case MAYFLY_CALL_ID_WORKER:
return irq_is_enabled(RTC0_IRQn);
return irq_is_enabled(HAL_SWI_WORKER_IRQ);

case MAYFLY_CALL_ID_JOB:
return irq_is_enabled(HAL_RADIO_SW_IRQ);
return irq_is_enabled(HAL_SWI_JOB_IRQ);

default:
LL_ASSERT(0);
Expand Down Expand Up @@ -105,16 +106,16 @@ void mayfly_pend(u8_t caller_id, u8_t callee_id)
switch (callee_id) {
#if defined(CONFIG_BT_LL_SW_SPLIT)
case MAYFLY_CALL_ID_LLL:
hal_nrf5_pend_lll_irq();
hal_swi_lll_pend();
break;
#endif /* CONFIG_BT_LL_SW_SPLIT */

case MAYFLY_CALL_ID_WORKER:
NVIC_SetPendingIRQ(RTC0_IRQn);
hal_swi_worker_pend();
break;

case MAYFLY_CALL_ID_JOB:
hal_nrf5_pend_job_irq();
hal_swi_job_pend();
break;

default:
Expand Down
39 changes: 0 additions & 39 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h

This file was deleted.

50 changes: 50 additions & 0 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_COMPATIBLE_NRF52X)

static inline void hal_swi_init(void)
{
/* No platform-specific initialization required. */
}

/* SW IRQs required for the nRF5 BLE Controller. */
#if defined(CONFIG_BT_LL_SW_SPLIT)
/* Split architecture uses max. two SWI */
#define HAL_SWI_RADIO_IRQ NRF5_IRQ_SWI4_IRQn
#define HAL_SWI_WORKER_IRQ NRF5_IRQ_RTC0_IRQn

#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO)
#define HAL_SWI_JOB_IRQ HAL_SWI_WORKER_IRQ
#else
#define HAL_SWI_JOB_IRQ NRF5_IRQ_SWI5_IRQn
#endif

static inline void hal_swi_lll_pend(void)
{
NVIC_SetPendingIRQ(HAL_SWI_RADIO_IRQ);
}

#elif defined(CONFIG_BT_LL_SW_LEGACY)
/* Legacy controller uses max. one SWI */
#define HAL_SWI_WORKER_IRQ NRF5_IRQ_RTC0_IRQn
#define HAL_SWI_JOB_IRQ NRF5_IRQ_SWI5_IRQn

#else
#error "CTRL architecture not defined"
#endif

static inline void hal_swi_worker_pend(void)
{
NVIC_SetPendingIRQ(HAL_SWI_WORKER_IRQ);
}

static inline void hal_swi_job_pend(void)
{
NVIC_SetPendingIRQ(HAL_SWI_JOB_IRQ);
}

#endif /* CONFIG_SOC_SERIES_NRF51X || CONFIG_SOC_COMPATIBLE_NRF52X */
7 changes: 7 additions & 0 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/swi_vendor_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "hal/nrf5/swi.h"
30 changes: 18 additions & 12 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

#include <soc.h>

#include "hal/swi.h"
#include "hal/ccm.h"
#include "hal/radio.h"
#include "hal/ticker.h"
#include "hal/irq_vendor_hal.h"

#include "util/mem.h"
#include "util/memq.h"
Expand Down Expand Up @@ -90,10 +90,14 @@ static void rtc0_nrf5_isr(void *arg)

mayfly_run(TICKER_USER_ID_ULL_HIGH);

#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO)
mayfly_run(TICKER_USER_ID_ULL_LOW);
#endif

DEBUG_TICKER_ISR(0);
}

static void lll_nrf5_isr(void *arg)
static void swi_lll_nrf5_isr(void *arg)
{
DEBUG_RADIO_ISR(1);

Expand All @@ -102,14 +106,16 @@ static void lll_nrf5_isr(void *arg)
DEBUG_RADIO_ISR(0);
}

static void ull_low_nrf5_isr(void *arg)
#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO)
static void swi_ull_low_nrf5_isr(void *arg)
{
DEBUG_TICKER_JOB(1);

mayfly_run(TICKER_USER_ID_ULL_LOW);

DEBUG_TICKER_JOB(0);
}
#endif

int lll_init(void)
{
Expand Down Expand Up @@ -146,26 +152,26 @@ int lll_init(void)
}

/* Initialize SW IRQ structure */
hal_nrf5_irq_init();
hal_swi_init();

/* Connect ISRs */
IRQ_DIRECT_CONNECT(NRF5_IRQ_RADIO_IRQn, CONFIG_BT_CTLR_LLL_PRIO,
radio_nrf5_isr, 0);
IRQ_CONNECT(NRF5_IRQ_RTC0_IRQn, CONFIG_BT_CTLR_ULL_HIGH_PRIO,
rtc0_nrf5_isr, NULL, 0);
#if HAL_RADIO_LLL_IRQ != HAL_RADIO_ULL_LOW_IRQ
IRQ_CONNECT(HAL_RADIO_LLL_IRQ, CONFIG_BT_CTLR_LLL_PRIO,
lll_nrf5_isr, NULL, 0);
IRQ_CONNECT(HAL_RADIO_ULL_LOW_IRQ, CONFIG_BT_CTLR_ULL_LOW_PRIO,
ull_low_nrf5_isr, NULL, 0);
IRQ_CONNECT(HAL_SWI_RADIO_IRQ, CONFIG_BT_CTLR_LLL_PRIO,
swi_lll_nrf5_isr, NULL, 0);
#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO)
IRQ_CONNECT(HAL_SWI_JOB_IRQ, CONFIG_BT_CTLR_ULL_LOW_PRIO,
swi_ull_low_nrf5_isr, NULL, 0);
#endif

/* Enable IRQs */
irq_enable(NRF5_IRQ_RADIO_IRQn);
irq_enable(NRF5_IRQ_RTC0_IRQn);
#if HAL_RADIO_LLL_IRQ != HAL_RADIO_ULL_LOW_IRQ
irq_enable(HAL_RADIO_LLL_IRQ);
irq_enable(HAL_RADIO_ULL_LOW_IRQ);
irq_enable(HAL_SWI_RADIO_IRQ);
#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO)
irq_enable(HAL_SWI_JOB_IRQ);
#endif

return 0;
Expand Down

0 comments on commit 78b461a

Please sign in to comment.