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/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new e45e932a8a Adds low level operations to start and stop DMA.
e45e932a8a is described below
commit e45e932a8afb905a45fbb7b58329781e889c5754
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Wed Sep 27 14:11:51 2023 -0300
Adds low level operations to start and stop DMA.
---
arch/arm/src/stm32l4/stm32l4_adc.c | 63 +++++++++++++++++++++++++++++++++++---
arch/arm/src/stm32l4/stm32l4_adc.h | 33 +++++++++++++++-----
2 files changed, 84 insertions(+), 12 deletions(-)
diff --git a/arch/arm/src/stm32l4/stm32l4_adc.c
b/arch/arm/src/stm32l4/stm32l4_adc.c
index eb165c5dc6..d438eb241e 100644
--- a/arch/arm/src/stm32l4/stm32l4_adc.c
+++ b/arch/arm/src/stm32l4/stm32l4_adc.c
@@ -328,7 +328,11 @@ static int adc_llops_offset_set(struct
stm32_adc_dev_s *dev,
uint8_t ch, uint8_t i, uint16_t offset);
# ifdef ADC_HAVE_DMA
static int adc_regbufregister(struct stm32_adc_dev_s *dev,
- uint16_t *buffer, uint8_t len);
+ uint16_t *buffer, uint16_t len);
+static void adc_llops_dma_start(struct stm32_adc_dev_s *adc,
+ dma_callback_t callback,
+ uint16_t *buffer, uint16_t len);
+static void adc_llops_dma_stop(struct stm32_adc_dev_s *adc);
# endif
# ifdef ADC_HAVE_EXTCFG
static int adc_llops_extsel_set(struct stm32_adc_dev_s *dev,
@@ -397,9 +401,6 @@ static const struct stm32_adc_ops_s g_adc_llops =
.val_get = adc_llops_regget,
.reg_startconv = adc_llops_startconv,
.offset_set = adc_llops_offset_set,
-# ifdef ADC_HAVE_DMA
- .regbuf_reg = adc_regbufregister,
-# endif
# ifdef ADC_HAVE_INJECTED
.inj_get = adc_llops_injget,
.inj_startconv = adc_llops_inj_startconv,
@@ -409,6 +410,11 @@ static const struct stm32_adc_ops_s g_adc_llops =
# endif
# ifdef ADC_HAVE_JEXTCFG
.jextsel_set = adc_llops_jextsel_set,
+# endif
+# ifdef ADC_HAVE_DMA
+ .regbuf_reg = adc_regbufregister,
+ .dma_start = adc_llops_dma_start,
+ .dma_stop = adc_llops_dma_stop,
# endif
.dump_regs = adc_llops_dumpregs
};
@@ -2520,7 +2526,7 @@ static void adc_llops_jextsel_set(struct stm32_adc_dev_s
*dev,
#ifdef ADC_HAVE_DMA
static int adc_regbufregister(struct stm32_adc_dev_s *dev,
- uint16_t *buffer, uint8_t len)
+ uint16_t *buffer, uint16_t len)
{
struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
@@ -2536,6 +2542,53 @@ static int adc_regbufregister(struct stm32_adc_dev_s
*dev,
return OK;
}
+
+/****************************************************************************
+ * Name: adc_llops_dma_start
+ ****************************************************************************/
+
+static void adc_llops_dma_start(struct stm32_adc_dev_s *adc,
+ dma_callback_t callback,
+ uint16_t *buffer, uint16_t len)
+{
+ struct stm32_dev_s *dev = (struct stm32_dev_s *)adc;
+
+ /* Stop and free DMA if it was started before */
+
+ if (dev->dma != NULL)
+ {
+ stm32l4_dmastop(dev->dma);
+ stm32l4_dmafree(dev->dma);
+ }
+
+ dev->dma = stm32l4_dmachannel(dev->dmachan);
+
+ stm32l4_dmasetup(dev->dma,
+ dev->base + STM32L4_ADC_DR_OFFSET,
+ (uint32_t)buffer,
+ len,
+ ADC_DMA_CONTROL_WORD);
+
+ stm32l4_dmastart(dev->dma, callback, dev, false);
+}
+
+/****************************************************************************
+ * Name: adc_llops_dma_stop
+ ****************************************************************************/
+
+static void adc_llops_dma_stop(struct stm32_adc_dev_s *adc)
+{
+ struct stm32_dev_s *dev = (struct stm32_dev_s *)adc;
+
+ /* Stop and free DMA */
+
+ if (dev->dma != NULL)
+ {
+ stm32l4_dmastop(dev->dma);
+ stm32l4_dmafree(dev->dma);
+ }
+}
+
#endif /* ADC_HAVE_DMA */
/****************************************************************************
diff --git a/arch/arm/src/stm32l4/stm32l4_adc.h
b/arch/arm/src/stm32l4/stm32l4_adc.h
index 372bf7c214..c3085f25c3 100644
--- a/arch/arm/src/stm32l4/stm32l4_adc.h
+++ b/arch/arm/src/stm32l4/stm32l4_adc.h
@@ -29,6 +29,7 @@
#include <nuttx/analog/adc.h>
#include "chip.h"
#include "hardware/stm32l4_adc.h"
+#include "stm32l4_dma.h"
/****************************************************************************
* Pre-processor Definitions
@@ -458,8 +459,6 @@
(adc)->llops->val_get(adc)
#define ADC_INJDATA_GET(adc, chan) \
(adc)->llops->inj_get(adc, chan)
-#define ADC_REGBUF_REGISTER(adc, buffer, len) \
- (adc)->llops->regbuf_reg(adc, buffer, len)
#define ADC_REG_STARTCONV(adc, state) \
(adc)->llops->reg_startconv(adc, state)
#define ADC_INJ_STARTCONV(adc, state) \
@@ -471,6 +470,15 @@
#define ADC_DUMP_REGS(adc) \
(adc)->llops->dump_regs(adc)
+#ifdef ADC_HAVE_DMA
+# define ADC_REGBUF_REGISTER(adc, buffer, len) \
+ (adc)->llops->regbuf_reg(adc, buffer, len)
+# define ADC_DMA_START(adc, cb, buf, len) \
+ (adc)->llops->dma_start(adc, cb, buf, len)
+# define ADC_DMA_STOP(adc) \
+ (adc)->llops->dma_stop(adc)
+#endif
+
/* IOCTL Commands ***********************************************************
*
* Cmd: ANIOC_STM32L4_TRIGGER_REG Arg:
@@ -524,11 +532,6 @@ struct stm32_adc_ops_s
uint32_t (*val_get)(struct stm32_adc_dev_s *dev);
- /* Register buffer for ADC DMA transfer */
-
- int (*regbuf_reg)(struct stm32_adc_dev_s *dev, uint16_t *buffer,
- uint8_t len);
-
/* Start/stop regular conversion */
void (*reg_startconv)(struct stm32_adc_dev_s *dev, bool state);
@@ -558,6 +561,22 @@ struct stm32_adc_ops_s
void (*inj_startconv)(struct stm32_adc_dev_s *dev, bool state);
#endif
+#ifdef ADC_HAVE_DMA
+ /* Register buffer for ADC DMA transfer */
+
+ int (*regbuf_reg)(struct stm32_adc_dev_s *dev, uint16_t *buffer,
+ uint16_t len);
+
+ /* Start DMA */
+
+ void (*dma_start)(struct stm32_adc_dev_s *dev, dma_callback_t callback,
+ uint16_t *buffer, uint16_t len);
+
+ /* Stop DMA */
+
+ void (*dma_stop)(struct stm32_adc_dev_s *dev);
+#endif
+
/* Dump ADC regs */
void (*dump_regs)(struct stm32_adc_dev_s *dev);