8000 espnow: Remove unecessary 25ms latency on send(). · micropython/micropython@74bb60a · GitHub
[go: up one dir, main page]

Skip to content

Commit 74bb60a

Browse files
committed
espnow: Remove unecessary 25ms latency on send().
Reduce minimum time to wait for acks from sent packets from 25ms to 1ms.
1 parent f01fd27 commit 74bb60a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ports/esp8266/modespnow.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ static const size_t MAX_PACKET_LEN = (
9090
// Default timeout (millisec) to wait for incoming ESPNow messages (5 minutes).
9191
#define DEFAULT_RECV_TIMEOUT_MS (5 * 60 * 1000)
9292

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
9796

9897
// The data structure for the espnow_singleton.
9998
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
347346
// ie. self->tx_responses == self->tx_packets.
348347
// Return the number of responses where status != ESP_NOW_SEND_SUCCESS.
349348
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
353354
}
354355
// Note: the loop timeout is just a fallback - in normal operation
355356
// we should never reach that timeout.

0 commit comments

Comments
 (0)
0