summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-04-01 15:52:55 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-04-01 15:52:55 +0000
commitf7122813d51018e5d3460a30596d2320a08ef740 (patch)
tree78afeda9da8586ecf85683fede0a6d79d062b8b0 /nuttx/arch/arm/src
parent8a4cd2258a5f535f54abf86d6eb92aa000ac085b (diff)
downloadpx4-nuttx-f7122813d51018e5d3460a30596d2320a08ef740.tar.gz
px4-nuttx-f7122813d51018e5d3460a30596d2320a08ef740.tar.bz2
px4-nuttx-f7122813d51018e5d3460a30596d2320a08ef740.zip
LPC17xx: Hold off sleep mode while DMA is in progress. Open1788: Reverse sense of the IDLE LED
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5810 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src')
-rw-r--r--nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.c89
-rw-r--r--nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.h53
-rw-r--r--nuttx/arch/arm/src/lpc17xx/lpc17_idle.c24
3 files changed, 143 insertions, 23 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.c b/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.c
index 6ccc8e4ef..ee12b1b22 100644
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.c
@@ -70,8 +70,9 @@
struct lpc17_dmach_s
{
+ uint8_t chn; /* The DMA channel number */
bool inuse; /* True: The channel is in use */
- uint8_t chn; /* Channel number */
+ bool inprogress; /* True: DMA is in progress on this channel */
dma_callback_t callback; /* DMA completion callback function */
void *arg; /* Argument to pass to the callback function */
};
@@ -102,11 +103,81 @@ static struct lpc17_gpdma_s g_gpdma;
* Public Data
****************************************************************************/
+/* If the following value is zero, then there is no DMA in progress. This
+ * value is needed in the IDLE loop to determine if the IDLE loop should
+ * go into lower power power consumption modes. According to the LPC17xx
+ * User Manual: "The DMA controller can continue to work in Sleep mode, and
+ * has access to the peripheral SRAMs and all peripheral registers. The
+ * flash memory and the Main SRAM are not available in Sleep mode, they are
+ * disabled in order to save power."
+ */
+
+volatile uint8_t g_dma_inprogress;
+
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
+ * Name: lpc17_dmainprogress
+ *
+ * Description:
+ * Another DMA has started. Increment the g_dma_inprogress counter.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void lpc17_dmainprogress(struct lpc17_dmach_s *dmach)
+{
+ irqstate_t flags;
+
+ /* Increment the DMA in progress counter */
+
+ flags = irqsave();
+ DEBUGASSERT(!dmach->inprogress && g_dma_inprogress < LPC17_NDMACH);
+ g_dma_inprogress++;
+ dmach->inprogress = true;
+ irqrestore(flags);
+}
+
+/****************************************************************************
+ * Name: lpc17_dmadone
+ *
+ * Description:
+ * A DMA has completed. Decrement the g_dma_inprogress counter.
+ *
+ * This function is called only from lpc17_dmastop which, in turn, will be
+ * called either by the user directly, by the user indirectly via
+ * lpc17_dmafree(), or from gpdma_interrupt when the transfer completes.
+ *
+ * NOTE: In the first two cases, we must be able to handle the case where
+ * there is no DMA in progress and gracefully ignore the call.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void lpc17_dmadone(struct lpc17_dmach_s *dmach)
+{
+ irqstate_t flags;
+
+ /* Increment the DMA in progress counter */
+
+ flags = irqsave();
+ if (dmach->inprogress)
+ {
+ DEBUGASSERT(g_dma_inprogress > 0);
+ dmach->inprogress = false;
+ g_dma_inprogress--;
+ }
+
+ irqrestore(flags);
+}
+
+/****************************************************************************
* Name: gpdma_interrupt
*
* Description:
@@ -488,6 +559,14 @@ int lpc17_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *arg)
dmach->callback = callback;
dmach->arg = arg;
+ /* Increment the count of DMAs in-progress. This count will be
+ * decremented when lpc17_dmastop() is called, either by the user,
+ * indirectly via lpc17_dmafree(), or from gpdma_interrupt when the
+ * transfer completes.
+ */
+
+ lpc17_dmainprogress(dmach);
+
/* Clear any pending DMA interrupts */
chbit = DMACH((uint32_t)dmach->chn);
@@ -521,6 +600,10 @@ int lpc17_dmastart(DMA_HANDLE handle, dma_callback_t callback, void *arg)
* reset and lpc17_dmasetup() must be called before lpc17_dmastart() can be
* called again
*
+ * This function will be called either by the user directly, by the user
+ * indirectly via lpc17_dmafree(), or from gpdma_interrupt when the
+ * transfer completes.
+ *
****************************************************************************/
void lpc17_dmastop(DMA_HANDLE handle)
@@ -547,6 +630,10 @@ void lpc17_dmastop(DMA_HANDLE handle)
chbit = DMACH((uint32_t)dmach->chn);
putreg32(chbit, LPC17_DMA_INTTCCLR);
putreg32(chbit, LPC17_DMA_INTERRCLR);
+
+ /* Decrement the count of DMAs in progress */
+
+ lpc17_dmadone(dmach);
}
/****************************************************************************
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.h b/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.h
index 43bdb27ea..0136ac105 100644
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.h
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_gpdma.h
@@ -1,4 +1,4 @@
-/************************************************************************************
+/****************************************************************************
* arch/arm/src/lpc17xx/lpc17_gpdma.h
*
* Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved.
@@ -31,36 +31,37 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************************************/
+ ****************************************************************************/
#ifndef __ARCH_ARM_SRC_LPC17XX_LPC17_GPDMA_H
#define __ARCH_ARM_SRC_LPC17XX_LPC17_GPDMA_H
-/************************************************************************************
+/****************************************************************************
* Included Files
- ************************************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
#include "chip/lpc17_gpdma.h"
-/************************************************************************************
+/****************************************************************************
* Pre-processor Definitions
- ************************************************************************************/
+ ****************************************************************************/
-/************************************************************************************
+/****************************************************************************
* Public Types
- ************************************************************************************/
+ ****************************************************************************/
#ifdef CONFIG_LPC17_GPDMA
/* DMA_HANDLE is an opaque reference to an allocated DMA channel */
typedef FAR void *DMA_HANDLE;
-/* dma_callback_t a function pointer provided to lpc17_dmastart. This function is
- * called at the completion of the DMA transfer. 'arg' is the same 'arg' value
- * that was provided when lpc17_dmastart() was called and result indicates the result
- * of the transfer: Zero indicates a successful tranfers. On failure, a negated
- * errno is returned indicating the general nature of the DMA faiure.
+/* dma_callback_t a function pointer provided to lpc17_dmastart. This
+ * function is called at the completion of the DMA transfer. 'arg' is the
+ * same 'arg' value that was provided when lpc17_dmastart() was called and
+ * result indicates the result of the transfer: Zero indicates a successful
+ * tranfers. On failure, a negated errno is returned indicating the general
+ * nature of the DMA faiure.
*/
typedef void (*dma_callback_t)(DMA_HANDLE handle, void *arg, int result);
@@ -110,19 +111,34 @@ struct lpc17_dmaregs_s
#endif /* CONFIG_DEBUG_DMA */
-/************************************************************************************
+/****************************************************************************
* Public Data
- ************************************************************************************/
+ ****************************************************************************/
#ifndef __ASSEMBLY__
-#ifdef __cplusplus
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
extern "C"
{
+#else
+#define EXTERN extern
#endif
-/************************************************************************************
+/* If the following value is zero, then there is no DMA in progress. This
+ * value is needed in the IDLE loop to determine if the IDLE loop should
+ * go into lower power power consumption modes. According to the LPC17xx
+ * User Manual: "The DMA controller can continue to work in Sleep mode, and
+ * has access to the peripheral SRAMs and all peripheral registers. The
+ * flash memory and the Main SRAM are not available in Sleep mode, they are
+ * disabled in order to save power."
+ */
+
+EXTERN volatile uint8_t g_dma_inprogress;
+
+/****************************************************************************
* Public Functions
- ************************************************************************************/
+ ****************************************************************************/
/****************************************************************************
* Name: up_dmainitialize
@@ -244,6 +260,7 @@ void lpc17_dmadump(DMA_HANDLE handle, const struct lpc17_dmaregs_s *regs,
# define lpc17_dmadump(handle,regs,msg)
#endif
+#undef EXTERN
#ifdef __cplusplus
}
#endif
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_idle.c b/nuttx/arch/arm/src/lpc17xx/lpc17_idle.c
index 88cd817f7..133847659 100644
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_idle.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_idle.c
@@ -41,7 +41,9 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
+
#include "up_internal.h"
+#include "lpc17_gpdma.h"
/****************************************************************************
* Pre-processor Definitions
@@ -94,11 +96,25 @@ void up_idle(void)
sched_process_timer();
#else
- /* Sleep until an interrupt occurs to save power */
+/* If the g_dma_inprogress is zero, then there is no DMA in progress. This
+ * value is needed in the IDLE loop to determine if the IDLE loop should
+ * go into lower power power consumption modes. According to the LPC17xx
+ * User Manual: "The DMA controller can continue to work in Sleep mode, and
+ * has access to the peripheral SRAMs and all peripheral registers. The
+ * flash memory and the Main SRAM are not available in Sleep mode, they are
+ * disabled in order to save power."
+ */
+
+#ifdef CONFIG_LPC17_GPDMA
+ if (g_dma_inprogress == 0)
+#endif
+ {
+ /* Sleep until an interrupt occurs in order to save power */
- BEGIN_IDLE();
- asm("WFI");
- END_IDLE();
+ BEGIN_IDLE();
+ asm("WFI");
+ END_IDLE();
+ }
#endif
}