Bluetooth: controller: Refactor use of SWI

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 <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2019-09-16 11:17:40 +05:30 committed by Carles Cufí
parent ee85f248fc
commit 78b461ae3e
7 changed files with 92 additions and 67 deletions

View file

@ -0,0 +1,7 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "hal/swi_vendor_hal.h"

View file

@ -1,7 +0,0 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "hal/nrf5/nrf5_sw_irqs.h"

View file

@ -8,13 +8,14 @@
#include <zephyr/types.h> #include <zephyr/types.h>
#include <soc.h> #include <soc.h>
#include "hal/nrf5/swi.h"
#include "util/memq.h" #include "util/memq.h"
#include "util/mayfly.h" #include "util/mayfly.h"
#define LOG_MODULE_NAME bt_ctlr_nrf5_mayfly #define LOG_MODULE_NAME bt_ctlr_nrf5_mayfly
#include "common/log.h" #include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#include "hal/nrf5/nrf5_sw_irqs.h"
#if defined(CONFIG_BT_LL_SW_LEGACY) #if defined(CONFIG_BT_LL_SW_LEGACY)
#define MAYFLY_CALL_ID_WORKER MAYFLY_CALL_ID_0 #define MAYFLY_CALL_ID_WORKER MAYFLY_CALL_ID_0
@ -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); LL_ASSERT(callee_id == MAYFLY_CALL_ID_JOB);
if (enable) { if (enable) {
irq_enable(HAL_RADIO_SW_IRQ); irq_enable(HAL_SWI_JOB_IRQ);
} else { } else {
irq_disable(HAL_RADIO_SW_IRQ); irq_disable(HAL_SWI_JOB_IRQ);
} }
} }
@ -48,14 +49,14 @@ u32_t mayfly_is_enabled(u8_t caller_id, u8_t callee_id)
switch (callee_id) { switch (callee_id) {
#if defined(CONFIG_BT_LL_SW_SPLIT) #if defined(CONFIG_BT_LL_SW_SPLIT)
case MAYFLY_CALL_ID_LLL: 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 */ #endif /* CONFIG_BT_LL_SW_SPLIT */
case MAYFLY_CALL_ID_WORKER: case MAYFLY_CALL_ID_WORKER:
return irq_is_enabled(RTC0_IRQn); return irq_is_enabled(HAL_SWI_WORKER_IRQ);
case MAYFLY_CALL_ID_JOB: case MAYFLY_CALL_ID_JOB:
return irq_is_enabled(HAL_RADIO_SW_IRQ); return irq_is_enabled(HAL_SWI_JOB_IRQ);
default: default:
LL_ASSERT(0); LL_ASSERT(0);
@ -105,16 +106,16 @@ void mayfly_pend(u8_t caller_id, u8_t callee_id)
switch (callee_id) { switch (callee_id) {
#if defined(CONFIG_BT_LL_SW_SPLIT) #if defined(CONFIG_BT_LL_SW_SPLIT)
case MAYFLY_CALL_ID_LLL: case MAYFLY_CALL_ID_LLL:
hal_nrf5_pend_lll_irq(); hal_swi_lll_pend();
break; break;
#endif /* CONFIG_BT_LL_SW_SPLIT */ #endif /* CONFIG_BT_LL_SW_SPLIT */
case MAYFLY_CALL_ID_WORKER: case MAYFLY_CALL_ID_WORKER:
NVIC_SetPendingIRQ(RTC0_IRQn); hal_swi_worker_pend();
break; break;
case MAYFLY_CALL_ID_JOB: case MAYFLY_CALL_ID_JOB:
hal_nrf5_pend_job_irq(); hal_swi_job_pend();
break; break;
default: default:

View file

@ -1,39 +0,0 @@
/*
* 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 */

View file

@ -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 */

View file

@ -0,0 +1,7 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "hal/nrf5/swi.h"

View file

@ -13,10 +13,10 @@
#include <soc.h> #include <soc.h>
#include "hal/swi.h"
#include "hal/ccm.h" #include "hal/ccm.h"
#include "hal/radio.h" #include "hal/radio.h"
#include "hal/ticker.h" #include "hal/ticker.h"
#include "hal/irq_vendor_hal.h"
#include "util/mem.h" #include "util/mem.h"
#include "util/memq.h" #include "util/memq.h"
@ -90,10 +90,14 @@ static void rtc0_nrf5_isr(void *arg)
mayfly_run(TICKER_USER_ID_ULL_HIGH); 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); DEBUG_TICKER_ISR(0);
} }
static void lll_nrf5_isr(void *arg) static void swi_lll_nrf5_isr(void *arg)
{ {
DEBUG_RADIO_ISR(1); DEBUG_RADIO_ISR(1);
@ -102,7 +106,8 @@ static void lll_nrf5_isr(void *arg)
DEBUG_RADIO_ISR(0); 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); DEBUG_TICKER_JOB(1);
@ -110,6 +115,7 @@ static void ull_low_nrf5_isr(void *arg)
DEBUG_TICKER_JOB(0); DEBUG_TICKER_JOB(0);
} }
#endif
int lll_init(void) int lll_init(void)
{ {
@ -146,26 +152,26 @@ int lll_init(void)
} }
/* Initialize SW IRQ structure */ /* Initialize SW IRQ structure */
hal_nrf5_irq_init(); hal_swi_init();
/* Connect ISRs */ /* Connect ISRs */
IRQ_DIRECT_CONNECT(NRF5_IRQ_RADIO_IRQn, CONFIG_BT_CTLR_LLL_PRIO, IRQ_DIRECT_CONNECT(NRF5_IRQ_RADIO_IRQn, CONFIG_BT_CTLR_LLL_PRIO,
radio_nrf5_isr, 0); radio_nrf5_isr, 0);
IRQ_CONNECT(NRF5_IRQ_RTC0_IRQn, CONFIG_BT_CTLR_ULL_HIGH_PRIO, IRQ_CONNECT(NRF5_IRQ_RTC0_IRQn, CONFIG_BT_CTLR_ULL_HIGH_PRIO,
rtc0_nrf5_isr, NULL, 0); rtc0_nrf5_isr, NULL, 0);
#if HAL_RADIO_LLL_IRQ != HAL_RADIO_ULL_LOW_IRQ IRQ_CONNECT(HAL_SWI_RADIO_IRQ, CONFIG_BT_CTLR_LLL_PRIO,
IRQ_CONNECT(HAL_RADIO_LLL_IRQ, CONFIG_BT_CTLR_LLL_PRIO, swi_lll_nrf5_isr, NULL, 0);
lll_nrf5_isr, NULL, 0); #if (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO)
IRQ_CONNECT(HAL_RADIO_ULL_LOW_IRQ, CONFIG_BT_CTLR_ULL_LOW_PRIO, IRQ_CONNECT(HAL_SWI_JOB_IRQ, CONFIG_BT_CTLR_ULL_LOW_PRIO,
ull_low_nrf5_isr, NULL, 0); swi_ull_low_nrf5_isr, NULL, 0);
#endif #endif
/* Enable IRQs */ /* Enable IRQs */
irq_enable(NRF5_IRQ_RADIO_IRQn); irq_enable(NRF5_IRQ_RADIO_IRQn);
irq_enable(NRF5_IRQ_RTC0_IRQn); irq_enable(NRF5_IRQ_RTC0_IRQn);
#if HAL_RADIO_LLL_IRQ != HAL_RADIO_ULL_LOW_IRQ irq_enable(HAL_SWI_RADIO_IRQ);
irq_enable(HAL_RADIO_LLL_IRQ); #if (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO)
irq_enable(HAL_RADIO_ULL_LOW_IRQ); irq_enable(HAL_SWI_JOB_IRQ);
#endif #endif
return 0; return 0;