Skip to content

Commit 91f4c38

Browse files
cvinayakAnas Nashif
authored andcommitted
Bluetooth: controller: GPIO PA/LNA feature
Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent d2c4dbe commit 91f4c38

File tree

4 files changed

+391
-25
lines changed

4 files changed

+391
-25
lines changed

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

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ void radio_isr_set(radio_isr_fp fp_radio_isr)
5050

5151
void radio_setup(void)
5252
{
53+
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
54+
NRF_GPIO->DIRSET = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
55+
#if defined(CONFIG_BT_CTLR_GPIO_PA_POL_INV)
56+
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
57+
#else
58+
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_PA_PIN);
59+
#endif
60+
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
61+
62+
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
63+
NRF_GPIO->DIRSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
64+
65+
radio_gpio_lna_off();
66+
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
67+
5368
#if defined(CONFIG_SOC_SERIES_NRF52X)
5469
struct {
5570
u32_t volatile reserved_0[0x5a0 >> 2];
@@ -719,6 +734,38 @@ void radio_tmr_start_us(u8_t trx, u32_t us)
719734
NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk;
720735
}
721736

737+
u32_t radio_tmr_start_now(u8_t trx)
738+
{
739+
u32_t now, start;
740+
741+
/* Setup PPI for Radio start */
742+
NRF_PPI->CH[0].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[0]);
743+
NRF_PPI->CH[0].TEP = (trx) ? (u32_t)&(NRF_RADIO->TASKS_TXEN) :
744+
(u32_t)&(NRF_RADIO->TASKS_RXEN);
745+
NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk;
746+
747+
/* Capture the current time */
748+
NRF_TIMER0->TASKS_CAPTURE[1] = 1;
749+
now = NRF_TIMER0->CC[1];
750+
start = now;
751+
752+
/* Setup PPI while determining the latency in doing so */
753+
do {
754+
/* Set start to be, now plus the determined latency */
755+
start = (now << 1) - start;
756+
757+
/* Setup compare event with min. 1 us offset */
758+
NRF_TIMER0->CC[0] = start + 1;
759+
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
760+
761+
/* Capture the current time */
762+
NRF_TIMER0->TASKS_CAPTURE[1] = 1;
763+
now = NRF_TIMER0->CC[1];
764+
} while (now > start);
765+
766+
return start;
767+
}
768+
722769
void radio_tmr_stop(void)
723770
{
724771
NRF_TIMER0->TASKS_STOP = 1;
@@ -796,6 +843,88 @@ u32_t radio_tmr_sample_get(void)
796843
return NRF_TIMER0->CC[3];
797844
}
798845

846+
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN) || \
847+
defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
848+
#if defined(CONFIG_BT_CTLR_GPIO_PA_PIN)
849+
void radio_gpio_pa_setup(void)
850+
{
851+
NRF_GPIOTE->CONFIG[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN] =
852+
(GPIOTE_CONFIG_MODE_Task <<
853+
GPIOTE_CONFIG_MODE_Pos) |
854+
(CONFIG_BT_CTLR_GPIO_PA_PIN <<
855+
GPIOTE_CONFIG_PSEL_Pos) |
856+
(GPIOTE_CONFIG_POLARITY_Toggle <<
857+
GPIOTE_CONFIG_POLARITY_Pos) |
858+
#if defined(CONFIG_BT_CTLR_GPIO_PA_POL_INV)
859+
(GPIOTE_CONFIG_OUTINIT_High <<
860+
GPIOTE_CONFIG_OUTINIT_Pos);
861+
#else
862+
(GPIOTE_CONFIG_OUTINIT_Low <<
863+
GPIOTE_CONFIG_OUTINIT_Pos);
864+
#endif
865+
}
866+
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN */
867+
868+
#if defined(CONFIG_BT_CTLR_GPIO_LNA_PIN)
869+
void radio_gpio_lna_setup(void)
870+
{
871+
NRF_GPIOTE->CONFIG[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN] =
872+
(GPIOTE_CONFIG_MODE_Task <<
873+
GPIOTE_CONFIG_MODE_Pos) |
874+
(CONFIG_BT_CTLR_GPIO_LNA_PIN <<
875+
GPIOTE_CONFIG_PSEL_Pos) |
876+
(GPIOTE_CONFIG_POLARITY_Toggle <<
877+
GPIOTE_CONFIG_POLARITY_Pos) |
878+
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
879+
(GPIOTE_CONFIG_OUTINIT_High <<
880+
GPIOTE_CONFIG_OUTINIT_Pos);
881+
#else
882+
(GPIOTE_CONFIG_OUTINIT_Low <<
883+
GPIOTE_CONFIG_OUTINIT_Pos);
884+
#endif
885+
}
886+
887+
void radio_gpio_lna_on(void)
888+
{
889+
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
890+
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
891+
#else
892+
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
893+
#endif
894+
}
895+
896+
void radio_gpio_lna_off(void)
897+
{
898+
#if defined(CONFIG_BT_CTLR_GPIO_LNA_POL_INV)
899+
NRF_GPIO->OUTSET = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
900+
#else
901+
NRF_GPIO->OUTCLR = BIT(CONFIG_BT_CTLR_GPIO_LNA_PIN);
902+
#endif
903+
}
904+
#endif /* CONFIG_BT_CTLR_GPIO_LNA_PIN */
905+
906+
void radio_gpio_pa_lna_enable(u32_t trx_us)
907+
{
908+
NRF_TIMER0->CC[2] = trx_us;
909+
NRF_TIMER0->EVENTS_COMPARE[2] = 0;
910+
911+
NRF_PPI->CH[7].EEP = (u32_t)&(NRF_TIMER0->EVENTS_COMPARE[2]);
912+
NRF_PPI->CH[7].TEP = (u32_t)
913+
&(NRF_GPIOTE->TASKS_OUT[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN]);
914+
915+
NRF_PPI->CH[8].EEP = (u32_t)&(NRF_RADIO->EVENTS_DISABLED);
916+
NRF_PPI->CH[8].TEP = (u32_t)
917+
&(NRF_GPIOTE->TASKS_OUT[CONFIG_BT_CTLR_PA_LNA_GPIOTE_CHAN]);
918+
919+
NRF_PPI->CHENSET = PPI_CHEN_CH7_Msk | PPI_CHEN_CH8_Msk;
920+
}
921+
922+
void radio_gpio_pa_lna_disable(void)
923+
{
924+
NRF_PPI->CHENCLR = PPI_CHEN_CH7_Msk | PPI_CHEN_CH8_Msk;
925+
}
926+
#endif /* CONFIG_BT_CTLR_GPIO_PA_PIN || CONFIG_BT_CTLR_GPIO_LNA_PIN */
927+
799928
static u8_t MALIGN(4) _ccm_scratch[(RADIO_PDU_LEN_MAX - 4) + 16];
800929

801930
void *radio_ccm_rx_pkt_set(struct ccm *ccm, void *pkt)

subsys/bluetooth/controller/hal/radio.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void radio_tmr_status_reset(void);
6868
void radio_tmr_tifs_set(u32_t tifs);
6969
u32_t radio_tmr_start(u8_t trx, u32_t ticks_start, u32_t remainder);
7070
void radio_tmr_start_us(u8_t trx, u32_t us);
71+
u32_t radio_tmr_start_now(u8_t trx);
7172
void radio_tmr_stop(void);
7273
void radio_tmr_hcto_configure(u32_t hcto);
7374
void radio_tmr_aa_capture(void);
@@ -80,6 +81,13 @@ u32_t radio_tmr_end_get(void);
8081
void radio_tmr_sample(void);
8182
u32_t radio_tmr_sample_get(void);
8283

84+
void radio_gpio_pa_setup(void);
85+
void radio_gpio_lna_setup(void);
86+
void radio_gpio_lna_on(void);
87+
void radio_gpio_lna_off(void);
88+
void radio_gpio_pa_lna_enable(u32_t trx_us);
89+
void radio_gpio_pa_lna_disable(void);
90+
8391
void *radio_ccm_rx_pkt_set(struct ccm *ccm, void *pkt);
8492
void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt);
8593
u32_t radio_ccm_is_done(void);

0 commit comments

Comments
 (0)