Skip to content

Commit

Permalink
cpu/esp_common: fix of blocking mechanism in FreeRTOS queus
Browse files Browse the repository at this point in the history
When FreeRTOS semaphores, as required by ESP-IDF, are used together with `gnrc_netif`, RIOT may crash if `STATUS_RECEIVE_BLOCKED` is used as a blocking mechanism in the FreeRTOS adaptation layer. The reason for this is that `gnrc_netif` uses thread flags since PR RIOT-OS#16748. If the `gnrc_netif` thread is blocked because of a FreeRTOS semaphore, and is thus in `STATUS_RECEIVE_BLOCKED` state, the `_msg_send` function will cause a crash because it then assumes that `target->wait_data` contains a pointer to a message of type `msg_t`, but by using thread flags it contains the flag mask. This situation can happen if the ESP hardware is used while another thread is sending something timer controlled to the `gnrc_netif` thread.

To solve this problem `STATUS_MUTEX_LOCKED` is used instead of `STATUS_RECEIVE_BLOCKED` and `STATUS_SEND_BLOCKED`
  • Loading branch information
gschorcht committed Aug 23, 2022
1 parent a168c48 commit 2bdccb5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cpu/esp_common/freertos/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ BaseType_t IRAM_ATTR _queue_generic_send(QueueHandle_t xQueue,
else {
/* suspend the calling thread to wait for space in the queue */
thread_t *me = thread_get_active();
sched_set_status(me, STATUS_SEND_BLOCKED);
sched_set_status(me, STATUS_MUTEX_BLOCKED);
/* waiting list is sorted by priority */
thread_add_to_list(&queue->sending, me);

Expand Down Expand Up @@ -408,7 +408,7 @@ BaseType_t IRAM_ATTR _queue_generic_recv (QueueHandle_t xQueue,
else {
/* suspend the calling thread to wait for an item in the queue */
thread_t *me = thread_get_active();
sched_set_status(me, STATUS_RECEIVE_BLOCKED);
sched_set_status(me, STATUS_MUTEX_BLOCKED);
/* waiting list is sorted by priority */
thread_add_to_list(&queue->receiving, me);

Expand Down

0 comments on commit 2bdccb5

Please sign in to comment.