Skip to content

Commit 69788c3

Browse files
committed
complete_cb now called after the final frame has been sent
1 parent 0a81a92 commit 69788c3

File tree

7 files changed

+56
-83
lines changed

7 files changed

+56
-83
lines changed

lib/twr_ds/src/twr_ds.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ static bool
187187
rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
188188
{
189189
struct uwb_rng_txd txd;
190-
struct uwb_mac_interface * cbs_i;
191190
if (inst->fctrl != FCNTL_IEEE_RANGE_16)
192191
return false;
193192

@@ -337,20 +336,15 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
337336
uwb_rng_calc_rel_tx(rng, &txd, &g_config, inst->rxtimestamp, inst->frame_len);
338337
uwb_set_delay_start(inst, txd.response_tx_delay);
339338

340-
if (uwb_start_tx(inst).start_tx_error){
339+
if (uwb_start_tx(inst).start_tx_error) {
341340
STATS_INC(g_twr_ds_stat, start_tx_error);
342-
}
343-
else{
341+
dpl_sem_release(&rng->sem);
342+
rng_issue_complete(inst);
343+
} else {
344344
STATS_INC(g_twr_ds_stat, complete);
345+
rng->control.complete_after_tx = 1;
345346
}
346347

347-
dpl_sem_release(&rng->sem);
348-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
349-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
350-
if (cbs_i != NULL && cbs_i->complete_cb)
351-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
352-
}
353-
}
354348
break;
355349
}
356350
case UWB_DATA_CODE_DS_TWR_FINAL:
@@ -360,12 +354,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
360354

361355
STATS_INC(g_twr_ds_stat, complete);
362356
dpl_sem_release(&rng->sem);
363-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
364-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
365-
if (cbs_i != NULL && cbs_i->complete_cb)
366-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
367-
}
368-
}
357+
rng_issue_complete(inst);
369358
break;
370359
}
371360
default:

lib/twr_ds_ext/src/twr_ds_ext.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,17 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
343343
uwb_rng_calc_rel_tx(rng, &txd, &g_config, inst->rxtimestamp, inst->frame_len);
344344
uwb_set_delay_start(inst, txd.response_tx_delay);
345345

346-
if (uwb_start_tx(inst).start_tx_error) {
347-
STATS_INC(g_twr_ds_ext_stat, tx_error);
348-
}else{
349-
STATS_INC(g_twr_ds_ext_stat, complete);
350-
}
351-
352-
dpl_sem_release(&rng->sem);
353-
354346
/* Remove the remote data so local node doesn't think they've been received */
355347
memcpy(&frame->local, &frame->remote, sizeof(frame->local));
356348
uwb_rng_clear_twr_data(&frame->remote);
357349

358-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
359-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
360-
if (cbs_i!=NULL && cbs_i->complete_cb)
361-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
362-
}
350+
if (uwb_start_tx(inst).start_tx_error) {
351+
STATS_INC(g_twr_ds_ext_stat, tx_error);
352+
dpl_sem_release(&rng->sem);
353+
rng_issue_complete(inst);
354+
}else{
355+
STATS_INC(g_twr_ds_ext_stat, complete);
356+
rng->control.complete_after_tx = 1;
363357
}
364358
break;
365359
}
@@ -370,12 +364,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
370364

371365
STATS_INC(g_twr_ds_ext_stat, complete);
372366
dpl_sem_release(&rng->sem);
373-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
374-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
375-
if (cbs_i!=NULL && cbs_i->complete_cb)
376-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
377-
}
378-
}
367+
rng_issue_complete(inst);
379368
break;
380369
}
381370
default:

lib/twr_ss/src/twr_ss.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ static bool
197197
rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
198198
{
199199
twr_frame_t * frame;
200-
struct uwb_mac_interface * cbs_i;
201200
struct uwb_rng_instance * rng = (struct uwb_rng_instance *)cbs->inst_ptr;
202201
if (inst->fctrl != FCNTL_IEEE_RANGE_16)
203202
return false;
@@ -289,16 +288,11 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
289288

290289
if (uwb_start_tx(inst).start_tx_error) {
291290
SS_STATS_INC(tx_error);
291+
dpl_sem_release(&rng->sem);
292+
rng_issue_complete(inst);
292293
} else {
293294
SS_STATS_INC(complete);
294-
}
295-
296-
dpl_sem_release(&rng->sem);
297-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
298-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
299-
if (cbs_i != NULL && cbs_i->complete_cb)
300-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
301-
}
295+
rng->control.complete_after_tx = 1;
302296
}
303297
break;
304298
}
@@ -312,12 +306,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
312306

313307
SS_STATS_INC(complete);
314308
dpl_sem_release(&rng->sem);
315-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
316-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
317-
if (cbs_i != NULL && cbs_i->complete_cb)
318-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
319-
}
320-
}
309+
rng_issue_complete(inst);
321310
break;
322311
}
323312
default:

lib/twr_ss_ack/src/twr_ss_ack.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ static bool
216216
rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
217217
{
218218
twr_frame_t * frame;
219-
struct uwb_mac_interface * cbs_i;
220219
if (inst->fctrl != FCNTL_IEEE_RANGE_16 &&
221220
inst->fctrl != (FCNTL_IEEE_RANGE_16|UWB_FCTRL_ACK_REQUESTED) &&
222221
inst->fctrl != UWB_FCTRL_FRAME_TYPE_ACK) {
@@ -316,20 +315,15 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
316315
uwb_write_tx(inst, frame->array, 0, sizeof(twr_frame_final_t));
317316
uwb_write_tx_fctrl(inst, sizeof(twr_frame_final_t), 0);
318317

319-
if (uwb_start_tx(inst).start_tx_error){
318+
if (uwb_start_tx(inst).start_tx_error) {
320319
SS_STATS_INC(tx_error);
321-
}
322-
else{
320+
dpl_sem_release(&rng->sem);
321+
rng_issue_complete(inst);
322+
} else {
323323
SS_STATS_INC(complete);
324+
rng->control.complete_after_tx = 1;
324325
}
325-
326-
dpl_sem_release(&rng->sem);
327-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
328-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
329-
if (cbs_i != NULL && cbs_i->complete_cb)
330-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
331-
}
332-
}
326+
break;
333327
break;
334328
}
335329
case UWB_DATA_CODE_SS_TWR_ACK_FINAL:
@@ -342,12 +336,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
342336

343337
SS_STATS_INC(complete);
344338
dpl_sem_release(&rng->sem);
345-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
346-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
347-
if (cbs_i != NULL && cbs_i->complete_cb)
348-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
349-
}
350-
}
339+
rng_issue_complete(inst);
351340
break;
352341
}
353342
default:

lib/twr_ss_ext/src/twr_ss_ext.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,12 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
285285

286286
if (uwb_start_tx(inst).start_tx_error){
287287
STATS_INC(g_twr_ss_ext_stat, tx_error);
288+
dpl_sem_release(&rng->sem);
289+
rng_issue_complete(inst);
288290
}
289291
else{
290292
STATS_INC(g_twr_ss_ext_stat, complete);
291-
}
292-
293-
dpl_sem_release(&rng->sem);
294-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
295-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
296-
if (cbs_i != NULL && cbs_i->complete_cb)
297-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
298-
}
293+
rng->control.complete_after_tx = 1;
299294
}
300295
break;
301296
}
@@ -308,12 +303,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
308303

309304
STATS_INC(g_twr_ss_ext_stat, complete);
310305
dpl_sem_release(&rng->sem);
311-
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
312-
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
313-
if (cbs_i != NULL && cbs_i->complete_cb)
314-
if(cbs_i->complete_cb(inst, cbs_i)) continue;
315-
}
316-
}
306+
rng_issue_complete(inst);
317307
break;
318308
}
319309
default:

lib/uwb_rng/include/uwb_rng/uwb_rng.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct uwb_rng_config{
7777
//! Range control parameters.
7878
typedef struct _uwb_rng_control_t{
7979
uint16_t delay_start_enabled:1; //!< Set for enabling delayed start
80+
uint16_t complete_after_tx:1; //!< Set by ranging state machine to say that exchange is complete after next tx
8081
}uwb_rng_control_t;
8182

8283
//! Range status parameters
@@ -188,6 +189,7 @@ void uwb_rng_clear_twr_data(struct _twr_data_t *s);
188189
dpl_float64_t uwb_rng_twr_to_tof(struct uwb_rng_instance * rng, uint16_t idx);
189190
dpl_float64_t uwb_rng_tof_to_meters(dpl_float64_t ToF);
190191
void uwb_rng_calc_rel_tx(struct uwb_rng_instance * rng, struct uwb_rng_txd *ret, struct uwb_rng_config *cfg, uint64_t ts, uint16_t rx_data_len);
192+
void rng_issue_complete(struct uwb_dev * inst);
191193

192194
#ifndef __KERNEL__
193195
float uwb_rng_path_loss(float Pt, float G, float fc, float R);

lib/uwb_rng/src/uwb_rng.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,26 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
869869
return false;
870870
}
871871

872+
/**
873+
* @fn rng_issue_complete(struct uwb_dev * inst)
874+
* @brief Calls all complete_cb present in the struct uwb_mac_interface list
875+
*
876+
* @param inst Pointer to struct uwb_dev.
877+
*
878+
* @return void
879+
*/
880+
void
881+
rng_issue_complete(struct uwb_dev * inst)
882+
{
883+
struct uwb_mac_interface * cbs_i;
884+
if(!(SLIST_EMPTY(&inst->interface_cbs))) {
885+
SLIST_FOREACH(cbs_i, &inst->interface_cbs, next) {
886+
if (cbs_i != NULL && cbs_i->complete_cb)
887+
if(cbs_i->complete_cb(inst, cbs_i)) continue;
888+
}
889+
}
890+
}
891+
872892
/**
873893
* @fn tx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
874894
* @brief API for transmission complete callback.
@@ -893,6 +913,11 @@ tx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs)
893913
switch(rng->code) {
894914
case UWB_DATA_CODE_SS_TWR ... UWB_DATA_CODE_DS_TWR_EXT_END:
895915
RNG_STATS_INC(tx_complete);
916+
if (rng->control.complete_after_tx) {
917+
dpl_sem_release(&rng->sem);
918+
rng_issue_complete(inst);
919+
}
920+
rng->control.complete_after_tx = 0;
896921
return true;
897922
break;
898923
default:

0 commit comments

Comments
 (0)