You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/21 02:23:53 UTC
[incubator-nuttx] 01/02: xtensa/esp32: Clean up esp32_dma_init code
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit bfc551484addf2ad864fa6dfaa98a915d900b92f
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Mar 17 15:10:15 2021 -0300
xtensa/esp32: Clean up esp32_dma_init code
Removed "isrx" parameter whose only purpose is to trigger an assertion
on DEBUG builds. Also performed a minor refactor.
---
arch/xtensa/src/esp32/esp32_dma.c | 42 ++++++++++++++++-----------------
arch/xtensa/src/esp32/esp32_dma.h | 3 +--
arch/xtensa/src/esp32/esp32_spi.c | 4 ++--
arch/xtensa/src/esp32/esp32_spi_slave.c | 6 ++---
4 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/arch/xtensa/src/esp32/esp32_dma.c b/arch/xtensa/src/esp32/esp32_dma.c
index c085753..112e48b 100644
--- a/arch/xtensa/src/esp32/esp32_dma.c
+++ b/arch/xtensa/src/esp32/esp32_dma.c
@@ -36,6 +36,14 @@
#include "esp32_dma.h"
/****************************************************************************
+ * Preprocessor Definitions
+ ****************************************************************************/
+
+#ifndef MIN
+# define MIN(a,b) (a < b ? a : b)
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -51,7 +59,6 @@
* num - DMA descriptions number
* pbuf - RX/TX buffer pointer
* len - RX/TX buffer length
- * isrx - true: RX DMA descriptions. false: TX DMA descriptions
*
* Returned Value:
* Binded pbuf data bytes
@@ -59,47 +66,38 @@
****************************************************************************/
uint32_t esp32_dma_init(struct esp32_dmadesc_s *dmadesc, uint32_t num,
- uint8_t *pbuf, uint32_t len, int isrx)
+ uint8_t *pbuf, uint32_t len)
{
int i;
uint32_t bytes = len;
uint8_t *pdata = pbuf;
- uint32_t n;
+ uint32_t data_len;
- DEBUGASSERT(pbuf && len);
- if (isrx)
- {
- DEBUGASSERT((len & 3) == 0);
- }
+ DEBUGASSERT(dmadesc != NULL);
+ DEBUGASSERT(pbuf != NULL);
+ DEBUGASSERT(len > 0);
for (i = 0; i < num; i++)
{
- if (bytes < ESP32_DMA_DATALEN_MAX)
- {
- n = bytes;
- }
- else
- {
- n = ESP32_DMA_DATALEN_MAX;
- }
+ data_len = MIN(bytes, ESP32_DMA_DATALEN_MAX);
- dmadesc[i].ctrl = (n << DMA_CTRL_DATALEN_S) |
- (n << DMA_CTRL_BUFLEN_S) |
+ dmadesc[i].ctrl = (data_len << DMA_CTRL_DATALEN_S) |
+ (data_len << DMA_CTRL_BUFLEN_S) |
DMA_CTRL_OWN;
dmadesc[i].pbuf = pdata;
dmadesc[i].next = &dmadesc[i + 1];
- bytes -= n;
- if (!bytes)
+ bytes -= data_len;
+ if (bytes == 0)
{
break;
}
- pdata += n;
+ pdata += data_len;
}
dmadesc[i].ctrl |= DMA_CTRL_EOF;
- dmadesc[i].next = NULL;
+ dmadesc[i].next = NULL;
return len - bytes;
}
diff --git a/arch/xtensa/src/esp32/esp32_dma.h b/arch/xtensa/src/esp32/esp32_dma.h
index aec4632..1768da0 100644
--- a/arch/xtensa/src/esp32/esp32_dma.h
+++ b/arch/xtensa/src/esp32/esp32_dma.h
@@ -80,7 +80,6 @@ struct esp32_dmadesc_s
* num - DMA descriptions number
* pbuf - RX/TX buffer pointer
* len - RX/TX buffer length
- * isrx - true: RX DMA descriptions. false: TX DMA descriptions
*
* Returned Value:
* Bind pbuf data bytes
@@ -88,7 +87,7 @@ struct esp32_dmadesc_s
****************************************************************************/
uint32_t esp32_dma_init(struct esp32_dmadesc_s *dmadesc, uint32_t num,
- uint8_t *pbuf, uint32_t len, int isrx);
+ uint8_t *pbuf, uint32_t len);
#ifdef __cplusplus
}
diff --git a/arch/xtensa/src/esp32/esp32_spi.c b/arch/xtensa/src/esp32/esp32_spi.c
index cc67f23..76e4c09 100644
--- a/arch/xtensa/src/esp32/esp32_spi.c
+++ b/arch/xtensa/src/esp32/esp32_spi.c
@@ -917,7 +917,7 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv,
esp32_spi_reset_regbits(priv, SPI_DMA_CONF_OFFSET, SPI_DMA_RESET_MASK);
n = esp32_dma_init(s_dma_txdesc[priv->config->dma_chan - 1],
- SPI_DMADESC_NUM, tp, bytes, 0);
+ SPI_DMADESC_NUM, tp, bytes);
regval = (uintptr_t)s_dma_txdesc[priv->config->dma_chan - 1] &
SPI_OUTLINK_ADDR_V;
@@ -936,7 +936,7 @@ static void esp32_spi_dma_exchange(FAR struct esp32_spi_priv_s *priv,
if (rp)
{
esp32_dma_init(s_dma_rxdesc[priv->config->dma_chan - 1],
- SPI_DMADESC_NUM, rp, bytes, 1);
+ SPI_DMADESC_NUM, rp, bytes);
regval = (uintptr_t)s_dma_rxdesc[priv->config->dma_chan - 1] &
SPI_INLINK_ADDR_V;
diff --git a/arch/xtensa/src/esp32/esp32_spi_slave.c b/arch/xtensa/src/esp32/esp32_spi_slave.c
index bfc958f..e4ffdef 100644
--- a/arch/xtensa/src/esp32/esp32_spi_slave.c
+++ b/arch/xtensa/src/esp32/esp32_spi_slave.c
@@ -649,7 +649,7 @@ static void esp32_spislv_tx(struct esp32_spislv_priv_s *priv)
if (priv->dma_chan)
{
esp32_dma_init(s_tx_desc[priv->dma_chan - 1], SPI_DMADESC_NUM,
- priv->txbuffer, priv->txlen, 0);
+ priv->txbuffer, priv->txlen);
regval = (uint32_t)s_tx_desc[priv->dma_chan - 1] & SPI_OUTLINK_ADDR_V;
esp32_spi_set_reg(priv, SPI_DMA_OUT_LINK_OFFSET,
@@ -725,7 +725,7 @@ static void esp32_spislv_rx(struct esp32_spislv_priv_s *priv)
/* Start to receive next block of data */
esp32_dma_init(s_rx_desc[priv->dma_chan - 1], SPI_DMADESC_NUM,
- priv->rxbuffer + priv->rxlen, tmp, 1);
+ priv->rxbuffer + priv->rxlen, tmp);
regval = (uint32_t)s_rx_desc[priv->dma_chan - 1] &
SPI_INLINK_ADDR_V;
@@ -911,7 +911,7 @@ static void esp32_spislv_initialize(FAR struct spi_sctrlr_s *dev)
SPI_OUTDSCR_BURST_EN_M);
esp32_dma_init(s_rx_desc[priv->dma_chan - 1], SPI_DMADESC_NUM,
- priv->rxbuffer, SPI_SLAVE_BUFSIZE, 1);
+ priv->rxbuffer, SPI_SLAVE_BUFSIZE);
regval = (uint32_t)s_rx_desc[priv->dma_chan - 1] & SPI_INLINK_ADDR_V;
esp32_spi_set_reg(priv, SPI_DMA_IN_LINK_OFFSET,