@@ -90,10 +90,9 @@ static const size_t MAX_PACKET_LEN = (
90
90
// Default timeout (millisec) to wait for incoming ESPNow messages (5 minutes).
91
91
#define DEFAULT_RECV_TIMEOUT_MS (5 * 60 * 1000)
92
92
93
- // Number of milliseconds to wait (mp_hal_wait_ms()) in each loop
94
- // while waiting for send or receive packet.
95
- // Needs to be >15ms to permit yield to other tasks.
96
- #define BUSY_WAIT_MS (25)
93
+ // Number of milliseconds to wait for pending responses to sent packets.
94
+ // This is a fallback which should never be reached.
95
+ #define PENDING_RESPONSES_TIMEOUT_MS 100
97
96
98
97
// The data structure for the espnow_singleton.
99
98
typedef struct _esp_espnow_obj_t {
@@ -347,9 +346,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_rec
347
346
// ie. self->tx_responses == self->tx_packets.
348
347
// Return the number of responses where status != ESP_NOW_SEND_SUCCESS.
349
348
static void _wait_for_pending_responses (esp_espnow_obj_t * self ) {
350
- for (int i = 0 ; i < 90 && self -> tx_responses < self -> tx_packets ; i ++ ) {
351
- // Won't yield unless delay > portTICK_PERIOD_MS (10ms)
352
- mp_hal_delay_ms (BUSY_WAIT_MS );
349
+ for (int i = 0 ; i < PENDING_RESPONSES_TIMEOUT_MS ; i ++ ) {
350
+ if (self -> tx_responses >= self -> tx_packets ) {
351
+ return ;
352
+ }
353
+ mp_hal_delay_ms (1 ); // Allow other tasks to run
353
354
}
354
355
// Note: the loop timeout is just a fallback - in normal operation
355
356
// we should never reach that timeout.
0 commit comments