@@ -56,6 +56,8 @@ static bool esb_initialized = false;
5656static bool esb_paired = false;
5757
5858#define TX_ERROR_THRESHOLD 30
59+ #define TX_ERROR_MAX 100
60+ #define TX_ERROR_CLEAR_RATE 3
5961
6062LOG_MODULE_REGISTER (esb_event , LOG_LEVEL_INF );
6163
@@ -71,18 +73,27 @@ void event_handler(struct esb_evt const *event)
7173 case ESB_EVENT_TX_SUCCESS :
7274 if (!paired_addr [0 ]) // zero, not paired
7375 pairing_packets ++ ; // keep track of pairing state
74- if (tx_errors >= TX_ERROR_THRESHOLD )
76+ if (tx_errors >= TX_ERROR_THRESHOLD && tx_errors < TX_ERROR_THRESHOLD + TX_ERROR_CLEAR_RATE && last_tx_fail == 0 )
77+ {
78+ last_tx_success = 0 ; // reset last_tx_success on threshold reached
7579 last_tx_fail = k_uptime_get ();
76- tx_errors = 0 ;
80+ }
81+ if (tx_errors > TX_ERROR_CLEAR_RATE )
82+ tx_errors -= TX_ERROR_CLEAR_RATE ;
83+ else
84+ tx_errors = 0 ;
7785 LOG_DBG ("TX SUCCESS" );
7886 if (esb_paired )
7987 clocks_stop ();
8088 break ;
8189 case ESB_EVENT_TX_FAILED :
82- if (tx_errors < UINT32_MAX )
90+ if (tx_errors < TX_ERROR_MAX )
8391 tx_errors ++ ;
84- if (tx_errors == TX_ERROR_THRESHOLD ) // consecutive failure to transmit
92+ if (tx_errors == TX_ERROR_THRESHOLD && last_tx_success == 0 ) // consecutive failure to transmit
93+ {
94+ last_tx_fail = 0 ; // reset last_tx_fail on threshold reached
8595 last_tx_success = k_uptime_get ();
96+ }
8697 LOG_DBG ("TX FAILED" );
8798 if (esb_paired )
8899 clocks_stop ();
0 commit comments