@@ -157,6 +157,7 @@ static ohci_ed_t * const p_ed_head[] =
157157
158158static void ed_list_insert (ohci_ed_t * p_pre , ohci_ed_t * p_ed );
159159static void ed_list_remove_by_addr (ohci_ed_t * p_head , uint8_t dev_addr );
160+ static gtd_extra_data_t * gtd_get_extra_data (ohci_gtd_t const * const gtd );
160161
161162//--------------------------------------------------------------------+
162163// USBH-HCD API
@@ -345,7 +346,7 @@ static void gtd_init(ohci_gtd_t *p_td, uint8_t *data_ptr, uint16_t total_bytes)
345346 tu_memclr (p_td , sizeof (ohci_gtd_t ));
346347
347348 p_td -> used = 1 ;
348- p_td -> expected_bytes = total_bytes ;
349+ gtd_get_extra_data ( p_td ) -> expected_bytes = total_bytes ;
349350
350351 p_td -> buffer_rounding = 1 ; // less than queued length is not a error
351352 p_td -> delay_interrupt = OHCI_INT_ON_COMPLETE_NO ;
@@ -610,6 +611,16 @@ static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd)
610611 }
611612}
612613
614+ static gtd_extra_data_t * gtd_get_extra_data (ohci_gtd_t const * const gtd ) {
615+ if ( gtd_is_control (gtd ) )
616+ {
617+ return & ohci_data .control [((intptr_t )gtd - (intptr_t )& ohci_data .control -> gtd ) / sizeof (ohci_data .control [0 ])].gtd_data ;
618+ }else
619+ {
620+ return & ohci_data .gtd_data [gtd - ohci_data .gtd_pool ];
621+ }
622+ }
623+
613624static inline uint32_t gtd_xfer_byte_left (uint32_t buffer_end , uint32_t current_buffer )
614625{
615626 // 5.2.9 OHCI sample code
@@ -641,8 +652,7 @@ static void done_queue_isr(uint8_t hostid)
641652 if ( (qtd -> delay_interrupt == OHCI_INT_ON_COMPLETE_YES ) || (event != XFER_RESULT_SUCCESS ) )
642653 {
643654 ohci_ed_t * const ed = gtd_get_ed (qtd );
644-
645- uint32_t const xferred_bytes = qtd -> expected_bytes - gtd_xfer_byte_left ((uint32_t ) qtd -> buffer_end , (uint32_t ) qtd -> current_buffer_pointer );
655+ uint32_t const xferred_bytes = gtd_get_extra_data (qtd )-> expected_bytes - gtd_xfer_byte_left ((uint32_t ) qtd -> buffer_end , (uint32_t ) qtd -> current_buffer_pointer );
646656
647657 // NOTE Assuming the current list is BULK and there is no other EDs in the list has queued TDs.
648658 // When there is a error resulting this ED is halted, and this EP still has other queued TD
0 commit comments