Skip to content

Commit b23e795

Browse files
committed
Bluetooth: Controller: Verbose radio is ready assertion
Provide Radio ISR latency in microseconds when asserting due to high ISR latency. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 09451b1 commit b23e795

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,12 @@ void lll_conn_isr_rx(void *param)
396396
#endif /* HAL_RADIO_GPIO_HAVE_PA_PIN */
397397

398398
/* assert if radio packet ptr is not set and radio started tx */
399-
LL_ASSERT(!radio_is_ready());
399+
if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) {
400+
LL_ASSERT_MSG(!radio_is_ready(), "%s: Radio ISR latency: %u", __func__,
401+
lll_prof_latency_get());
402+
} else {
403+
LL_ASSERT(!radio_is_ready());
404+
}
400405

401406
lll_conn_isr_rx_exit:
402407
/* Save the AA captured for the first Rx in connection event */
@@ -504,6 +509,10 @@ void lll_conn_isr_tx(void *param)
504509
struct lll_conn *lll;
505510
uint32_t hcto;
506511

512+
if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) {
513+
lll_prof_latency_capture();
514+
}
515+
507516
/* Clear radio tx status and events */
508517
lll_isr_tx_status_reset();
509518

@@ -573,7 +582,12 @@ void lll_conn_isr_tx(void *param)
573582
lll_conn_rx_pkt_set(lll);
574583

575584
/* assert if radio packet ptr is not set and radio started rx */
576-
LL_ASSERT(!radio_is_ready());
585+
if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) {
586+
LL_ASSERT_MSG(!radio_is_ready(), "%s: Radio ISR latency: %u", __func__,
587+
lll_prof_latency_get());
588+
} else {
589+
LL_ASSERT(!radio_is_ready());
590+
}
577591

578592
#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_TX)
579593
pdu_tx = get_last_tx_pdu(lll);

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lll.h"
2525

2626
static int send(struct node_rx_pdu *rx);
27+
static uint16_t latency_get(void);
2728
static inline void sample(uint32_t *timestamp);
2829
static inline void sample_ticks(uint32_t *timestamp_ticks);
2930
static inline void delta(uint32_t timestamp, uint16_t *cputime);
@@ -108,6 +109,29 @@ void lll_prof_latency_capture(void)
108109
* and generate the profiling event at the end of the ISR.
109110
*/
110111
radio_tmr_sample();
112+
113+
/* Initialize so that if we call lll_prof_latency_get before it is
114+
* set, we can set it.
115+
*/
116+
timestamp_latency = UINT16_MAX;
117+
}
118+
119+
uint16_t lll_prof_latency_get(void)
120+
{
121+
uint16_t latency;
122+
123+
/* We are here before lll_prof_cputime_capture was called */
124+
if (timestamp_latency == UINT16_MAX) {
125+
/* get the ISR latency sample */
126+
timestamp_latency = radio_tmr_sample_get();
127+
}
128+
129+
/* Get the elapsed time in us since on-air radio packet end to ISR
130+
* entry.
131+
*/
132+
latency = latency_get();
133+
134+
return latency;
111135
}
112136

113137
#if defined(HAL_RADIO_GPIO_HAVE_PA_PIN)
@@ -181,14 +205,10 @@ static int send(struct node_rx_pdu *rx)
181205
struct profile *p;
182206
uint8_t chg = 0U;
183207

184-
/* calculate the elapsed time in us since on-air radio packet end
185-
* to ISR entry
208+
/* Get the elapsed time in us since on-air radio packet end to ISR
209+
* entry.
186210
*/
187-
#if defined(HAL_RADIO_GPIO_HAVE_PA_PIN)
188-
latency = timestamp_latency - timestamp_radio_end;
189-
#else /* !HAL_RADIO_GPIO_HAVE_PA_PIN */
190-
latency = timestamp_latency - radio_tmr_end_get();
191-
#endif /* !HAL_RADIO_GPIO_HAVE_PA_PIN */
211+
latency = latency_get();
192212

193213
/* check changes in min, avg and max of latency */
194214
if (latency > latency_max) {
@@ -267,6 +287,22 @@ static int send(struct node_rx_pdu *rx)
267287
return 0;
268288
}
269289

290+
static uint16_t latency_get(void)
291+
{
292+
uint16_t latency;
293+
294+
/* calculate the elapsed time in us since on-air radio packet end
295+
* to ISR entry
296+
*/
297+
#if defined(HAL_RADIO_GPIO_HAVE_PA_PIN)
298+
latency = timestamp_latency - timestamp_radio_end;
299+
#else /* !HAL_RADIO_GPIO_HAVE_PA_PIN */
300+
latency = timestamp_latency - radio_tmr_end_get();
301+
#endif /* !HAL_RADIO_GPIO_HAVE_PA_PIN */
302+
303+
return latency;
304+
}
305+
270306
static inline void sample(uint32_t *timestamp)
271307
{
272308
radio_tmr_sample();

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static inline void lll_prof_exit_ull_low(void) {}
2525
#endif
2626

2727
void lll_prof_latency_capture(void);
28+
uint16_t lll_prof_latency_get(void);
2829
void lll_prof_radio_end_backup(void);
2930
void lll_prof_cputime_capture(void);
3031
void lll_prof_send(void);

0 commit comments

Comments
 (0)