|
24 | 24 | #include "lll.h" |
25 | 25 |
|
26 | 26 | static int send(struct node_rx_pdu *rx); |
| 27 | +static uint16_t latency_get(void); |
27 | 28 | static inline void sample(uint32_t *timestamp); |
28 | 29 | static inline void sample_ticks(uint32_t *timestamp_ticks); |
29 | 30 | static inline void delta(uint32_t timestamp, uint16_t *cputime); |
@@ -108,6 +109,29 @@ void lll_prof_latency_capture(void) |
108 | 109 | * and generate the profiling event at the end of the ISR. |
109 | 110 | */ |
110 | 111 | 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; |
111 | 135 | } |
112 | 136 |
|
113 | 137 | #if defined(HAL_RADIO_GPIO_HAVE_PA_PIN) |
@@ -181,14 +205,10 @@ static int send(struct node_rx_pdu *rx) |
181 | 205 | struct profile *p; |
182 | 206 | uint8_t chg = 0U; |
183 | 207 |
|
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. |
186 | 210 | */ |
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(); |
192 | 212 |
|
193 | 213 | /* check changes in min, avg and max of latency */ |
194 | 214 | if (latency > latency_max) { |
@@ -267,6 +287,22 @@ static int send(struct node_rx_pdu *rx) |
267 | 287 | return 0; |
268 | 288 | } |
269 | 289 |
|
| 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 | + |
270 | 306 | static inline void sample(uint32_t *timestamp) |
271 | 307 | { |
272 | 308 | radio_tmr_sample(); |
|
0 commit comments