Skip to content

Commit e7e19f5

Browse files
committed
[OHCI] Allow more than 16 devices
1 parent ae364b1 commit e7e19f5

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/portable/ohci/ohci.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static ohci_ed_t * const p_ed_head[] =
157157

158158
static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed);
159159
static 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+
613624
static 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

src/portable/ohci/ohci.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ enum {
4545
#define ED_MAX (CFG_TUH_DEVICE_MAX*CFG_TUH_ENDPOINT_MAX)
4646
#define GTD_MAX ED_MAX
4747

48+
// tinyUSB's OHCI implementation caps number of EDs to 8 bits
49+
TU_VERIFY_STATIC (ED_MAX <= 256, "Reduce CFG_TUH_DEVICE_MAX or CFG_TUH_ENDPOINT_MAX");
50+
4851
//--------------------------------------------------------------------+
4952
// OHCI Data Structure
5053
//--------------------------------------------------------------------+
@@ -70,9 +73,8 @@ typedef struct TU_ATTR_ALIGNED(16)
7073
{
7174
// Word 0
7275
uint32_t used : 1;
73-
uint32_t index : 4; // endpoint index the td belongs to, or device address in case of control xfer
74-
uint32_t expected_bytes : 13; // TODO available for hcd
75-
76+
uint32_t index : 8; // endpoint index the gtd belongs to, or device address in case of control xfer
77+
uint32_t : 9; // can be used
7678
uint32_t buffer_rounding : 1;
7779
uint32_t pid : 2;
7880
uint32_t delay_interrupt : 3;
@@ -152,6 +154,12 @@ typedef struct TU_ATTR_ALIGNED(32)
152154

153155
TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" );
154156

157+
typedef struct
158+
{
159+
uint16_t expected_bytes : 13; // can be up to 8192 bytes long so use 13 bits
160+
uint16_t : 3; // can be used
161+
} gtd_extra_data_t;
162+
155163
// structure with member alignment required from large to small
156164
typedef struct TU_ATTR_ALIGNED(256)
157165
{
@@ -164,11 +172,13 @@ typedef struct TU_ATTR_ALIGNED(256)
164172
struct {
165173
ohci_ed_t ed;
166174
ohci_gtd_t gtd;
175+
gtd_extra_data_t gtd_data;
167176
}control[CFG_TUH_DEVICE_MAX+CFG_TUH_HUB+1];
168177

169178
// ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32
170179
ohci_ed_t ed_pool[ED_MAX];
171180
ohci_gtd_t gtd_pool[GTD_MAX];
181+
gtd_extra_data_t gtd_data[GTD_MAX]; // extra data needed by TDs that can't fit in the TD struct
172182

173183
volatile uint16_t frame_number_hi;
174184

0 commit comments

Comments
 (0)