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
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
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 @@ -16,9 +17,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,14 +15,15 @@
#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"

// 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
9 changes: 5 additions & 4 deletions host/class/msc/usb_host_msc/src/msc_host.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -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 @@ -20,14 +20,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
12 changes: 7 additions & 5 deletions host/class/uvc/usb_host_uvc/private_include/uvc_critical_priv.h
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-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -9,11 +9,13 @@
#include <stdatomic.h>

#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"
#include "esp_private/critical_section.h"

extern portMUX_TYPE uvc_lock;
#define UVC_ENTER_CRITICAL() portENTER_CRITICAL(&uvc_lock)
#define UVC_EXIT_CRITICAL() portEXIT_CRITICAL(&uvc_lock)
// TODO: Nice to have dedicated critical section macro for declaring extern lock, eg: DECLARE_EXT_CRIT_SECTION_LOCK
extern DECLARE_CRIT_SECTION_LOCK_IN_STRUCT(uvc_lock);

#define UVC_ENTER_CRITICAL() esp_os_enter_critical(&uvc_lock)
#define UVC_EXIT_CRITICAL() esp_os_exit_critical(&uvc_lock)

#define UVC_ATOMIC_LOAD(x) __atomic_load_n(&x, __ATOMIC_SEQ_CST)
#define UVC_ATOMIC_SET_IF_NULL(x, new_x) ({ \
Expand Down
3 changes: 2 additions & 1 deletion host/class/uvc/usb_host_uvc/uvc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "esp_private/critical_section.h"

static const char *TAG = "uvc";

// UVC spinlock
portMUX_TYPE uvc_lock = portMUX_INITIALIZER_UNLOCKED;
DEFINE_CRIT_SECTION_LOCK(uvc_lock);

// UVC driver status
#define UVC_STARTED BIT0 // UVC driver events handling started
Expand Down
Loading