@@ -84,13 +84,13 @@ static inline void ep_set_both_response(uint32_t base, uint8_t ep, uint8_t tx_re
8484//--------------------------------------------------------------------+
8585// Private data structures
8686//--------------------------------------------------------------------+
87- struct usb_xfer {
87+ typedef struct {
8888 bool valid ;
8989 uint8_t * buffer ;
9090 size_t len ;
9191 size_t processed_len ;
9292 size_t max_size ;
93- };
93+ } xfer_ctl_t ;
9494
9595typedef struct {
9696 uint32_t usb_base ;
@@ -99,7 +99,7 @@ typedef struct {
9999 volatile bool ep0_completion_pending ; // EP0 XFER_COMPLETE in event queue, not yet processed
100100 uint8_t pending_addr ; // Address to set in ISR after Set Address status ZLP
101101 bool isochronous [EP_MAX ][2 ]; // [ep][dir]
102- struct usb_xfer xfer [EP_MAX ][2 ]; // [ep][dir]
102+ xfer_ctl_t xfer [EP_MAX ][2 ]; // [ep][dir]
103103
104104 // EP0 + EP4 shared buffer: EP0 OUT(64) + EP4 OUT(64) + EP4 IN(64)
105105 TU_ATTR_ALIGNED (4 ) uint8_t ep0_buffer [EP_BUF_SIZE + EP_BUF_SIZE + EP_BUF_SIZE ];
@@ -173,7 +173,7 @@ static uint8_t* ep_dma_buffer(dcd_data_t* d, uint8_t ep) {
173173static void update_in (uint8_t rhport , uint8_t ep , bool force , bool in_isr ) {
174174 dcd_data_t * d = & _dcd_data [rhport ];
175175 uint32_t base = d -> usb_base ;
176- struct usb_xfer * xfer = & d -> xfer [ep ][TUSB_DIR_IN ];
176+ xfer_ctl_t * xfer = & d -> xfer [ep ][TUSB_DIR_IN ];
177177
178178 if (xfer -> valid ) {
179179 if (force || xfer -> len ) {
@@ -218,7 +218,7 @@ static void update_in(uint8_t rhport, uint8_t ep, bool force, bool in_isr) {
218218static void update_out (uint8_t rhport , uint8_t ep , size_t rx_len , bool in_isr ) {
219219 dcd_data_t * d = & _dcd_data [rhport ];
220220 uint32_t base = d -> usb_base ;
221- struct usb_xfer * xfer = & d -> xfer [ep ][TUSB_DIR_OUT ];
221+ xfer_ctl_t * xfer = & d -> xfer [ep ][TUSB_DIR_OUT ];
222222
223223 if (xfer -> valid ) {
224224 size_t len = TU_MIN (xfer -> max_size , TU_MIN (xfer -> len , rx_len ));
@@ -426,16 +426,13 @@ void dcd_int_handler(uint8_t rhport) {
426426}
427427
428428void dcd_int_enable (uint8_t rhport ) {
429- // PFIC enable: USB_IRQn=22, USB2_IRQn=23
430- volatile uint32_t * pfic_ienr = (volatile uint32_t * ) 0xE000E100 ;
431- uint8_t irqn = (rhport == 0 ) ? 22 : 23 ;
432- pfic_ienr [irqn / 32 ] = (1u << (irqn % 32 ));
429+ uint8_t irqn = (rhport == 0 ) ? CH58X_USB_IRQn : CH58X_USB2_IRQn ;
430+ CH58X_PFIC_IENR [irqn / 32 ] = (1u << (irqn % 32 ));
433431}
434432
435433void dcd_int_disable (uint8_t rhport ) {
436- volatile uint32_t * pfic_irer = (volatile uint32_t * ) 0xE000E180 ;
437- uint8_t irqn = (rhport == 0 ) ? 22 : 23 ;
438- pfic_irer [irqn / 32 ] = (1u << (irqn % 32 ));
434+ uint8_t irqn = (rhport == 0 ) ? CH58X_USB_IRQn : CH58X_USB2_IRQn ;
435+ CH58X_PFIC_IRER [irqn / 32 ] = (1u << (irqn % 32 ));
439436 __asm volatile ("fence.i" );
440437}
441438
@@ -496,7 +493,11 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_ep) {
496493 TU_ASSERT (ep < EP_MAX );
497494
498495 d -> isochronous [ep ][dir ] = (desc_ep -> bmAttributes .xfer == TUSB_XFER_ISOCHRONOUS );
499- d -> xfer [ep ][dir ].max_size = tu_edpt_packet_size (desc_ep );
496+ uint16_t max_size = tu_edpt_packet_size (desc_ep );
497+ if (max_size > EP_BUF_SIZE ) {
498+ max_size = EP_BUF_SIZE ;
499+ }
500+ d -> xfer [ep ][dir ].max_size = max_size ;
500501
501502 if (ep != 0 ) {
502503 dcd_int_disable (rhport );
@@ -554,7 +555,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer,
554555 uint8_t dir = tu_edpt_dir (ep_addr );
555556
556557 dcd_data_t * d = & _dcd_data [rhport ];
557- struct usb_xfer * xfer = & d -> xfer [ep ][dir ];
558+ xfer_ctl_t * xfer = & d -> xfer [ep ][dir ];
558559
559560 dcd_int_disable (rhport );
560561
@@ -576,7 +577,6 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer,
576577 if (dir == TUSB_DIR_IN ) {
577578 update_in (rhport , ep , true, is_isr );
578579 } else {
579-
580580 if (d -> isochronous [ep ][TUSB_DIR_OUT ]) {
581581 ep_set_rx_response (d -> usb_base , ep , CH58X_EP_R_RES_TOUT );
582582 } else {
0 commit comments