Skip to content

Commit 96165a1

Browse files
committed
rename HCD_MAX_XFER to CFG_TUH_ENDPOINT_MAX
minor clean up
1 parent eb6b5d1 commit 96165a1

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

src/host/hcd.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
extern "C" {
3636
#endif
3737

38+
//--------------------------------------------------------------------+
39+
// Configuration
40+
//--------------------------------------------------------------------+
41+
42+
#ifndef CFG_TUH_ENDPOINT_MAX
43+
#define CFG_TUH_ENDPOINT_MAX (CFG_TUH_DEVICE_MAX*(CFG_TUH_HUB + CFG_TUH_HID*2 + CFG_TUH_MSC*2 + CFG_TUH_CDC*3))
44+
// #ifdef TUP_HCD_ENDPOINT_MAX
45+
// #define CFG_TUH_ENDPPOINT_MAX TUP_HCD_ENDPOINT_MAX
46+
// #else
47+
// #define
48+
// #endif
49+
#endif
50+
3851
//--------------------------------------------------------------------+
3952
// MACRO CONSTANT TYPEDEF
4053
//--------------------------------------------------------------------+
@@ -81,26 +94,13 @@ typedef struct
8194

8295
} hcd_event_t;
8396

84-
#if CFG_TUH_ENABLED
85-
// Max number of endpoints per device
86-
enum {
87-
// TODO better computation
88-
HCD_MAX_ENDPOINT = CFG_TUH_DEVICE_MAX*(CFG_TUH_HUB + CFG_TUH_HID*2 + CFG_TUH_MSC*2 + CFG_TUH_CDC*3),
89-
HCD_MAX_XFER = HCD_MAX_ENDPOINT*2,
90-
};
91-
92-
//#define HCD_MAX_ENDPOINT 16
93-
//#define HCD_MAX_XFER 16
94-
9597
typedef struct {
9698
uint8_t rhport;
9799
uint8_t hub_addr;
98100
uint8_t hub_port;
99101
uint8_t speed;
100102
} hcd_devtree_info_t;
101103

102-
#endif
103-
104104
//--------------------------------------------------------------------+
105105
// Controller API
106106
//--------------------------------------------------------------------+

src/host/hub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline hub_interface_t* get_itf(uint8_t dev_addr)
5454
return &hub_data[dev_addr-1-CFG_TUH_DEVICE_MAX];
5555
}
5656

57-
#if CFG_TUSB_DEBUG
57+
#if CFG_TUSB_DEBUG >= 2
5858
static char const* const _hub_feature_str[] =
5959
{
6060
[HUB_FEATURE_PORT_CONNECTION ] = "PORT_CONNECTION",

src/portable/ehci/ehci.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858

5959
#define FRAMELIST_SIZE (1024 >> FRAMELIST_SIZE_BIT_VALUE)
6060

61+
#define HCD_MAX_XFER CFG_TUH_ENDPOINT_MAX
62+
6163
typedef struct
6264
{
6365
ehci_link_t period_framelist[FRAMELIST_SIZE];
@@ -73,7 +75,7 @@ typedef struct
7375
ehci_qtd_t qtd;
7476
}control[CFG_TUH_DEVICE_MAX+CFG_TUH_HUB+1];
7577

76-
ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT];
78+
ehci_qhd_t qhd_pool[CFG_TUH_ENDPOINT_MAX];
7779
ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32);
7880

7981
ehci_registers_t* regs;
@@ -189,6 +191,7 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr)
189191
prev = list_next(prev) )
190192
{
191193
// TODO check type for ISO iTD and siTD
194+
// TODO Suppress cast-align warning
192195
#pragma GCC diagnostic push
193196
#pragma GCC diagnostic ignored "-Wcast-align"
194197
ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev);
@@ -477,7 +480,7 @@ static void async_advance_isr(uint8_t rhport)
477480
(void) rhport;
478481

479482
ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
480-
for(uint32_t i = 0; i < HCD_MAX_ENDPOINT; i++)
483+
for(uint32_t i = 0; i < CFG_TUH_ENDPOINT_MAX; i++)
481484
{
482485
if ( qhd_pool[i].removing )
483486
{
@@ -545,7 +548,7 @@ static void period_list_xfer_complete_isr(uint8_t hostid, uint32_t interval_ms)
545548
// TODO abstract max loop guard for period
546549
while( !next_item.terminate &&
547550
!(interval_ms > 1 && period_1ms_addr == tu_align32(next_item.address)) &&
548-
max_loop < (HCD_MAX_ENDPOINT + EHCI_MAX_ITD + EHCI_MAX_SITD)*CFG_TUH_DEVICE_MAX)
551+
max_loop < (CFG_TUH_ENDPOINT_MAX + EHCI_MAX_ITD + EHCI_MAX_SITD)*CFG_TUH_DEVICE_MAX)
549552
{
550553
switch ( next_item.type )
551554
{
@@ -717,7 +720,7 @@ void hcd_int_handler(uint8_t rhport)
717720
//------------- queue head helper -------------//
718721
static inline ehci_qhd_t* qhd_find_free (void)
719722
{
720-
for (uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
723+
for (uint32_t i=0; i<CFG_TUH_ENDPOINT_MAX; i++)
721724
{
722725
if ( !ehci_data.qhd_pool[i].used ) return &ehci_data.qhd_pool[i];
723726
}
@@ -734,7 +737,7 @@ static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr)
734737
{
735738
ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
736739

737-
for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
740+
for(uint32_t i=0; i<CFG_TUH_ENDPOINT_MAX; i++)
738741
{
739742
if ( (qhd_pool[i].dev_addr == dev_addr) &&
740743
ep_addr == tu_edpt_addr(qhd_pool[i].ep_number, qhd_pool[i].pid) )

src/portable/nxp/khci/hcd_khci.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ typedef struct
125125
uint16_t bda[2*2];
126126
};
127127
endpoint_state_t endpoint[2];
128-
pipe_state_t pipe[HCD_MAX_XFER * 2];
128+
pipe_state_t pipe[CFG_TUH_ENDPOINT_MAX * 2];
129129
uint32_t in_progress; /* Bitmap. Each bit indicates that a transfer of the corresponding pipe is in progress */
130130
uint32_t pending; /* Bitmap. Each bit indicates that a transfer of the corresponding pipe will be resume the next frame */
131131
bool need_reset; /* The device has not been reset after connection. */
@@ -142,7 +142,7 @@ int find_pipe(uint8_t dev_addr, uint8_t ep_addr)
142142
{
143143
/* Find the target pipe */
144144
int num;
145-
for (num = 0; num < HCD_MAX_XFER * 2; ++num) {
145+
for (num = 0; num < CFG_TUH_ENDPOINT_MAX * 2; ++num) {
146146
pipe_state_t *p = &_hcd.pipe[num];
147147
if ((p->dev_addr == dev_addr) && (p->ep_addr == ep_addr))
148148
return num;
@@ -463,7 +463,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
463463
const unsigned ie = NVIC_GetEnableIRQ(USB0_IRQn);
464464
NVIC_DisableIRQ(USB0_IRQn);
465465
pipe_state_t *p = &_hcd.pipe[0];
466-
pipe_state_t *end = &_hcd.pipe[HCD_MAX_XFER * 2];
466+
pipe_state_t *end = &_hcd.pipe[CFG_TUH_ENDPOINT_MAX * 2];
467467
for (;p != end; ++p) {
468468
if (p->dev_addr == dev_addr)
469469
tu_memclr(p, sizeof(*p));
@@ -511,7 +511,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
511511
// TU_LOG1("O %u %x\n", dev_addr, ep_addr);
512512
/* Find a free pipe */
513513
pipe_state_t *p = &_hcd.pipe[0];
514-
pipe_state_t *end = &_hcd.pipe[HCD_MAX_XFER * 2];
514+
pipe_state_t *end = &_hcd.pipe[CFG_TUH_ENDPOINT_MAX * 2];
515515
if (dev_addr || ep_addr) {
516516
p += 2;
517517
for (; p < end && (p->dev_addr || p->ep_addr); ++p) ;

src/portable/ohci/ohci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr)
313313

314314
ohci_ed_t* ed_pool = ohci_data.ed_pool;
315315

316-
for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
316+
for(uint32_t i=0; i<CFG_TUH_ENDPOINT_MAX; i++)
317317
{
318318
if ( (ed_pool[i].dev_addr == dev_addr) &&
319319
ep_addr == tu_edpt_addr(ed_pool[i].ep_number, ed_pool[i].pid == PID_IN) )
@@ -329,7 +329,7 @@ static ohci_ed_t * ed_find_free(void)
329329
{
330330
ohci_ed_t* ed_pool = ohci_data.ed_pool;
331331

332-
for(uint8_t i = 0; i < HCD_MAX_ENDPOINT; i++)
332+
for(uint8_t i = 0; i < CFG_TUH_ENDPOINT_MAX; i++)
333333
{
334334
if ( !ed_pool[i].used ) return &ed_pool[i];
335335
}

src/portable/ohci/ohci.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ enum {
4242
OHCI_MAX_ITD = 4
4343
};
4444

45+
#define HCD_MAX_XFER CFG_TUH_ENDPOINT_MAX
46+
4547
//--------------------------------------------------------------------+
4648
// OHCI Data Structure
4749
//--------------------------------------------------------------------+
@@ -162,7 +164,7 @@ typedef struct TU_ATTR_ALIGNED(256)
162164
}control[CFG_TUH_DEVICE_MAX+CFG_TUH_HUB+1];
163165

164166
// ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32
165-
ohci_ed_t ed_pool[HCD_MAX_ENDPOINT];
167+
ohci_ed_t ed_pool[CFG_TUH_ENDPOINT_MAX];
166168
ohci_gtd_t gtd_pool[HCD_MAX_XFER];
167169

168170
volatile uint16_t frame_number_hi;

src/portable/raspberrypi/rp2040/rp2040_usb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void rp2040_usb_init(void)
5858
unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
5959

6060
// Clear any previous state just in case
61+
// TODO Suppress warning array-bounds with gcc11
6162
#pragma GCC diagnostic push
6263
#pragma GCC diagnostic ignored "-Warray-bounds"
6364
memset(usb_hw, 0, sizeof(*usb_hw));

0 commit comments

Comments
 (0)