Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions subsys/bluetooth/controller/Kconfig.df
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ config BT_CTLR_DF_INIT_ANT_SEL_GPIOS
In such case application is responsible for appropriate GPIOs
initialization.

config BT_CTLR_DF_PER_ADV_CTE_NUM_MAX
int "Maximum number of transmitted PDUs with Constant Tone Extension in connectionless mode"
depends on BT_CTLR_DF_ADV_CTE_TX && BT_CTLR_ADV_PDU_LINK
range 1 16
default 1
help
Maximum supported number of PDUs, that have Constant Tone Extension, transmitted in single
periodic advertising chain. The range is taken from BT Core spec 5.1, Vol 4 Part E
section 7.8.82 HCI_LE_Set_Connectionless_IQ_Sampling_Enable Max_Sampled_CTEs parameter.

config BT_CTLR_DF_DEBUG_ENABLE
bool "Bluetooth Direction Finding debug support enable"
help
Expand Down
30 changes: 10 additions & 20 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "ll_sw/pdu.h"

#include "radio_internal.h"

#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
#if ((CONFIG_BT_CTLR_GPIO_PA_PIN) > 31)
#define NRF_GPIO_PA NRF_P1
Expand Down Expand Up @@ -490,19 +492,10 @@ void *radio_pkt_decrypt_get(void)

#if !defined(CONFIG_BT_CTLR_TIFS_HW)

#define SW_SWITCH_PREV_RX 0
#define SW_SWITCH_NEXT_RX 0
#define SW_SWITCH_PREV_TX 1
#define SW_SWITCH_NEXT_TX 1
#define SW_SWITCH_PREV_PHY_1M 0
#define SW_SWITCH_PREV_FLAGS_DONTCARE 0
#define SW_SWITCH_NEXT_FLAGS_DONTCARE 0

static uint8_t sw_tifs_toggle;

static inline void sw_switch(uint8_t dir_curr, uint8_t dir_next,
uint8_t phy_curr, uint8_t flags_curr,
uint8_t phy_next, uint8_t flags_next)
void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t flags_curr,
uint8_t phy_next, uint8_t flags_next)
{
uint8_t ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(sw_tifs_toggle);
uint8_t cc = SW_SWITCH_TIMER_EVTS_COMP(sw_tifs_toggle);
Expand All @@ -511,8 +504,8 @@ static inline void sw_switch(uint8_t dir_curr, uint8_t dir_next,
hal_radio_sw_switch_setup(cc, ppi, sw_tifs_toggle);

/* NOTE: As constants are passed to dir_curr and dir_next, the
* compiler should optimize out the redundant code path as
* this is an inline function.
* compiler should optimize out the redundant code path
* during the optimization.
*/
if (dir_next) {
/* TX */
Expand Down Expand Up @@ -649,9 +642,8 @@ void radio_switch_complete_and_rx(uint8_t phy_rx)
* across nRF5x radios, sw_switch assumes the 1M chain delay for
* calculations.
*/
sw_switch(SW_SWITCH_PREV_TX, SW_SWITCH_NEXT_RX,
SW_SWITCH_PREV_PHY_1M, SW_SWITCH_PREV_FLAGS_DONTCARE,
phy_rx, SW_SWITCH_NEXT_FLAGS_DONTCARE);
sw_switch(SW_SWITCH_TX, SW_SWITCH_RX, SW_SWITCH_PHY_1M, SW_SWITCH_FLAGS_DONTCARE, phy_rx,
SW_SWITCH_FLAGS_DONTCARE);
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

Expand All @@ -666,8 +658,7 @@ void radio_switch_complete_and_tx(uint8_t phy_rx, uint8_t flags_rx,
NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk |
RADIO_SHORTS_END_DISABLE_Msk;

sw_switch(SW_SWITCH_PREV_RX, SW_SWITCH_NEXT_TX,
phy_rx, flags_rx, phy_tx, flags_tx);
sw_switch(SW_SWITCH_RX, SW_SWITCH_TX, phy_rx, flags_rx, phy_tx, flags_tx);
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

Expand All @@ -682,8 +673,7 @@ void radio_switch_complete_and_b2b_tx(uint8_t phy_curr, uint8_t flags_curr,
NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk |
RADIO_SHORTS_END_DISABLE_Msk;

sw_switch(SW_SWITCH_PREV_TX, SW_SWITCH_NEXT_TX,
phy_curr, flags_curr, phy_next, flags_next);
sw_switch(SW_SWITCH_TX, SW_SWITCH_TX, phy_curr, flags_curr, phy_next, flags_next);
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "radio_nrf5.h"
#include "radio_df.h"
#include "radio_internal.h"

/* @brief Minimum antennas number required if antenna switching is enabled */
#define DF_ANT_NUM_MIN 2
Expand Down Expand Up @@ -315,7 +316,7 @@ void radio_df_ant_switch_pattern_clear(void)
NRF_RADIO->CLEARPATTERN = RADIO_CLEARPATTERN_CLEARPATTERN_Clear;
}

void radio_df_ant_switch_pattern_set(uint8_t *patterns, uint8_t len)
void radio_df_ant_switch_pattern_set(const uint8_t *patterns, uint8_t len)
{
/* SWITCHPATTERN is like a moving pointer to underlying buffer.
* Each write stores a value and moves the pointer to new free position.
Expand Down Expand Up @@ -359,6 +360,18 @@ void radio_switch_complete_and_phy_end_disable(void)
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

void radio_switch_complete_and_phy_end_b2b_tx(uint8_t phy_curr, uint8_t flags_curr,
uint8_t phy_next, uint8_t flags_next)
{
#if defined(CONFIG_BT_CTLR_TIFS_HW)
NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_PHYEND_DISABLE_Msk |
RADIO_SHORTS_DISABLED_TXEN_Msk;
#else /* !CONFIG_BT_CTLR_TIFS_HW */
NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_PHYEND_DISABLE_Msk;
sw_switch(SW_SWITCH_TX, SW_SWITCH_TX, phy_curr, flags_curr, phy_next, flags_next);
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

void radio_df_iq_data_packet_set(uint8_t *buffer, size_t len)
{
nrf_radio_dfe_buffer_set(NRF_RADIO, (uint32_t *)buffer, len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void radio_df_ant_switch_pattern_clear(void);
* Radio internal list. Before start of new patterns clear the list
* by call to @ref radio_df_ant_switch_pattern_clear.
*/
void radio_df_ant_switch_pattern_set(uint8_t *patterns, uint8_t len);
void radio_df_ant_switch_pattern_set(const uint8_t *patterns, uint8_t len);
/* Provides switch pattern of antenna used to transmit PDU that is used to
* transmit CTE
*/
Expand All @@ -50,6 +50,10 @@ void radio_df_reset(void);
/* Completes switching and enables shortcut between PHYEND and DISABLE events */
void radio_switch_complete_and_phy_end_disable(void);

/* Completes switching and enables shortcut between PHYEND and TXEN events */
void radio_switch_complete_and_phy_end_b2b_tx(uint8_t phy_curr, uint8_t flags_curr,
uint8_t phy_next, uint8_t flags_next);

/* Enables CTE inline configuration to automatically setup sampling and
* switching according to CTEInfo in received PDU.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#define SW_SWITCH_RX 0
#define SW_SWITCH_TX 1
#define SW_SWITCH_PHY_1M 0
#define SW_SWITCH_FLAGS_DONTCARE 0

void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t flags_curr,
uint8_t phy_next, uint8_t flags_next);
42 changes: 31 additions & 11 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ static inline bool isr_rx_ci_adva_check(uint8_t tx_addr, uint8_t *addr,
struct pdu_adv *ci);

#if defined(CONFIG_BT_CTLR_ADV_EXT)
#define PAYLOAD_FRAG_COUNT ((CONFIG_BT_CTLR_ADV_DATA_LEN_MAX + \
PDU_AC_PAYLOAD_SIZE_MAX - 1) / \
PDU_AC_PAYLOAD_SIZE_MAX)
#define PAYLOAD_BASED_FRAG_COUNT ((CONFIG_BT_CTLR_ADV_DATA_LEN_MAX + \
PDU_AC_PAYLOAD_SIZE_MAX - 1) / \
PDU_AC_PAYLOAD_SIZE_MAX)
#define PAYLOAD_FRAG_COUNT MAX(PAYLOAD_BASED_FRAG_COUNT, BT_CTLR_DF_PER_ADV_CTE_NUM_MAX)
#define BT_CTLR_ADV_AUX_SET CONFIG_BT_CTLR_ADV_AUX_SET
#if defined(CONFIG_BT_CTLR_ADV_PERIODIC)
#define BT_CTLR_ADV_SYNC_SET CONFIG_BT_CTLR_ADV_SYNC_SET
Expand Down Expand Up @@ -493,13 +494,36 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu,
uint8_t pdu_idx;
void *p;

if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &pdu_free_idx)) {
return NULL;
}

pdu_idx = first;
p = pdu->pdu[pdu_idx];
ed = pdu->extra_data[pdu_idx];

do {
void *next;

/* Store partial list in current data index if there is
* no free slot in mfifo. It can be released on next
* switch attempt (on next event).
*/
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &pdu_free_idx)) {
pdu->pdu[pdu_idx] = p;
return NULL;
}

#if defined(CONFIG_BT_CTLR_ADV_PDU_LINK)
next = lll_adv_pdu_linked_next_get(p);
#else
next = NULL;
#endif

MFIFO_BY_IDX_ENQUEUE(pdu_free, pdu_free_idx, p);
k_sem_give(&sem_pdu_free);

p = next;
} while (p);

pdu->pdu[pdu_idx] = NULL;

if (ed && (!MFIFO_ENQUEUE_IDX_GET(extra_data_free,
&ed_free_idx))) {
/* No pdu_free_idx clean up is required, sobsequent
Expand All @@ -516,12 +540,8 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu,
pdu->first = first;
*is_modified = 1U;

p = pdu->pdu[pdu_idx];
pdu->pdu[pdu_idx] = NULL;

MFIFO_BY_IDX_ENQUEUE(pdu_free, pdu_free_idx, p);
k_sem_give(&sem_pdu_free);

if (ed) {
pdu->extra_data[pdu_idx] = NULL;

Expand Down
7 changes: 7 additions & 0 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ static inline struct pdu_adv *lll_adv_sync_data_peek(struct lll_adv_sync *lll,

return (void *)lll->data.pdu[last];
}

#if defined(CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY)
static inline void *lll_adv_sync_extra_data_peek(struct lll_adv_sync *lll)
{
return lll->data.extra_data[lll->data.last];
}
#endif /* CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY */
#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
#endif /* CONFIG_BT_CTLR_ADV_EXT */

Expand Down
Loading