From d72d4f356d35d4a0963aa09dac7586bf3520f35d Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Tue, 20 Aug 2019 11:34:00 +0200 Subject: [PATCH] bluetooth: controller: define generic macros for LLL, ULL LOW IRQs This commit defines generic macros for the software interrupt (SWI) IRQ lines that are used for LLL and ULL LOW interrupts. This is done for both the cases of the legacy and new (split) controller architectures. In addition, it abstracts some of the functionality around software-IRQ signals, to generic functions, which have platform-specific implementations. Signed-off-by: Ioannis Glaropoulos --- .../ll_sw/nordic/hal/irq_vendor_hal.h | 7 ++++ .../controller/ll_sw/nordic/hal/nrf5/mayfly.c | 15 +++---- .../ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h | 39 +++++++++++++++++++ .../controller/ll_sw/nordic/lll/lll.c | 28 ++++++++----- 4 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 subsys/bluetooth/controller/ll_sw/nordic/hal/irq_vendor_hal.h create mode 100644 subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/irq_vendor_hal.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/irq_vendor_hal.h new file mode 100644 index 00000000000..de13525f2de --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/irq_vendor_hal.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "hal/nrf5/nrf5_sw_irqs.h" diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/mayfly.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/mayfly.c index efc24781303..44f457c2bbf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/mayfly.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/mayfly.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018 Nordic Semiconductor ASA + * Copyright (c) 2016-2019 Nordic Semiconductor ASA * Copyright (c) 2016 Vinayak Kariappa Chettimada * * SPDX-License-Identifier: Apache-2.0 @@ -14,6 +14,7 @@ #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 @@ -34,9 +35,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(SWI5_IRQn); + irq_enable(HAL_RADIO_SW_IRQ); } else { - irq_disable(SWI5_IRQn); + irq_disable(HAL_RADIO_SW_IRQ); } } @@ -47,14 +48,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(SWI4_IRQn); + return irq_is_enabled(HAL_RADIO_LLL_IRQ); #endif /* CONFIG_BT_LL_SW_SPLIT */ case MAYFLY_CALL_ID_WORKER: return irq_is_enabled(RTC0_IRQn); case MAYFLY_CALL_ID_JOB: - return irq_is_enabled(SWI5_IRQn); + return irq_is_enabled(HAL_RADIO_SW_IRQ); default: LL_ASSERT(0); @@ -104,7 +105,7 @@ 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: - NVIC_SetPendingIRQ(SWI4_IRQn); + hal_nrf5_pend_lll_irq(); break; #endif /* CONFIG_BT_LL_SW_SPLIT */ @@ -113,7 +114,7 @@ void mayfly_pend(u8_t caller_id, u8_t callee_id) break; case MAYFLY_CALL_ID_JOB: - NVIC_SetPendingIRQ(SWI5_IRQn); + hal_nrf5_pend_job_irq(); break; default: diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h new file mode 100644 index 00000000000..214c6b1be6a --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrf5_sw_irqs.h @@ -0,0 +1,39 @@ +/* + * 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_nrf5_irq_init(void) +{ + /* No platform-specific initialization required. */ +} + +/* SW IRQs required for the nRF5 BLE Controller (Split Architecture). */ +#if defined(CONFIG_BT_LL_SW_SPLIT) +#define HAL_RADIO_LLL_IRQ NRF5_IRQ_SWI4_IRQn +#define HAL_RADIO_ULL_LOW_IRQ NRF5_IRQ_SWI5_IRQn + +#define HAL_RADIO_SW_IRQ HAL_RADIO_ULL_LOW_IRQ + +static inline void hal_nrf5_pend_lll_irq(void) +{ + NVIC_SetPendingIRQ(HAL_RADIO_LLL_IRQ); +} + +#elif defined(CONFIG_BT_LL_SW_LEGACY) +/* A single SW IRQ is required for the nRF Legacy BLE Controller. */ +#define HAL_RADIO_SW_IRQ NRF5_IRQ_SWI5_IRQn + +#else +#error "CTRL architecture not defined" +#endif + +static inline void hal_nrf5_pend_job_irq(void) +{ + NVIC_SetPendingIRQ(HAL_RADIO_SW_IRQ); +} + +#endif /* CONFIG_SOC_SERIES_NRF51X || CONFIG_SOC_COMPATIBLE_NRF52X */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index d06cc4e33a6..c1f4e65907c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -11,9 +11,12 @@ #include #include +#include + #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" @@ -27,7 +30,7 @@ #define LOG_MODULE_NAME bt_ctlr_llsw_nordic_lll #include "common/log.h" -#include + #include "hal/debug.h" static struct { @@ -90,7 +93,7 @@ static void rtc0_nrf5_isr(void *arg) DEBUG_TICKER_ISR(0); } -static void swi4_nrf5_isr(void *arg) +static void lll_nrf5_isr(void *arg) { DEBUG_RADIO_ISR(1); @@ -99,7 +102,7 @@ static void swi4_nrf5_isr(void *arg) DEBUG_RADIO_ISR(0); } -static void swi5_nrf5_isr(void *arg) +static void ull_low_nrf5_isr(void *arg) { DEBUG_TICKER_JOB(1); @@ -142,21 +145,28 @@ int lll_init(void) return err; } + /* Initialize SW IRQ structure */ + hal_nrf5_irq_init(); + /* Connect ISRs */ IRQ_DIRECT_CONNECT(NRF5_IRQ_RADIO_IRQn, CONFIG_BT_CTLR_LLL_PRIO, radio_nrf5_isr, 0); - IRQ_CONNECT(NRF5_IRQ_SWI4_IRQn, CONFIG_BT_CTLR_LLL_PRIO, - swi4_nrf5_isr, NULL, 0); IRQ_CONNECT(NRF5_IRQ_RTC0_IRQn, CONFIG_BT_CTLR_ULL_HIGH_PRIO, rtc0_nrf5_isr, NULL, 0); - IRQ_CONNECT(NRF5_IRQ_SWI5_IRQn, CONFIG_BT_CTLR_ULL_LOW_PRIO, - swi5_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); +#endif /* Enable IRQs */ irq_enable(NRF5_IRQ_RADIO_IRQn); - irq_enable(NRF5_IRQ_SWI4_IRQn); irq_enable(NRF5_IRQ_RTC0_IRQn); - irq_enable(NRF5_IRQ_SWI5_IRQn); +#if HAL_RADIO_LLL_IRQ != HAL_RADIO_ULL_LOW_IRQ + irq_enable(HAL_RADIO_LLL_IRQ); + irq_enable(HAL_RADIO_ULL_LOW_IRQ); +#endif return 0; }