Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -19,6 +19,7 @@
#include "esp_log.h"
#include "esp_err.h"
#include "esp_private/usb_phy.h"
#include "esp_private/critical_section.h"
//
#include "unity.h"
#include "tinyusb.h"
Expand All @@ -33,7 +34,10 @@ static SemaphoreHandle_t sem_done = NULL;
TaskHandle_t test_task_handles[MULTIPLE_THREADS_TASKS_NUM];

// Unlocked spinlock, ready to use
static portMUX_TYPE _spinlock = portMUX_INITIALIZER_UNLOCKED;
DEFINE_CRIT_SECTION_LOCK_STATIC(multitask_test_lock);
#define TINYUSB_TASK_ENTER_CRITICAL() esp_os_enter_critical(&multitask_test_lock)
#define TINYUSB_TASK_EXIT_CRITICAL() esp_os_exit_critical(&multitask_test_lock)

static volatile int nb_of_success = 0;

static void test_task_install(void *arg)
Expand All @@ -49,9 +53,9 @@ static void test_task_install(void *arg)
if (tinyusb_driver_install(&tusb_cfg) == ESP_OK) {
test_device_wait();
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, tinyusb_driver_uninstall(), "Unable to uninstall driver after install in worker");
taskENTER_CRITICAL(&_spinlock);
TINYUSB_TASK_ENTER_CRITICAL();
nb_of_success++;
taskEXIT_CRITICAL(&_spinlock);
TINYUSB_TASK_EXIT_CRITICAL();
}

// Notify the parent task that the task completed the job
Expand All @@ -68,9 +72,9 @@ static void test_task_uninstall(void *arg)
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (tinyusb_driver_uninstall() == ESP_OK) {
taskENTER_CRITICAL(&_spinlock);
TINYUSB_TASK_ENTER_CRITICAL();
nb_of_success++;
taskEXIT_CRITICAL(&_spinlock);
TINYUSB_TASK_EXIT_CRITICAL();
}

// Notify the parent task that the task completed the job
Expand Down
7 changes: 4 additions & 3 deletions device/esp_tinyusb/tinyusb_cdc_acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_private/critical_section.h"
#include "tusb.h"
#include "tinyusb_cdc_acm.h"
#include "cdc.h"
Expand All @@ -24,9 +25,9 @@
#endif

// CDC-ACM spinlock
static portMUX_TYPE cdc_acm_lock = portMUX_INITIALIZER_UNLOCKED;
#define CDC_ACM_ENTER_CRITICAL() portENTER_CRITICAL(&cdc_acm_lock)
#define CDC_ACM_EXIT_CRITICAL() portEXIT_CRITICAL(&cdc_acm_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(cdc_acm_lock);
#define CDC_ACM_ENTER_CRITICAL() esp_os_enter_critical(&cdc_acm_lock)
#define CDC_ACM_EXIT_CRITICAL() esp_os_exit_critical(&cdc_acm_lock)

typedef struct {
tusb_cdcacm_callback_t callback_rx;
Expand Down
9 changes: 5 additions & 4 deletions device/esp_tinyusb/tinyusb_msc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,6 +11,7 @@
#include "esp_vfs_fat.h"
#include "esp_partition.h"
#include "esp_memory_utils.h"
#include "esp_private/critical_section.h"
#include "soc/soc_caps.h"
#include "sdkconfig.h"
#include "vfs_fat_internal.h"
Expand Down Expand Up @@ -103,9 +104,9 @@ typedef struct {

static tinyusb_msc_driver_t *p_msc_driver;

static portMUX_TYPE msc_lock = portMUX_INITIALIZER_UNLOCKED;
#define MSC_ENTER_CRITICAL() portENTER_CRITICAL(&msc_lock)
#define MSC_EXIT_CRITICAL() portEXIT_CRITICAL(&msc_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(msc_lock);
#define MSC_ENTER_CRITICAL() esp_os_enter_critical(&msc_lock)
#define MSC_EXIT_CRITICAL() esp_os_exit_critical(&msc_lock)

#define MSC_GOTO_ON_FALSE_CRITICAL(cond, err) \
do { \
Expand Down
7 changes: 4 additions & 3 deletions device/esp_tinyusb/tinyusb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_private/critical_section.h"
#include "soc/soc_caps.h"
#include "esp_log.h"
#include "esp_check.h"
Expand All @@ -20,9 +21,9 @@

const static char *TAG = "tinyusb_task";

static portMUX_TYPE tusb_task_lock = portMUX_INITIALIZER_UNLOCKED;
#define TINYUSB_TASK_ENTER_CRITICAL() portENTER_CRITICAL(&tusb_task_lock)
#define TINYUSB_TASK_EXIT_CRITICAL() portEXIT_CRITICAL(&tusb_task_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(tusb_task_lock);
#define TINYUSB_TASK_ENTER_CRITICAL() esp_os_enter_critical(&tusb_task_lock)
#define TINYUSB_TASK_EXIT_CRITICAL() esp_os_exit_critical(&tusb_task_lock)

#define TINYUSB_TASK_CHECK(cond, ret_val) ({ \
if (!(cond)) { \
Expand Down
7 changes: 4 additions & 3 deletions host/class/cdc/usb_host_cdc_acm/cdc_acm_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "esp_private/critical_section.h"
#include "soc/soc_caps.h"
#include "esp_log.h"
#include "esp_check.h"
Expand All @@ -30,9 +31,9 @@ static const char *TAG = "cdc_acm";
#define CDC_ACM_CTRL_TIMEOUT_MS (5000) // Every CDC device should be able to respond to CTRL transfer in 5 seconds

// CDC-ACM spinlock
static portMUX_TYPE cdc_acm_lock = portMUX_INITIALIZER_UNLOCKED;
#define CDC_ACM_ENTER_CRITICAL() portENTER_CRITICAL(&cdc_acm_lock)
#define CDC_ACM_EXIT_CRITICAL() portEXIT_CRITICAL(&cdc_acm_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(cdc_acm_lock);
#define CDC_ACM_ENTER_CRITICAL() esp_os_enter_critical(&cdc_acm_lock)
#define CDC_ACM_EXIT_CRITICAL() esp_os_exit_critical(&cdc_acm_lock)

// CDC-ACM events
#define CDC_ACM_TEARDOWN BIT0
Expand Down
7 changes: 4 additions & 3 deletions host/class/hid/usb_host_hid/hid_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_private/critical_section.h"
#include "usb/usb_host.h"

#include "usb/hid_host.h"
Expand All @@ -25,9 +26,9 @@
#define HID_MAX_REPORT_DESC_LEN 2048u

// HID spinlock
static portMUX_TYPE hid_lock = portMUX_INITIALIZER_UNLOCKED;
#define HID_ENTER_CRITICAL() portENTER_CRITICAL(&hid_lock)
#define HID_EXIT_CRITICAL() portEXIT_CRITICAL(&hid_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(hid_lock);
#define HID_ENTER_CRITICAL() esp_os_enter_critical(&hid_lock)
#define HID_EXIT_CRITICAL() esp_os_exit_critical(&hid_lock)

// HID verification macros
#define HID_GOTO_ON_FALSE_CRITICAL(exp, err) \
Expand Down
7 changes: 4 additions & 3 deletions host/class/msc/usb_host_msc/src/msc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_private/critical_section.h"
#include "usb/usb_host.h"
#include "diskio_usb.h"
#include "msc_common.h"
Expand All @@ -26,9 +27,9 @@
#include "soc/soc_memory_layout.h"

// MSC driver spin lock
static portMUX_TYPE msc_lock = portMUX_INITIALIZER_UNLOCKED;
#define MSC_ENTER_CRITICAL() portENTER_CRITICAL(&msc_lock)
#define MSC_EXIT_CRITICAL() portEXIT_CRITICAL(&msc_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(msc_lock);
#define MSC_ENTER_CRITICAL() esp_os_enter_critical(&msc_lock)
#define MSC_EXIT_CRITICAL() esp_os_exit_critical(&msc_lock)

#define MSC_GOTO_ON_FALSE_CRITICAL(exp, err) \
do { \
Expand Down
7 changes: 4 additions & 3 deletions host/class/uac/usb_host_uac/uac_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/ringbuf.h"
#include "esp_private/critical_section.h"
#include "usb/usb_host.h"
#include "usb/uac_host.h"
#include "usb/usb_types_ch9.h"

// UAC spinlock
static portMUX_TYPE uac_lock = portMUX_INITIALIZER_UNLOCKED;
#define UAC_ENTER_CRITICAL() portENTER_CRITICAL(&uac_lock)
#define UAC_EXIT_CRITICAL() portEXIT_CRITICAL(&uac_lock)
DEFINE_CRIT_SECTION_LOCK_STATIC(uac_lock);
#define UAC_ENTER_CRITICAL() esp_os_enter_critical(&uac_lock)
#define UAC_EXIT_CRITICAL() esp_os_exit_critical(&uac_lock)

// UAC verification macros
#define UAC_GOTO_ON_FALSE_CRITICAL(exp, err) \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,10 +11,12 @@
#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"

// TODO: Fix extern uvc_lock by using dedicated macro IDF-13950
extern portMUX_TYPE uvc_lock;
#define UVC_ENTER_CRITICAL() portENTER_CRITICAL(&uvc_lock)
#define UVC_EXIT_CRITICAL() portEXIT_CRITICAL(&uvc_lock)


#define UVC_ATOMIC_LOAD(x) __atomic_load_n(&x, __ATOMIC_SEQ_CST)
#define UVC_ATOMIC_SET_IF_NULL(x, new_x) ({ \
__typeof__(x) expected = NULL; \
Expand Down
Loading