diff --git a/device/esp_tinyusb/tusb_cdc_acm.c b/device/esp_tinyusb/tusb_cdc_acm.c index a69ba6e2..dc646525 100644 --- a/device/esp_tinyusb/tusb_cdc_acm.c +++ b/device/esp_tinyusb/tusb_cdc_acm.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -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 "tusb_cdc_acm.h" #include "cdc.h" @@ -20,9 +21,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; diff --git a/host/class/cdc/usb_host_cdc_acm/cdc_acm_host.c b/host/class/cdc/usb_host_cdc_acm/cdc_acm_host.c index 50d575c7..fe20cf5f 100644 --- a/host/class/cdc/usb_host_cdc_acm/cdc_acm_host.c +++ b/host/class/cdc/usb_host_cdc_acm/cdc_acm_host.c @@ -12,6 +12,7 @@ #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/event_groups.h" +#include "esp_private/critical_section.h" #include "esp_log.h" #include "esp_check.h" #include "esp_system.h" @@ -27,9 +28,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 diff --git a/host/class/hid/usb_host_hid/hid_host.c b/host/class/hid/usb_host_hid/hid_host.c index f1c62106..8b290c41 100644 --- a/host/class/hid/usb_host_hid/hid_host.c +++ b/host/class/hid/usb_host_hid/hid_host.c @@ -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) \ diff --git a/host/class/msc/usb_host_msc/src/msc_host.c b/host/class/msc/usb_host_msc/src/msc_host.c index 20332498..a8f78aaa 100644 --- a/host/class/msc/usb_host_msc/src/msc_host.c +++ b/host/class/msc/usb_host_msc/src/msc_host.c @@ -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" @@ -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 { \ diff --git a/host/class/uac/usb_host_uac/uac_host.c b/host/class/uac/usb_host_uac/uac_host.c index eb3d49a6..ea81f94f 100644 --- a/host/class/uac/usb_host_uac/uac_host.c +++ b/host/class/uac/usb_host_uac/uac_host.c @@ -19,14 +19,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) \ diff --git a/host/class/uvc/usb_host_uvc/src/libusb_adapter.c b/host/class/uvc/usb_host_uvc/src/libusb_adapter.c index 25de0f3e..dcfb7791 100644 --- a/host/class/uvc/usb_host_uvc/src/libusb_adapter.c +++ b/host/class/uvc/usb_host_uvc/src/libusb_adapter.c @@ -15,6 +15,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "esp_private/critical_section.h" #include "esp_log.h" #include "esp_check.h" #include "usb/usb_host.h" @@ -42,8 +43,10 @@ } \ } while(0) -#define UVC_ENTER_CRITICAL() portENTER_CRITICAL(&s_uvc_lock) -#define UVC_EXIT_CRITICAL() portEXIT_CRITICAL(&s_uvc_lock) +// UVC spinlock +DEFINE_CRIT_SECTION_LOCK_STATIC(uvc_lock); +#define UVC_ENTER_CRITICAL() esp_os_enter_critical(&uvc_lock) +#define UVC_EXIT_CRITICAL() esp_os_exit_critical(&uvc_lock) #define COUNT_OF(array) (sizeof(array) / sizeof(array[0])) @@ -71,7 +74,6 @@ typedef struct { STAILQ_HEAD(opened_devs, opened_camera) opened_devices_tailq; } uvc_driver_t; -static portMUX_TYPE s_uvc_lock = portMUX_INITIALIZER_UNLOCKED; static uvc_driver_t *s_uvc_driver; static libuvc_adapter_config_t s_config = {