Skip to content

Commit 79cbe93

Browse files
committed
separate flush tx/rx fifo
1 parent 03cfe90 commit 79cbe93

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/portable/synopsys/dwc2/dcd_dwc2.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,6 @@ static uint16_t _allocated_fifo_words_tx; // TX FIFO size in words (IN EPs)
101101
// SOF enabling flag - required for SOF to not get disabled in ISR when SOF was enabled by
102102
static bool _sof_en;
103103

104-
static inline void fifo_flush(uint8_t rhport)
105-
{
106-
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
107-
108-
// flush all TX fifo and wait for it cleared
109-
dwc2->grstctl = GRSTCTL_TXFFLSH | (0x10u << GRSTCTL_TXFNUM_Pos);
110-
while (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) {}
111-
112-
// flush RX fifo and wait for it cleared
113-
dwc2->grstctl = GRSTCTL_RXFFLSH;
114-
while (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk) {}
115-
}
116-
117104
// Calculate the RX FIFO size according to minimum recommendations from reference manual
118105
// RxFIFO = (5 * number of control endpoints + 8) +
119106
// ((largest USB packet used / 4) + 1 for status information) +
@@ -125,6 +112,17 @@ static inline uint16_t calc_grxfsiz(uint16_t max_ep_size, uint8_t ep_count) {
125112
return 15 + 2 * (max_ep_size / 4) + 2 * ep_count;
126113
}
127114

115+
TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_tx(dwc2_regs_t* dwc2, uint8_t epnum) {
116+
// flush TX fifo and wait for it cleared
117+
dwc2->grstctl = GRSTCTL_TXFFLSH | (epnum << GRSTCTL_TXFNUM_Pos);
118+
while (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) {}
119+
}
120+
TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_rx(dwc2_regs_t* dwc2) {
121+
// flush RX fifo and wait for it cleared
122+
dwc2->grstctl = GRSTCTL_RXFFLSH;
123+
while (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk) {}
124+
}
125+
128126
static bool fifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) {
129127
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
130128
uint8_t const ep_count = _dwc2_controller[rhport].ep_count;
@@ -238,8 +236,7 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) {
238236
}
239237

240238
// Flush the FIFO, and wait until we have confirmed it cleared.
241-
dwc2->grstctl = ((epnum << GRSTCTL_TXFNUM_Pos) | GRSTCTL_TXFFLSH);
242-
while ((dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) != 0) {}
239+
fifo_flush_tx(dwc2, epnum);
243240
} else {
244241
dwc2_epout_t* epout = dwc2->epout;
245242

@@ -283,7 +280,8 @@ static void bus_reset(uint8_t rhport) {
283280
dwc2->epout[n].doepctl |= DOEPCTL_SNAK;
284281
}
285282

286-
fifo_flush(rhport);
283+
fifo_flush_tx(dwc2, 0x10); // all tx fifo
284+
fifo_flush_rx(dwc2);
287285

288286
// 2. Set up interrupt mask
289287
dwc2->daintmsk = TU_BIT(DAINTMSK_OEPM_Pos) | TU_BIT(DAINTMSK_IEPM_Pos);
@@ -591,7 +589,8 @@ void dcd_init(uint8_t rhport) {
591589
// (non zero-length packet), send STALL back and discard.
592590
dwc2->dcfg |= DCFG_NZLSOHSK;
593591

594-
fifo_flush(rhport);
592+
fifo_flush_tx(dwc2, 0x10); // all tx fifo
593+
fifo_flush_rx(dwc2);
595594

596595
// Clear all interrupts
597596
uint32_t int_mask = dwc2->gintsts;
@@ -714,7 +713,8 @@ void dcd_edpt_close_all(uint8_t rhport) {
714713
// reset allocated fifo IN
715714
_allocated_fifo_words_tx = 16;
716715

717-
fifo_flush(rhport);
716+
fifo_flush_tx(dwc2, 0x10); // all tx fifo
717+
fifo_flush_rx(dwc2);
718718
}
719719

720720
bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {

0 commit comments

Comments
 (0)