Skip to content

Commit

Permalink
Merge branch 'bugfix/openthread_rxbuf_using_atomic_variable' into 'ma…
Browse files Browse the repository at this point in the history
…ster'

fix(openthread): using atomic variable for buffer count

See merge request espressif/esp-idf!29392
  • Loading branch information
chshu committed Mar 11, 2024
2 parents 60a2bf6 + 9458456 commit 54e7b73
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/openthread/src/port/esp_openthread_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdatomic.h>
#include "esp_openthread_radio.h"

#include "error.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ typedef struct {
typedef struct {
uint8_t head;
uint8_t tail;
uint8_t used;
atomic_uint_fast8_t used;
} esp_openthread_circular_queue_info_t;

static otRadioFrame s_transmit_frame;
Expand Down Expand Up @@ -216,7 +217,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
otPlatRadioEnergyScanDone(aInstance, s_ed_power);
}

while (s_recv_queue.used) {
while (atomic_load(&s_recv_queue.used)) {
if (s_receive_frame[s_recv_queue.head].mPsdu != NULL) {
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet()) {
Expand All @@ -229,7 +230,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
esp_ieee802154_receive_handle_done(s_receive_frame[s_recv_queue.head].mPsdu - 1);
s_receive_frame[s_recv_queue.head].mPsdu = NULL;
s_recv_queue.head = (s_recv_queue.head + 1) % CONFIG_IEEE802154_RX_BUFFER_SIZE;
s_recv_queue.used--;
atomic_fetch_sub(&s_recv_queue.used, 1);
}
}

Expand Down Expand Up @@ -681,7 +682,7 @@ void IRAM_ATTR esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_i
otRadioFrame ot_frame;
ot_frame.mPsdu = data + 1;

if (s_recv_queue.used == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
if (atomic_load(&s_recv_queue.used) == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
ESP_EARLY_LOGE(OT_PLAT_LOG_TAG, "radio receive buffer full!");
return;
}
Expand All @@ -699,7 +700,7 @@ void IRAM_ATTR esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_i
s_with_security_enh_ack = false;
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
s_recv_queue.tail = (s_recv_queue.tail + 1) % CONFIG_IEEE802154_RX_BUFFER_SIZE;
s_recv_queue.used++;
atomic_fetch_add(&s_recv_queue.used, 1);
set_event(EVENT_RX_DONE);
}

Expand Down

0 comments on commit 54e7b73

Please sign in to comment.