Skip to content

Commit

Permalink
Wrap dirty IRQ flag cleanup for v307 into a conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Nov 22, 2023
1 parent f86c14a commit 82916a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -9292,8 +9292,9 @@ __attribute__((interrupt())) // For RISCV CH32V307, which share the same MAC
#endif
void ETH_IRQHandler(void);
void ETH_IRQHandler(void) {
if (ETH->DMASR & MG_BIT(6)) { // Frame received, loop
for (uint32_t i = 0; i < 10; i++) { // read as they arrive but not forever
if (ETH->DMASR & MG_BIT(6)) { // Frame received, loop
ETH->DMASR = MG_BIT(16) | MG_BIT(6); // Clear flag
for (uint32_t i = 0; i < 10; i++) { // read as they arrive but not forever
if (s_rxdesc[s_rxno][0] & MG_BIT(31)) break; // exit when done
if (((s_rxdesc[s_rxno][0] & (MG_BIT(8) | MG_BIT(9))) ==
(MG_BIT(8) | MG_BIT(9))) &&
Expand All @@ -9307,7 +9308,11 @@ void ETH_IRQHandler(void) {
if (++s_rxno >= ETH_DESC_CNT) s_rxno = 0;
}
}
ETH->DMASR = ~0; // Clear flags
#ifdef __riscv
ETH->DMASR = ~0; // TODO: do more fine-grained flag cleanup
#else
ETH->DMASR = MG_BIT(7); // Clear possible RBUS while processing
#endif
ETH->DMARPDR = 0; // and resume RX
}

Expand Down
11 changes: 8 additions & 3 deletions src/drivers/stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ __attribute__((interrupt())) // For RISCV CH32V307, which share the same MAC
#endif
void ETH_IRQHandler(void);
void ETH_IRQHandler(void) {
if (ETH->DMASR & MG_BIT(6)) { // Frame received, loop
for (uint32_t i = 0; i < 10; i++) { // read as they arrive but not forever
if (ETH->DMASR & MG_BIT(6)) { // Frame received, loop
ETH->DMASR = MG_BIT(16) | MG_BIT(6); // Clear flag
for (uint32_t i = 0; i < 10; i++) { // read as they arrive but not forever
if (s_rxdesc[s_rxno][0] & MG_BIT(31)) break; // exit when done
if (((s_rxdesc[s_rxno][0] & (MG_BIT(8) | MG_BIT(9))) ==
(MG_BIT(8) | MG_BIT(9))) &&
Expand All @@ -215,7 +216,11 @@ void ETH_IRQHandler(void) {
if (++s_rxno >= ETH_DESC_CNT) s_rxno = 0;
}
}
ETH->DMASR = ~0; // Clear flags
#ifdef __riscv
ETH->DMASR = ~0; // TODO: do more fine-grained flag cleanup
#else
ETH->DMASR = MG_BIT(7); // Clear possible RBUS while processing
#endif
ETH->DMARPDR = 0; // and resume RX
}

Expand Down

0 comments on commit 82916a1

Please sign in to comment.