Bluetooth: controller: GPIO PA/LNA feature
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
parent
6cfac15c68
commit
b97b9c4fef
4 changed files with 391 additions and 25 deletions
|
@ -50,6 +50,21 @@ void radio_isr_set(radio_isr_fp fp_radio_isr)
|
|||
|
||||
void radio_setup(void)
|
||||
{
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
NRF_GPIO->DIRSET = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_POL_INV)
|
||||
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
|
||||
#else
|
||||
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
|
||||
#endif
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
NRF_GPIO->DIRSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
|
||||
|
||||
radio_gpio_lna_off();
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_NRF52X)
|
||||
struct {
|
||||
u32_t volatile reserved_0[0x5a0 >> 2];
|
||||
|
@ -719,6 +734,38 @@ void radio_tmr_start_us(u8_t trx, u32_t us)
|
|||
NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk;
|
||||
}
|
||||
|
||||
u32_t radio_tmr_start_now(u8_t trx)
|
||||
{
|
||||
u32_t now, start;
|
||||
|
||||
/* Setup PPI for Radio start */
|
||||
NRF_PPI->CH[0].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[0]);
|
||||
NRF_PPI->CH[0].TEP = (trx) ? (u32_t)&(NRF_RADIO->TASKS_TXEN) :
|
||||
(u32_t)&(NRF_RADIO->TASKS_RXEN);
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk;
|
||||
|
||||
/* Capture the current time */
|
||||
NRF_TIMER0->TASKS_CAPTURE[1] = 1;
|
||||
now = NRF_TIMER0->CC[1];
|
||||
start = now;
|
||||
|
||||
/* Setup PPI while determining the latency in doing so */
|
||||
do {
|
||||
/* Set start to be, now plus the determined latency */
|
||||
start = (now << 1) - start;
|
||||
|
||||
/* Setup compare event with min. 1 us offset */
|
||||
NRF_TIMER0->CC[0] = start + 1;
|
||||
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
|
||||
|
||||
/* Capture the current time */
|
||||
NRF_TIMER0->TASKS_CAPTURE[1] = 1;
|
||||
now = NRF_TIMER0->CC[1];
|
||||
} while (now > start);
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
void radio_tmr_stop(void)
|
||||
{
|
||||
NRF_TIMER0->TASKS_STOP = 1;
|
||||
|
@ -796,6 +843,88 @@ u32_t radio_tmr_sample_get(void)
|
|||
return NRF_TIMER0->CC[3];
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN) || \
|
||||
defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
void radio_gpio_pa_setup(void)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN] =
|
||||
(GPIOTE_CONFIG_MODE_Task <<
|
||||
GPIOTE_CONFIG_MODE_Pos) |
|
||||
(CONFIG_BT_CTLR_GPIO_PA_PIN <<
|
||||
GPIOTE_CONFIG_PSEL_Pos) |
|
||||
(GPIOTE_CONFIG_POLARITY_Toggle <<
|
||||
GPIOTE_CONFIG_POLARITY_Pos) |
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_POL_INV)
|
||||
(GPIOTE_CONFIG_OUTINIT_High <<
|
||||
GPIOTE_CONFIG_OUTINIT_Pos);
|
||||
#else
|
||||
(GPIOTE_CONFIG_OUTINIT_Low <<
|
||||
GPIOTE_CONFIG_OUTINIT_Pos);
|
||||
#endif
|
||||
}
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
void radio_gpio_lna_setup(void)
|
||||
{
|
||||
NRF_GPIOTE->CONFIG[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN] =
|
||||
(GPIOTE_CONFIG_MODE_Task <<
|
||||
GPIOTE_CONFIG_MODE_Pos) |
|
||||
(CONFIG_BT_CTLR_GPIO_LNA_PIN <<
|
||||
GPIOTE_CONFIG_PSEL_Pos) |
|
||||
(GPIOTE_CONFIG_POLARITY_Toggle <<
|
||||
GPIOTE_CONFIG_POLARITY_Pos) |
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
|
||||
(GPIOTE_CONFIG_OUTINIT_High <<
|
||||
GPIOTE_CONFIG_OUTINIT_Pos);
|
||||
#else
|
||||
(GPIOTE_CONFIG_OUTINIT_Low <<
|
||||
GPIOTE_CONFIG_OUTINIT_Pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
void radio_gpio_lna_on(void)
|
||||
{
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
|
||||
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
|
||||
#else
|
||||
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
void radio_gpio_lna_off(void)
|
||||
{
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
|
||||
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
|
||||
#else
|
||||
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
|
||||
#endif
|
||||
}
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
void radio_gpio_pa_lna_enable(u32_t trx_us)
|
||||
{
|
||||
NRF_TIMER0->CC[2] = trx_us;
|
||||
NRF_TIMER0->EVENTS_COMPARE[2] = 0;
|
||||
|
||||
NRF_PPI->CH[7].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[2]);
|
||||
NRF_PPI->CH[7].TEP = (u32_t)
|
||||
&(NRF_GPIOTE->TASKS_OUT[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN]);
|
||||
|
||||
NRF_PPI->CH[8].EEP = (u32_t)&(NRF_RADIO->EVENTS_DISABLED);
|
||||
NRF_PPI->CH[8].TEP = (u32_t)
|
||||
&(NRF_GPIOTE->TASKS_OUT[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN]);
|
||||
|
||||
NRF_PPI->CHENSET = PPI_CHEN_CH7_Msk | PPI_CHEN_CH8_Msk;
|
||||
}
|
||||
|
||||
void radio_gpio_pa_lna_disable(void)
|
||||
{
|
||||
NRF_PPI->CHENCLR = PPI_CHEN_CH7_Msk | PPI_CHEN_CH8_Msk;
|
||||
}
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN || CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
static u8_t MALIGN(4) _ccm_scratch[(RADIO_PDU_LEN_MAX - 4) + 16];
|
||||
|
||||
void *radio_ccm_rx_pkt_set(struct ccm *ccm, void *pkt)
|
||||
|
|
|
@ -68,6 +68,7 @@ void radio_tmr_status_reset(void);
|
|||
void radio_tmr_tifs_set(u32_t tifs);
|
||||
u32_t radio_tmr_start(u8_t trx, u32_t ticks_start, u32_t remainder);
|
||||
void radio_tmr_start_us(u8_t trx, u32_t us);
|
||||
u32_t radio_tmr_start_now(u8_t trx);
|
||||
void radio_tmr_stop(void);
|
||||
void radio_tmr_hcto_configure(u32_t hcto);
|
||||
void radio_tmr_aa_capture(void);
|
||||
|
@ -80,6 +81,13 @@ u32_t radio_tmr_end_get(void);
|
|||
void radio_tmr_sample(void);
|
||||
u32_t radio_tmr_sample_get(void);
|
||||
|
||||
void radio_gpio_pa_setup(void);
|
||||
void radio_gpio_lna_setup(void);
|
||||
void radio_gpio_lna_on(void);
|
||||
void radio_gpio_lna_off(void);
|
||||
void radio_gpio_pa_lna_enable(u32_t trx_us);
|
||||
void radio_gpio_pa_lna_disable(void);
|
||||
|
||||
void *radio_ccm_rx_pkt_set(struct ccm *ccm, void *pkt);
|
||||
void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt);
|
||||
u32_t radio_ccm_is_done(void);
|
||||
|
|
|
@ -605,6 +605,10 @@ static inline void isr_radio_state_tx(void)
|
|||
|
||||
radio_tmr_tifs_set(RADIO_TIFS);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_setup();
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
switch (_radio.role) {
|
||||
case ROLE_ADV:
|
||||
radio_switch_complete_and_tx(0, 0, 0, 0);
|
||||
|
@ -636,6 +640,11 @@ static inline void isr_radio_state_tx(void)
|
|||
radio_rssi_measure();
|
||||
#endif /* CONFIG_BT_CTLR_SCAN_REQ_RSSI */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS - 4 -
|
||||
radio_tx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
break;
|
||||
|
||||
case ROLE_SCAN:
|
||||
|
@ -661,6 +670,11 @@ static inline void isr_radio_state_tx(void)
|
|||
radio_tmr_hcto_configure(hcto);
|
||||
radio_rssi_measure();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS - 4 -
|
||||
radio_tx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
break;
|
||||
|
||||
case ROLE_MASTER:
|
||||
|
@ -693,7 +707,7 @@ static inline void isr_radio_state_tx(void)
|
|||
hcto += radio_rx_chain_delay_get(_radio.conn_curr->phy_rx,
|
||||
_radio.conn_curr->phy_flags);
|
||||
hcto += addr_us_get(_radio.conn_curr->phy_rx);
|
||||
hcto -= radio_tx_chain_delay_get(_radio.conn_curr->phy_rx,
|
||||
hcto -= radio_tx_chain_delay_get(_radio.conn_curr->phy_tx,
|
||||
_radio.conn_curr->phy_flags);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
hcto += radio_rx_chain_delay_get(0, 0);
|
||||
|
@ -703,7 +717,22 @@ static inline void isr_radio_state_tx(void)
|
|||
|
||||
radio_tmr_hcto_configure(hcto);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS - 4 -
|
||||
radio_tx_chain_delay_get(
|
||||
_radio.conn_curr->phy_tx,
|
||||
_radio.conn_curr->phy_flags) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS - 4 -
|
||||
radio_tx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR) || \
|
||||
defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_tmr_end_capture();
|
||||
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
|
||||
|
||||
|
@ -879,6 +908,13 @@ static inline u32_t isr_rx_adv(u8_t devmatch_ok, u8_t devmatch_id,
|
|||
radio_pkt_tx_set(&_radio.advertiser.scan_data.
|
||||
data[_radio.advertiser.scan_data.first][0]);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS -
|
||||
radio_rx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* assert if radio packet ptr is not set and radio started tx */
|
||||
LL_ASSERT(!radio_is_ready());
|
||||
|
||||
|
@ -1409,6 +1445,13 @@ static inline u32_t isr_rx_scan(u8_t devmatch_ok, u8_t devmatch_id,
|
|||
|
||||
radio_pkt_tx_set(pdu_adv_tx);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS -
|
||||
radio_rx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* assert if radio packet ptr is not set and radio started tx */
|
||||
LL_ASSERT(!radio_is_ready());
|
||||
|
||||
|
@ -1613,6 +1656,13 @@ static inline u32_t isr_rx_scan(u8_t devmatch_ok, u8_t devmatch_id,
|
|||
/* capture end of Tx-ed PDU, used to calculate HCTO. */
|
||||
radio_tmr_end_capture();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS -
|
||||
radio_rx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* assert if radio packet ptr is not set and radio started tx */
|
||||
LL_ASSERT(!radio_is_ready());
|
||||
|
||||
|
@ -3246,14 +3296,16 @@ static inline void isr_rx_conn(u8_t crc_ok, u8_t trx_done,
|
|||
u8_t crc_close = 0;
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
|
||||
static u8_t s_lmax;
|
||||
static u8_t s_lmin = (u8_t) -1;
|
||||
static u8_t s_min = (u8_t) -1;
|
||||
static u8_t s_lmax;
|
||||
static u8_t s_lprv;
|
||||
static u8_t s_max;
|
||||
static u8_t s_min = (u8_t) -1;
|
||||
static u8_t s_prv;
|
||||
u32_t sample;
|
||||
|
||||
u8_t latency, elapsed, prv;
|
||||
u32_t radio_tmr_end = 0;
|
||||
u32_t sample;
|
||||
u8_t chg = 0;
|
||||
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
|
||||
|
||||
|
@ -3369,6 +3421,30 @@ static inline void isr_rx_conn(u8_t crc_ok, u8_t trx_done,
|
|||
/* setup the radio tx packet buffer */
|
||||
tx_packet_set(_radio.conn_curr, pdu_data_tx);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
|
||||
/* PA enable is overwriting packet end used in ISR profiling, hence
|
||||
* back it up for later use.
|
||||
*/
|
||||
radio_tmr_end = radio_tmr_end_get();
|
||||
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
|
||||
|
||||
radio_gpio_pa_setup();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS -
|
||||
radio_rx_chain_delay_get(
|
||||
_radio.conn_curr->phy_rx,
|
||||
_radio.conn_curr->phy_flags) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
radio_gpio_pa_lna_enable(radio_tmr_end_get() + RADIO_TIFS -
|
||||
radio_rx_chain_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* assert if radio packet ptr is not set and radio started tx */
|
||||
LL_ASSERT(!radio_is_ready());
|
||||
|
||||
|
@ -3439,7 +3515,13 @@ isr_rx_conn_terminate_exit:
|
|||
/* calculate the elapsed time in us since on-air radio packet end
|
||||
* to ISR entry
|
||||
*/
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
latency = sample - radio_tmr_end;
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
ARG_UNUSED(radio_tmr_end);
|
||||
|
||||
latency = sample - radio_tmr_end_get();
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* check changes in min, avg and max of latency */
|
||||
if (latency > s_lmax) {
|
||||
|
@ -3575,11 +3657,24 @@ static inline u32_t isr_close_adv(void)
|
|||
|
||||
if ((_radio.state == STATE_CLOSE) &&
|
||||
(_radio.advertiser.chan_map_current != 0)) {
|
||||
u32_t start_us;
|
||||
|
||||
dont_close = 1;
|
||||
|
||||
adv_setup();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
start_us = radio_tmr_start_now(1);
|
||||
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(start_us +
|
||||
radio_tx_ready_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
ARG_UNUSED(start_us);
|
||||
|
||||
radio_tx_enable();
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* capture end of Tx-ed PDU, used to calculate HCTO. */
|
||||
radio_tmr_end_capture();
|
||||
|
@ -3629,6 +3724,8 @@ static inline u32_t isr_close_scan(void)
|
|||
u32_t dont_close = 0;
|
||||
|
||||
if (_radio.state == STATE_CLOSE) {
|
||||
u32_t start_us;
|
||||
|
||||
dont_close = 1;
|
||||
|
||||
radio_tmr_tifs_set(RADIO_TIFS);
|
||||
|
@ -3645,7 +3742,18 @@ static inline u32_t isr_close_scan(void)
|
|||
#endif /* CONFIG_BT_CTLR_PRIVACY */
|
||||
_radio.state = STATE_RX;
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
start_us = radio_tmr_start_now(0);
|
||||
|
||||
radio_gpio_lna_setup();
|
||||
radio_gpio_pa_lna_enable(start_us +
|
||||
radio_rx_ready_delay_get(0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
ARG_UNUSED(start_us);
|
||||
|
||||
radio_rx_enable();
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
/* capture end of Rx-ed PDU, for initiator to calculate first
|
||||
* master event.
|
||||
|
@ -4073,6 +4181,11 @@ static void isr(void)
|
|||
radio_ar_status_reset();
|
||||
radio_rssi_status_reset();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN) || \
|
||||
defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_pa_lna_disable();
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN || CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
switch (_radio.state) {
|
||||
case STATE_TX:
|
||||
isr_radio_state_tx();
|
||||
|
@ -5670,6 +5783,8 @@ static void adv_setup(void)
|
|||
static void event_adv(u32_t ticks_at_expire, u32_t remainder,
|
||||
u16_t lazy, void *context)
|
||||
{
|
||||
u32_t remainder_us;
|
||||
|
||||
ARG_UNUSED(remainder);
|
||||
ARG_UNUSED(lazy);
|
||||
ARG_UNUSED(context);
|
||||
|
@ -5719,14 +5834,23 @@ static void event_adv(u32_t ticks_at_expire, u32_t remainder,
|
|||
(u8_t *)wl->bdaddr);
|
||||
}
|
||||
|
||||
radio_tmr_start(1,
|
||||
ticks_at_expire +
|
||||
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
|
||||
_radio.remainder_anchor);
|
||||
remainder_us = radio_tmr_start(1,
|
||||
ticks_at_expire +
|
||||
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
|
||||
_radio.remainder_anchor);
|
||||
|
||||
/* capture end of Tx-ed PDU, used to calculate HCTO. */
|
||||
radio_tmr_end_capture();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_tx_ready_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
ARG_UNUSED(remainder_us);
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
#if (defined(CONFIG_BT_CTLR_XTAL_ADVANCED) && \
|
||||
(RADIO_TICKER_PREEMPT_PART_US <= RADIO_TICKER_PREEMPT_PART_MIN_US))
|
||||
/* check if preempt to start has changed */
|
||||
|
@ -6018,6 +6142,7 @@ static void event_scan(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
|||
void *context)
|
||||
{
|
||||
u32_t ticker_status;
|
||||
u32_t remainder_us;
|
||||
|
||||
ARG_UNUSED(remainder);
|
||||
ARG_UNUSED(lazy);
|
||||
|
@ -6077,16 +6202,25 @@ static void event_scan(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
|||
(u8_t *)wl->bdaddr);
|
||||
}
|
||||
|
||||
radio_tmr_start(0,
|
||||
ticks_at_expire +
|
||||
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
|
||||
_radio.remainder_anchor);
|
||||
remainder_us = radio_tmr_start(0,
|
||||
ticks_at_expire +
|
||||
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
|
||||
_radio.remainder_anchor);
|
||||
|
||||
/* capture end of Rx-ed PDU, for initiator to calculate first
|
||||
* master event.
|
||||
*/
|
||||
radio_tmr_end_capture();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_setup();
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_rx_ready_delay_get(0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
ARG_UNUSED(remainder_us);
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
#if (defined(CONFIG_BT_CTLR_XTAL_ADVANCED) && \
|
||||
(RADIO_TICKER_PREEMPT_PART_US <= RADIO_TICKER_PREEMPT_PART_MIN_US))
|
||||
/* check if preempt to start has changed */
|
||||
|
@ -7853,7 +7987,22 @@ static void event_slave(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
|||
|
||||
radio_tmr_hcto_configure(hcto);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_setup();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_rx_ready_delay_get(conn->phy_rx) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_rx_ready_delay_get(0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PROFILE_ISR) || \
|
||||
defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_tmr_end_capture();
|
||||
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
|
||||
|
||||
|
@ -7904,9 +8053,10 @@ static void event_master_prepare(u32_t ticks_at_expire, u32_t remainder,
|
|||
static void event_master(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
||||
void *context)
|
||||
{
|
||||
u8_t data_chan_use = 0;
|
||||
struct pdu_data *pdu_data_tx;
|
||||
struct connection *conn;
|
||||
u8_t data_chan_use = 0;
|
||||
u32_t remainder_us;
|
||||
|
||||
ARG_UNUSED(remainder);
|
||||
ARG_UNUSED(lazy);
|
||||
|
@ -7979,12 +8129,31 @@ static void event_master(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
|||
(conn->supervision_expire && (conn->supervision_expire <= 6)) ||
|
||||
(conn->connect_expire && (conn->connect_expire <= 6))) {
|
||||
#endif
|
||||
radio_tmr_start(1, ticks_at_expire +
|
||||
remainder_us = radio_tmr_start(1,
|
||||
ticks_at_expire +
|
||||
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
|
||||
_radio.remainder_anchor);
|
||||
|
||||
/* capture end of Tx-ed PDU, used to calculate HCTO. */
|
||||
radio_tmr_end_capture();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_tx_ready_delay_get(conn->phy_tx,
|
||||
conn->phy_flags) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_tx_ready_delay_get(0, 0) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
ARG_UNUSED(remainder_us);
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
#if SILENT_CONNECTION
|
||||
/* silent connection! */
|
||||
} else {
|
||||
|
@ -8031,6 +8200,20 @@ static void event_master(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
|
|||
hcto += 256;
|
||||
|
||||
radio_tmr_hcto_configure(hcto);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_setup();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_PHY)
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_rx_ready_delay_get(conn->phy_rx) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_PHY */
|
||||
radio_gpio_pa_lna_enable(remainder_us +
|
||||
radio_rx_ready_delay_get(0) -
|
||||
CONFIG_BT_CTLR_GPIO_LNA_OFFSET);
|
||||
#endif /* !CONFIG_BT_CTLR_PHY */
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
#include <toolchain.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <soc.h>
|
||||
#include <clock_control.h>
|
||||
|
||||
#include "hal/cpu.h"
|
||||
#include "hal/cntr.h"
|
||||
#include "hal/ccm.h"
|
||||
#include "hal/radio.h"
|
||||
|
@ -72,20 +74,25 @@ static const u8_t prbs9[] = {
|
|||
/* TODO: fill correct prbs15 */
|
||||
static const u8_t prbs15[255] = { 0x00, };
|
||||
|
||||
static u8_t tx_req;
|
||||
static u8_t volatile tx_ack;
|
||||
|
||||
static void isr_tx(void)
|
||||
{
|
||||
u8_t trx_done;
|
||||
u32_t l, i, s, t;
|
||||
|
||||
/* Read radio status and events */
|
||||
trx_done = radio_is_done();
|
||||
|
||||
/* Clear radio status and events */
|
||||
radio_status_reset();
|
||||
radio_tmr_status_reset();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_lna_disable();
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
/* Exit if radio disabled */
|
||||
if (!trx_done) {
|
||||
if (((tx_req - tx_ack) & 0x01) == 0) {
|
||||
tx_ack = tx_req;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -108,7 +115,14 @@ static void isr_tx(void)
|
|||
radio_tmr_aa_capture();
|
||||
radio_tmr_end_capture();
|
||||
|
||||
/* TODO: check for probable stall timer capture being set */
|
||||
/* TODO: check for probable stale timer capture being set */
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(t + radio_tx_ready_delay_get(test_phy,
|
||||
test_phy_flags) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
}
|
||||
|
||||
static void isr_rx(void)
|
||||
|
@ -171,6 +185,7 @@ static u32_t init(u8_t chan, u8_t phy, void (*isr)(void))
|
|||
/* Setup Radio in Tx/Rx */
|
||||
/* NOTE: No whitening in test mode. */
|
||||
radio_phy_set(test_phy, test_phy_flags);
|
||||
radio_tmr_tifs_set(150);
|
||||
radio_tx_power_set(0);
|
||||
radio_freq_chan_set((chan << 1) + 2);
|
||||
radio_aa_set((u8_t *)&test_sync_word);
|
||||
|
@ -182,6 +197,7 @@ static u32_t init(u8_t chan, u8_t phy, void (*isr)(void))
|
|||
|
||||
u32_t ll_test_tx(u8_t chan, u8_t len, u8_t type, u8_t phy)
|
||||
{
|
||||
u32_t start_us;
|
||||
u8_t *payload;
|
||||
u8_t *pdu;
|
||||
u32_t err;
|
||||
|
@ -195,6 +211,8 @@ u32_t ll_test_tx(u8_t chan, u8_t len, u8_t type, u8_t phy)
|
|||
return err;
|
||||
}
|
||||
|
||||
tx_req++;
|
||||
|
||||
pdu = radio_pkt_scratch_get();
|
||||
payload = &pdu[2];
|
||||
|
||||
|
@ -237,10 +255,20 @@ u32_t ll_test_tx(u8_t chan, u8_t len, u8_t type, u8_t phy)
|
|||
|
||||
radio_pkt_tx_set(pdu);
|
||||
radio_switch_complete_and_disable();
|
||||
radio_tmr_start(1, cntr_cnt_get() + CNTR_MIN_DELTA, 0);
|
||||
start_us = radio_tmr_start(1, cntr_cnt_get() + CNTR_MIN_DELTA, 0);
|
||||
radio_tmr_aa_capture();
|
||||
radio_tmr_end_capture();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
|
||||
radio_gpio_pa_setup();
|
||||
radio_gpio_pa_lna_enable(start_us +
|
||||
radio_tx_ready_delay_get(test_phy,
|
||||
test_phy_flags) -
|
||||
CONFIG_BT_CTLR_GPIO_PA_OFFSET);
|
||||
#else /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
ARG_UNUSED(start_us);
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_PA_PIN */
|
||||
|
||||
started = true;
|
||||
|
||||
return 0;
|
||||
|
@ -263,6 +291,10 @@ u32_t ll_test_rx(u8_t chan, u8_t phy, u8_t mod_idx)
|
|||
radio_switch_complete_and_rx(test_phy);
|
||||
radio_tmr_start(0, cntr_cnt_get() + CNTR_MIN_DELTA, 0);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_on();
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
started = true;
|
||||
|
||||
return 0;
|
||||
|
@ -271,6 +303,7 @@ u32_t ll_test_rx(u8_t chan, u8_t phy, u8_t mod_idx)
|
|||
u32_t ll_test_end(u16_t *num_rx)
|
||||
{
|
||||
struct device *hf_clock;
|
||||
u8_t ack;
|
||||
|
||||
if (!started) {
|
||||
return 1;
|
||||
|
@ -280,8 +313,17 @@ u32_t ll_test_end(u16_t *num_rx)
|
|||
*num_rx = test_num_rx;
|
||||
test_num_rx = 0;
|
||||
|
||||
/* Disable Radio */
|
||||
radio_disable();
|
||||
/* Disable Radio, if in Rx test */
|
||||
ack = tx_ack;
|
||||
if (tx_req == ack) {
|
||||
radio_disable();
|
||||
} else {
|
||||
/* Wait for Tx to complete */
|
||||
tx_req = ack + 2;
|
||||
while (tx_req != tx_ack) {
|
||||
cpu_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
/* Stop packet timer */
|
||||
radio_tmr_stop();
|
||||
|
@ -293,6 +335,10 @@ u32_t ll_test_end(u16_t *num_rx)
|
|||
/* Stop coarse timer */
|
||||
cntr_stop();
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
|
||||
radio_gpio_lna_off();
|
||||
#endif /* !CONFIG_BT_CTLR_GPIO_LNA_PIN */
|
||||
|
||||
started = false;
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue