Bluetooth: controller: radio: Add DF configuration to enable CTE TX

Add set of functions that will make possible to configure
radio Direction Finding Extension to transmit CTE for periodic
advertising.

Some of the new Radio API functions are provided as separate
functions changing the same Radio peripheral registers, e.g.
radio_df_mode_set_aoa, radio_df_mode_set_aod. This is done on
purpose and is related with lack of DFE in nrf52_bsim.
To avoid use of conditionally compiled constants to represent
e.g. CTE mode; separate functions were introduced.
Thanks to that DF unit tests are able to compile successfully
without changes in nrf52_bsim platform. Also if DFE is added
to nrf52_bsim there is no need to change the code until it is
desired.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
This commit is contained in:
Piotr Pryga 2021-01-21 22:54:34 -08:00 committed by Anas Nashif
parent b56a2d1384
commit 515f95382e
3 changed files with 153 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include <sys/util_macro.h>
#include <hal/nrf_radio.h>
#include "radio_nrf5.h"
#include "radio_df.h"
/* @brief Minimum antennas number required if antenna switching is enabled */
@ -134,3 +135,79 @@ uint8_t radio_df_ant_num_get(void)
return 0;
#endif
}
static inline void radio_df_mode_set(uint8_t mode)
{
NRF_RADIO->DFEMODE &= ~RADIO_DFEMODE_DFEOPMODE_Msk;
NRF_RADIO->DFEMODE |= ((mode << RADIO_DFEMODE_DFEOPMODE_Pos)
& RADIO_DFEMODE_DFEOPMODE_Msk);
}
void radio_df_mode_set_aoa(void)
{
radio_df_mode_set(NRF_RADIO_DFE_OP_MODE_AOA);
}
void radio_df_mode_set_aod(void)
{
radio_df_mode_set(NRF_RADIO_DFE_OP_MODE_AOD);
}
void radio_df_cte_inline_set(uint8_t enable)
{
NRF_RADIO->CTEINLINECONF &= ~RADIO_CTEINLINECONF_CTEINLINECTRLEN_Msk;
NRF_RADIO->CTEINLINECONF |= ((enable <<
RADIO_CTEINLINECONF_CTEINLINECTRLEN_Pos)
& RADIO_CTEINLINECONF_CTEINLINECTRLEN_Msk);
}
void radio_df_cte_length_set(uint8_t value)
{
NRF_RADIO->DFECTRL1 &= ~RADIO_DFECTRL1_NUMBEROF8US_Msk;
NRF_RADIO->DFECTRL1 |= ((value << RADIO_DFECTRL1_NUMBEROF8US_Pos)
& RADIO_DFECTRL1_NUMBEROF8US_Msk);
}
void radio_df_ant_switch_pattern_clear(void)
{
NRF_RADIO->CLEARPATTERN = RADIO_CLEARPATTERN_CLEARPATTERN_Clear;
}
static inline void radio_df_ant_switch_spacing_set(uint8_t spacing)
{
NRF_RADIO->DFECTRL1 &= ~RADIO_DFECTRL1_TSWITCHSPACING_Msk;
NRF_RADIO->DFECTRL1 |= ((spacing << RADIO_DFECTRL1_TSWITCHSPACING_Pos)
& RADIO_DFECTRL1_TSWITCHSPACING_Msk);
}
void radio_df_ant_switch_spacing_set_2us(void)
{
radio_df_ant_switch_spacing_set(RADIO_DFECTRL1_TSWITCHSPACING_2us);
}
void radio_df_ant_switch_spacing_set_4us(void)
{
radio_df_ant_switch_spacing_set(RADIO_DFECTRL1_TSWITCHSPACING_4us);
}
void radio_df_ant_switch_pattern_set(uint8_t pattern)
{
NRF_RADIO->SWITCHPATTERN = pattern;
}
void radio_df_reset(void)
{
radio_df_mode_set(RADIO_DFEMODE_DFEOPMODE_Disabled);
radio_df_cte_inline_set(RADIO_CTEINLINECONF_CTEINLINECTRLEN_Disabled);
radio_df_ant_switch_pattern_clear();
}
void radio_switch_complete_and_phy_end_disable(void)
{
NRF_RADIO->SHORTS =
(RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_PHYEND_DISABLE_Msk);
#if !defined(CONFIG_BT_CTLR_TIFS_HW)
hal_radio_sw_switch_disable();
#endif /* !CONFIG_BT_CTLR_TIFS_HW */
}

View File

@ -6,5 +6,30 @@
/* Performs steps related with DF antennae configuration. */
void radio_df_ant_configure(void);
/* Provides number of available antennae for Direction Finding */
/* Provides number of available antennas for Direction Finding. */
uint8_t radio_df_ant_num_get(void);
/* Sets Direction Finding AOA mode. */
void radio_df_mode_set_aoa(void);
/* Sets Direction Finding AOD mode. */
void radio_df_mode_set_aod(void);
/* Sets inline configuration enabled or disabled for receive of CTE. */
void radio_df_cte_inline_set(uint8_t eanble);
/* Sets length of the CTE for transmission. */
void radio_df_cte_length_set(uint8_t value);
/* Clears antenna switch pattern. */
void radio_df_ant_switch_pattern_clear(void);
/* Set antenna switch spacing to 2[us] */
void radio_df_ant_switch_spacing_set_2us(void);
/* Set antenna switch spacing to 4[us] */
void radio_df_ant_switch_spacing_set_4us(void);
/* Set antenna switch pattern. Pay attention, paterns are added to
* 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 pattern);
/* Resets Direction Finding radio configuration */
void radio_df_reset(void);
/* Completes switching and enables shortcut between PHYEND and DISABLE events */
void radio_switch_complete_and_phy_end_disable(void);

View File

@ -15,3 +15,53 @@ uint8_t radio_df_ant_num_get(void)
{
return 0;
}
void radio_df_cte_inline_set(uint8_t enable)
{
}
void radio_df_cte_length_set(uint8_t value)
{
}
void radio_df_ant_switch_pattern_clear(void)
{
}
void radio_df_ant_switch_pattern_set(uint8_t pattern)
{
}
void radio_df_reset(void)
{
}
void radio_switch_complete_and_phy_end_disable(void)
{
}
void radio_df_ant_switch_spacing_set_2us(void)
{
}
void radio_df_ant_switch_spacing_set_4us(void)
{
}
void radio_df_mode_set_aoa(void)
{
}
void radio_df_mode_set_aod(void)
{
}