Skip to content

Commit b32b445

Browse files
committed
esb lenient tx_error checks
1 parent e0da0d4 commit b32b445

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/connection/esb.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ uint32_t led_clock_offset = 0;
4242

4343
uint32_t tx_errors = 0;
4444
int64_t last_tx_success = 0;
45+
int64_t last_tx_fail = 0;
4546

4647
static struct esb_payload rx_payload;
4748
static struct esb_payload tx_payload = ESB_CREATE_PAYLOAD(0,
@@ -54,7 +55,7 @@ static uint8_t paired_addr[8] = {0};
5455
static bool esb_initialized = false;
5556
static bool esb_paired = false;
5657

57-
#define TX_ERROR_THRESHOLD 100
58+
#define TX_ERROR_THRESHOLD 30
5859

5960
LOG_MODULE_REGISTER(esb_event, LOG_LEVEL_INF);
6061

@@ -70,6 +71,8 @@ void event_handler(struct esb_evt const *event)
7071
case ESB_EVENT_TX_SUCCESS:
7172
if (!paired_addr[0]) // zero, not paired
7273
pairing_packets++; // keep track of pairing state
74+
if (tx_errors >= TX_ERROR_THRESHOLD)
75+
last_tx_fail = k_uptime_get();
7376
tx_errors = 0;
7477
LOG_DBG("TX SUCCESS");
7578
if (esb_paired)
@@ -505,7 +508,7 @@ static void esb_thread(void)
505508
sys_request_system_off(false);
506509
}
507510
}
508-
else if (tx_errors == 0 && get_status(SYS_STATUS_CONNECTION_ERROR))
511+
else if (tx_errors < TX_ERROR_THRESHOLD && get_status(SYS_STATUS_CONNECTION_ERROR) && k_uptime_get() - last_tx_fail > 3000) // TODO: there is possibly some race condition causing tx_error to potentially be above zero more often than not, so the check is more lenient; tx_error under threshold and last errors above threshold was not recent
509512
{
510513
set_status(SYS_STATUS_CONNECTION_ERROR, false);
511514
}

0 commit comments

Comments
 (0)