From 1138133a78fb4e360dca10a71848b21f08499357 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Fri, 31 May 2019 15:23:10 +0800 Subject: [PATCH] spi: fix a possible concurrency issue --- components/driver/spi_slave.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/driver/spi_slave.c b/components/driver/spi_slave.c index f9f792a28..43c0b283d 100644 --- a/components/driver/spi_slave.c +++ b/components/driver/spi_slave.c @@ -361,12 +361,14 @@ static void SPI_SLAVE_ISR_ATTR spi_intr(void *arg) } } + //Disable interrupt before checking to avoid concurrency issue. + esp_intr_disable(host->intr); //Grab next transaction r = xQueueReceiveFromISR(host->trans_queue, &trans, &do_yield); - if (!r) { - //No packet waiting. Disable interrupt. - esp_intr_disable(host->intr); - } else { + if (r) { + //enable the interrupt again if there is packet to send + esp_intr_enable(host->intr); + //We have a transaction. Send it. host->cur_trans = trans;