58
58
59
59
#define FRAMELIST_SIZE (1024 >> FRAMELIST_SIZE_BIT_VALUE)
60
60
61
- #define QHD_MAX (CFG_TUH_DEVICE_MAX*CFG_TUH_ENDPOINT_MAX)
61
+ // Total queue head pool. TODO should be user configurable and more optimize memory usage in the future
62
+ #define QHD_MAX (CFG_TUH_DEVICE_MAX*CFG_TUH_ENDPOINT_MAX + CFG_TUH_HUB)
62
63
#define QTD_MAX QHD_MAX
63
64
64
65
typedef struct
@@ -138,17 +139,6 @@ static inline ehci_qtd_t* qtd_control(uint8_t dev_addr)
138
139
static inline ehci_qhd_t * qhd_next (ehci_qhd_t const * p_qhd );
139
140
static inline ehci_qhd_t * qhd_find_free (void );
140
141
static inline ehci_qhd_t * qhd_get_from_addr (uint8_t dev_addr , uint8_t ep_addr );
141
-
142
- // determine if a queue head has bus-related error
143
- static inline bool qhd_has_xact_error (ehci_qhd_t * p_qhd )
144
- {
145
- volatile ehci_qtd_t * qtd_overlay = & p_qhd -> qtd_overlay ;
146
-
147
- // Error count = 0 often occurs when device disconnected
148
- return (qtd_overlay -> err_count == 0 || qtd_overlay -> buffer_err || qtd_overlay -> babble_err || qtd_overlay -> xact_err );
149
- //qtd_overlay->non_hs_period_missed_uframe || qtd_overlay->pingstate_err TODO split transaction error
150
- }
151
-
152
142
static void qhd_init (ehci_qhd_t * p_qhd , uint8_t dev_addr , tusb_desc_endpoint_t const * ep_desc );
153
143
154
144
static inline ehci_qtd_t * qtd_find_free (void );
@@ -392,15 +382,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
392
382
TU_ASSERT (ep_desc -> bmAttributes .xfer != TUSB_XFER_ISOCHRONOUS );
393
383
394
384
//------------- Prepare Queue Head -------------//
395
- ehci_qhd_t * p_qhd ;
396
-
397
- if ( ep_desc -> bEndpointAddress == 0 )
398
- {
399
- p_qhd = qhd_control (dev_addr );
400
- }else
401
- {
402
- p_qhd = qhd_find_free ();
403
- }
385
+ ehci_qhd_t * p_qhd = (ep_desc -> bEndpointAddress == 0 ) ? qhd_control (dev_addr ) : qhd_find_free ();
404
386
TU_ASSERT (p_qhd );
405
387
406
388
qhd_init (p_qhd , dev_addr , ep_desc );
@@ -622,18 +604,23 @@ static void period_list_xfer_complete_isr(uint8_t hostid, uint32_t interval_ms)
622
604
623
605
static void qhd_xfer_error_isr (ehci_qhd_t * p_qhd )
624
606
{
625
- if ( ( p_qhd -> dev_addr != 0 && p_qhd -> qtd_overlay . halted ) || // addr0 cannot be protocol STALL
626
- qhd_has_xact_error ( p_qhd ) )
627
- {
628
- // current qhd has error in transaction
629
- xfer_result_t error_event ;
607
+ volatile ehci_qtd_t * qtd_overlay = & p_qhd -> qtd_overlay ;
608
+
609
+ // TD has error
610
+ if ( qtd_overlay -> halted ) {
611
+ xfer_result_t xfer_result ;
630
612
631
- // no error bits are set, endpoint is halted due to STALL
632
- error_event = qhd_has_xact_error (p_qhd ) ? XFER_RESULT_FAILED : XFER_RESULT_STALLED ;
613
+ if (qtd_overlay -> err_count == 0 || qtd_overlay -> buffer_err || qtd_overlay -> babble_err || qtd_overlay -> xact_err ) {
614
+ // Error count = 0 often occurs when device disconnected, or other bus-related error
615
+ xfer_result = XFER_RESULT_FAILED ;
616
+ }else {
617
+ // no error bits are set, endpoint is halted due to STALL
618
+ xfer_result = XFER_RESULT_STALLED ;
619
+ }
633
620
634
621
p_qhd -> total_xferred_bytes += p_qhd -> p_qtd_list_head -> expected_bytes - p_qhd -> p_qtd_list_head -> total_bytes ;
635
622
636
- // if ( XFER_RESULT_FAILED == error_event ) {
623
+ // if (XFER_RESULT_FAILED == xfer_result ) {
637
624
// TU_BREAKPOINT(); // TODO skip unplugged device
638
625
// }
639
626
@@ -655,7 +642,8 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
655
642
}
656
643
657
644
// call USBH callback
658
- hcd_event_xfer_complete (p_qhd -> dev_addr , tu_edpt_addr (p_qhd -> ep_number , p_qhd -> pid == EHCI_PID_IN ? 1 : 0 ), p_qhd -> total_xferred_bytes , error_event , true);
645
+ uint8_t const ep_addr = tu_edpt_addr (p_qhd -> ep_number , p_qhd -> pid == EHCI_PID_IN ? 1 : 0 );
646
+ hcd_event_xfer_complete (p_qhd -> dev_addr , ep_addr , p_qhd -> total_xferred_bytes , xfer_result , true);
659
647
660
648
p_qhd -> total_xferred_bytes = 0 ;
661
649
}
0 commit comments