mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
fix race condition where reset event cleaar setup count
This commit is contained in:
parent
0eb0baed19
commit
a5bc0430f7
@ -40,19 +40,15 @@
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef enum {
|
||||
DCD_EVENT_INVALID = 0,
|
||||
DCD_EVENT_BUS_RESET,
|
||||
DCD_EVENT_UNPLUGGED,
|
||||
DCD_EVENT_SOF,
|
||||
DCD_EVENT_SUSPEND, // TODO LPM Sleep L1 support
|
||||
DCD_EVENT_RESUME,
|
||||
|
||||
DCD_EVENT_SETUP_RECEIVED,
|
||||
DCD_EVENT_XFER_COMPLETE,
|
||||
|
||||
// Not an DCD event, just a convenient way to defer ISR function
|
||||
USBD_EVENT_FUNC_CALL,
|
||||
|
||||
DCD_EVENT_INVALID = 0, // 0
|
||||
DCD_EVENT_BUS_RESET, // 1
|
||||
DCD_EVENT_UNPLUGGED, // 2
|
||||
DCD_EVENT_SOF, // 3
|
||||
DCD_EVENT_SUSPEND, // 4 TODO LPM Sleep L1 support
|
||||
DCD_EVENT_RESUME, // 5
|
||||
DCD_EVENT_SETUP_RECEIVED, // 6
|
||||
DCD_EVENT_XFER_COMPLETE, // 7
|
||||
USBD_EVENT_FUNC_CALL, // 8 Not an DCD event, just a convenient way to defer ISR function
|
||||
DCD_EVENT_COUNT
|
||||
} dcd_eventid_t;
|
||||
|
||||
|
@ -120,7 +120,6 @@ typedef struct {
|
||||
};
|
||||
volatile uint8_t cfg_num; // current active configuration (0x00 is not configured)
|
||||
uint8_t speed;
|
||||
volatile uint8_t setup_count;
|
||||
volatile uint8_t sof_consumer;
|
||||
|
||||
uint8_t itf2drv[CFG_TUD_INTERFACE_MAX]; // map interface number to driver (0xff is invalid)
|
||||
@ -131,6 +130,7 @@ typedef struct {
|
||||
}usbd_device_t;
|
||||
|
||||
tu_static usbd_device_t _usbd_dev;
|
||||
static volatile uint8_t _usbd_queued_setup;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver
|
||||
@ -459,6 +459,7 @@ bool tud_init(uint8_t rhport) {
|
||||
TU_LOG_INT(CFG_TUD_LOG_LEVEL, sizeof(tu_edpt_stream_t));
|
||||
|
||||
tu_varclr(&_usbd_dev);
|
||||
_usbd_queued_setup = 0;
|
||||
|
||||
#if OSAL_MUTEX_REQUIRED
|
||||
// Init device mutex
|
||||
@ -594,9 +595,10 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
_usbd_dev.setup_count--;
|
||||
TU_ASSERT(_usbd_queued_setup > 0,);
|
||||
_usbd_queued_setup--;
|
||||
TU_LOG_BUF(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
|
||||
if (_usbd_dev.setup_count) {
|
||||
if (_usbd_queued_setup) {
|
||||
TU_LOG_USBD(" Skipped since there is other SETUP in queue\r\n");
|
||||
break;
|
||||
}
|
||||
@ -1199,7 +1201,8 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr)
|
||||
break;
|
||||
|
||||
case DCD_EVENT_SETUP_RECEIVED:
|
||||
_usbd_dev.setup_count++;
|
||||
// TU_ASSERT(event->setup_received.bRequest != 0,);
|
||||
_usbd_queued_setup++;
|
||||
send = true;
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user