From 82916a1cefbd4db40a5bc958a45383226d088deb Mon Sep 17 00:00:00 2001 From: cpq Date: Wed, 22 Nov 2023 15:41:45 +0000 Subject: [PATCH] Wrap dirty IRQ flag cleanup for v307 into a conditional --- mongoose.c | 11 ++++++++--- src/drivers/stm32.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 86cfaff67c..7de236d9b8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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))) && @@ -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 } diff --git a/src/drivers/stm32.c b/src/drivers/stm32.c index 92715864eb..0576a27c23 100644 --- a/src/drivers/stm32.c +++ b/src/drivers/stm32.c @@ -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))) && @@ -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 }