@@ -147,6 +147,9 @@ static osal_mutex_t _usbh_mutex;
147
147
#define _usbh_mutex NULL
148
148
#endif
149
149
150
+ // Spinlock for interrupt handler
151
+ static OSAL_SPINLOCK_DEF (_usbh_spin , usbh_int_set );
152
+
150
153
// Event queue: usbh_int_set() is used as mutex in OS NONE config
151
154
OSAL_QUEUE_DEF (usbh_int_set , _usbh_qdef , CFG_TUH_TASK_QUEUE_SZ , hcd_event_t );
152
155
static osal_queue_t _usbh_q ;
@@ -424,6 +427,8 @@ bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
424
427
TU_LOG_INT_USBH (sizeof (tu_fifo_t ));
425
428
TU_LOG_INT_USBH (sizeof (tu_edpt_stream_t ));
426
429
430
+ osal_spin_init (& _usbh_spin );
431
+
427
432
// Event queue
428
433
_usbh_q = osal_queue_create (& _usbh_qdef );
429
434
TU_ASSERT (_usbh_q != NULL );
@@ -547,7 +552,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
547
552
// TODO better to have an separated queue for newly attached devices
548
553
if (_usbh_data .enumerating_daddr == TUSB_INDEX_INVALID_8 ) {
549
554
// New device attached and we are ready
550
- TU_LOG1 ("[%u:] USBH Device Attach\r\n" , event .rhport );
555
+ TU_LOG_USBH ("[%u:] USBH Device Attach\r\n" , event .rhport );
551
556
_usbh_data .enumerating_daddr = 0 ; // enumerate new device with address 0
552
557
enum_new_device (& event );
553
558
} else {
@@ -562,7 +567,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
562
567
break ;
563
568
564
569
case HCD_EVENT_DEVICE_REMOVE :
565
- TU_LOG1 ("[%u:%u:%u] USBH DEVICE REMOVED\r\n" , event .rhport , event .connection .hub_addr , event .connection .hub_port );
570
+ TU_LOG_USBH ("[%u:%u:%u] USBH DEVICE REMOVED\r\n" , event .rhport , event .connection .hub_addr , event .connection .hub_port );
566
571
if (_usbh_data .enumerating_daddr == 0 &&
567
572
event .rhport == _usbh_data .dev0_bus .rhport &&
568
573
event .connection .hub_addr == _usbh_data .dev0_bus .hub_addr &&
@@ -579,7 +584,8 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
579
584
uint8_t const epnum = tu_edpt_number (ep_addr );
580
585
uint8_t const ep_dir = (uint8_t ) tu_edpt_dir (ep_addr );
581
586
582
- TU_LOG_USBH ("on EP %02X with %u bytes: %s\r\n" , ep_addr , (unsigned int ) event .xfer_complete .len , tu_str_xfer_result [event .xfer_complete .result ]);
587
+ TU_LOG_USBH ("[:%u] on EP %02X with %u bytes: %s\r\n" ,
588
+ event .dev_addr , ep_addr , (unsigned int ) event .xfer_complete .len , tu_str_xfer_result [event .xfer_complete .result ]);
583
589
584
590
if (event .dev_addr == 0 ) {
585
591
// device 0 only has control endpoint
@@ -618,7 +624,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
618
624
uint8_t drv_id = dev -> ep2drv [epnum ][ep_dir ];
619
625
usbh_class_driver_t const * driver = get_driver (drv_id );
620
626
if (driver ) {
621
- TU_LOG_USBH ("%s xfer callback\r\n" , driver -> name );
627
+ TU_LOG_USBH (" %s xfer callback\r\n" , driver -> name );
622
628
driver -> xfer_cb (event .dev_addr , ep_addr , (xfer_result_t ) event .xfer_complete .result ,
623
629
event .xfer_complete .len );
624
630
} else {
@@ -894,6 +900,14 @@ void usbh_int_set(bool enabled) {
894
900
}
895
901
}
896
902
903
+ void usbh_spin_lock (bool in_isr ) {
904
+ osal_spin_lock (& _usbh_spin , in_isr );
905
+ }
906
+
907
+ void usbh_spin_unlock (bool in_isr ) {
908
+ osal_spin_unlock (& _usbh_spin , in_isr );
909
+ }
910
+
897
911
void usbh_defer_func (osal_task_func_t func , void * param , bool in_isr ) {
898
912
hcd_event_t event = { 0 };
899
913
event .event_id = USBH_EVENT_FUNC_CALL ;
@@ -1463,7 +1477,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
1463
1477
bool retry = (_usbh_data .enumerating_daddr != TUSB_INDEX_INVALID_8 ) && (failed_count < ATTEMPT_COUNT_MAX );
1464
1478
if (retry ) {
1465
1479
tusb_time_delay_ms_api (ATTEMPT_DELAY_MS ); // delay a bit
1466
- TU_LOG1 ("Enumeration attempt %u/%u\r\n" , failed_count + 1 , ATTEMPT_COUNT_MAX );
1480
+ TU_LOG_USBH ("Enumeration attempt %u/%u\r\n" , failed_count + 1 , ATTEMPT_COUNT_MAX );
1467
1481
retry = tuh_control_xfer (xfer );
1468
1482
}
1469
1483
0 commit comments