Skip to content

Commit d42bd89

Browse files
cvinayakAnas Nashif
authored andcommitted
Bluetooth: controller: Use single PPI channel for AA capture
Earlier design captured AA twice in the first Rx in a slave connection event and retained one of the capture until end of event to calculate drift. Design updated to use single capture of AA and save the first AA capture in a slave connection event in RAM instead. This frees up a PPI channel in the controller design. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent eebdb3b commit d42bd89

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

subsys/bluetooth/controller/hal/nrf5/radio.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void radio_tmr_status_reset(void)
644644
NRF_PPI->CHENCLR =
645645
(PPI_CHEN_CH0_Msk | PPI_CHEN_CH1_Msk | PPI_CHEN_CH2_Msk |
646646
PPI_CHEN_CH3_Msk | PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk |
647-
PPI_CHEN_CH6_Msk | PPI_CHEN_CH7_Msk);
647+
PPI_CHEN_CH6_Msk);
648648
}
649649

650650
void radio_tmr_tifs_set(u32_t tifs)
@@ -732,14 +732,14 @@ void radio_tmr_stop(void)
732732

733733
void radio_tmr_hcto_configure(u32_t hcto)
734734
{
735-
NRF_TIMER0->CC[2] = hcto;
736-
NRF_TIMER0->EVENTS_COMPARE[2] = 0;
735+
NRF_TIMER0->CC[1] = hcto;
736+
NRF_TIMER0->EVENTS_COMPARE[1] = 0;
737737

738-
NRF_PPI->CH[4].EEP = (u32_t)&(NRF_RADIO->EVENTS_ADDRESS);
739-
NRF_PPI->CH[4].TEP = (u32_t)&(NRF_TIMER0->TASKS_CAPTURE[2]);
740-
NRF_PPI->CH[5].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[2]);
741-
NRF_PPI->CH[5].TEP = (u32_t)&(NRF_RADIO->TASKS_DISABLE);
742-
NRF_PPI->CHENSET = (PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk);
738+
NRF_PPI->CH[3].EEP = (u32_t)&(NRF_RADIO->EVENTS_ADDRESS);
739+
NRF_PPI->CH[3].TEP = (u32_t)&(NRF_TIMER0->TASKS_CAPTURE[1]);
740+
NRF_PPI->CH[4].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[1]);
741+
NRF_PPI->CH[4].TEP = (u32_t)&(NRF_RADIO->TASKS_DISABLE);
742+
NRF_PPI->CHENSET = (PPI_CHEN_CH3_Msk | PPI_CHEN_CH4_Msk);
743743
}
744744

745745
void radio_tmr_aa_capture(void)
@@ -751,21 +751,34 @@ void radio_tmr_aa_capture(void)
751751
NRF_PPI->CHENSET = (PPI_CHEN_CH2_Msk | PPI_CHEN_CH3_Msk);
752752
}
753753

754-
u32_t radio_tmr_ready_get(void)
754+
u32_t radio_tmr_aa_get(void)
755755
{
756-
return NRF_TIMER0->CC[0];
756+
return NRF_TIMER0->CC[1];
757757
}
758758

759-
u32_t radio_tmr_aa_get(void)
759+
static u32_t radio_tmr_aa;
760+
761+
void radio_tmr_aa_save(u32_t aa)
760762
{
761-
return (NRF_TIMER0->CC[1] - NRF_TIMER0->CC[0]);
763+
radio_tmr_aa = aa;
764+
}
765+
766+
u32_t radio_tmr_aa_restore(void)
767+
{
768+
/* NOTE: we dont need to restore for now, but return the saved value. */
769+
return radio_tmr_aa;
770+
}
771+
772+
u32_t radio_tmr_ready_get(void)
773+
{
774+
return NRF_TIMER0->CC[0];
762775
}
763776

764777
void radio_tmr_end_capture(void)
765778
{
766-
NRF_PPI->CH[7].EEP = (u32_t)&(NRF_RADIO->EVENTS_END);
767-
NRF_PPI->CH[7].TEP = (u32_t)&(NRF_TIMER0->TASKS_CAPTURE[2]);
768-
NRF_PPI->CHENSET = PPI_CHEN_CH7_Msk;
779+
NRF_PPI->CH[5].EEP = (u32_t)&(NRF_RADIO->EVENTS_END);
780+
NRF_PPI->CH[5].TEP = (u32_t)&(NRF_TIMER0->TASKS_CAPTURE[2]);
781+
NRF_PPI->CHENSET = PPI_CHEN_CH5_Msk;
769782
}
770783

771784
u32_t radio_tmr_end_get(void)

subsys/bluetooth/controller/hal/radio.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ void radio_tmr_start_us(u8_t trx, u32_t us);
7171
void radio_tmr_stop(void);
7272
void radio_tmr_hcto_configure(u32_t hcto);
7373
void radio_tmr_aa_capture(void);
74-
u32_t radio_tmr_ready_get(void);
7574
u32_t radio_tmr_aa_get(void);
75+
void radio_tmr_aa_save(u32_t aa);
76+
u32_t radio_tmr_aa_restore(void);
77+
u32_t radio_tmr_ready_get(void);
7678
void radio_tmr_end_capture(void);
7779
u32_t radio_tmr_end_get(void);
7880
void radio_tmr_sample(void);

subsys/bluetooth/controller/ll_sw/ctrl.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,11 @@ static inline void isr_rx_conn(u8_t crc_ok, u8_t trx_done,
33743374

33753375
isr_rx_conn_exit:
33763376

3377+
/* Save the AA captured for the first Rx in connection event */
3378+
if (!radio_tmr_aa_restore()) {
3379+
radio_tmr_aa_save(radio_tmr_aa_get());
3380+
}
3381+
33773382
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
33783383
/* get the ISR latency sample */
33793384
sample = radio_tmr_sample_get();
@@ -3707,7 +3712,8 @@ static inline void isr_close_conn(void)
37073712
u32_t preamble_to_addr_us;
37083713

37093714
/* calculate the drift in ticks */
3710-
start_to_address_actual_us = radio_tmr_aa_get();
3715+
start_to_address_actual_us = radio_tmr_aa_restore() -
3716+
radio_tmr_ready_get();
37113717
window_widening_event_us =
37123718
_radio.conn_curr->slave.window_widening_event_us;
37133719
#if defined(CONFIG_BT_CTLR_PHY)
@@ -7828,7 +7834,10 @@ static void event_slave(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
78287834
radio_tmr_start(0, ticks_at_expire +
78297835
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
78307836
_radio.remainder_anchor);
7837+
78317838
radio_tmr_aa_capture();
7839+
radio_tmr_aa_save(0);
7840+
78327841
hcto = remainder_us + RADIO_TICKER_JITTER_US +
78337842
(RADIO_TICKER_JITTER_US << 2) +
78347843
(conn->slave.window_widening_event_us << 1) +
@@ -8003,7 +8012,9 @@ static void event_master(u32_t ticks_at_expire, u32_t remainder, u16_t lazy,
80038012
radio_tmr_start(0, ticks_at_expire +
80048013
TICKER_US_TO_TICKS(RADIO_TICKER_START_PART_US),
80058014
_radio.remainder_anchor);
8015+
80068016
radio_tmr_aa_capture();
8017+
radio_tmr_aa_save(0);
80078018

80088019
hcto = remainder_us + RADIO_TIFS;
80098020
#if defined(CONFIG_BT_CTLR_PHY)

0 commit comments

Comments
 (0)