spi: limit esp32 dma workaround only on esp32

This commit is contained in:
Armando
2022-09-15 18:26:12 +08:00
committed by wanlei
parent c0ba33a99d
commit 9061efd3d1
6 changed files with 37 additions and 18 deletions

View File

@@ -325,11 +325,13 @@ esp_err_t SPI_SLAVE_ATTR spi_slave_transmit(spi_host_device_t host, spi_slave_tr
return ESP_OK;
}
#if CONFIG_IDF_TARGET_ESP32
static void SPI_SLAVE_ISR_ATTR spi_slave_restart_after_dmareset(void *arg)
{
spi_slave_t *host = (spi_slave_t *)arg;
esp_intr_enable(host->intr);
}
#endif //#if CONFIG_IDF_TARGET_ESP32
//This is run in interrupt context and apart from initialization and destruction, this is the only code
//touching the host (=spihost[x]) variable. The rest of the data arrives in queues. That is why there are
@@ -352,18 +354,25 @@ static void SPI_SLAVE_ISR_ATTR spi_intr(void *arg)
spi_slave_hal_store_result(hal);
host->cur_trans->trans_len = spi_slave_hal_get_rcv_bitlen(hal);
#if CONFIG_IDF_TARGET_ESP32
//This workaround is only for esp32
if (spi_slave_hal_dma_need_reset(hal)) {
//On ESP32 and ESP32S2, actual_tx_dma_chan and actual_rx_dma_chan are always same
//On ESP32, actual_tx_dma_chan and actual_rx_dma_chan are always same
spicommon_dmaworkaround_req_reset(host->tx_dma_chan, spi_slave_restart_after_dmareset, host);
}
#endif //#if CONFIG_IDF_TARGET_ESP32
if (host->cfg.post_trans_cb) host->cfg.post_trans_cb(host->cur_trans);
//Okay, transaction is done.
//Return transaction descriptor.
xQueueSendFromISR(host->ret_queue, &host->cur_trans, &do_yield);
host->cur_trans = NULL;
}
#if CONFIG_IDF_TARGET_ESP32
//This workaround is only for esp32
if (use_dma) {
//On ESP32 and ESP32S2, actual_tx_dma_chan and actual_rx_dma_chan are always same
//On ESP32, actual_tx_dma_chan and actual_rx_dma_chan are always same
spicommon_dmaworkaround_idle(host->tx_dma_chan);
if (spicommon_dmaworkaround_reset_in_progress()) {
//We need to wait for the reset to complete. Disable int (will be re-enabled on reset callback) and exit isr.
@@ -372,6 +381,7 @@ static void SPI_SLAVE_ISR_ATTR spi_intr(void *arg)
return;
}
}
#endif //#if CONFIG_IDF_TARGET_ESP32
//Disable interrupt before checking to avoid concurrency issue.
esp_intr_disable(host->intr);
@@ -388,10 +398,13 @@ static void SPI_SLAVE_ISR_ATTR spi_intr(void *arg)
hal->rx_buffer = trans->rx_buffer;
hal->tx_buffer = trans->tx_buffer;
#if CONFIG_IDF_TARGET_ESP32
if (use_dma) {
//On ESP32 and ESP32S2, actual_tx_dma_chan and actual_rx_dma_chan are always same
//This workaround is only for esp32
//On ESP32, actual_tx_dma_chan and actual_rx_dma_chan are always same
spicommon_dmaworkaround_transfer_active(host->tx_dma_chan);
}
#endif //#if CONFIG_IDF_TARGET_ESP32
spi_slave_hal_prepare_data(hal);