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
This commit is contained in:
patacongo 2013-04-01 15:52:55 +00:00
parent 40a6b0438e
commit ccbbc1c553
3 changed files with 143 additions and 23 deletions

View File

@ -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,10 +103,80 @@ 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
*
@ -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);
}
/****************************************************************************

View File

@ -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

View File

@ -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."
*/
BEGIN_IDLE();
asm("WFI");
END_IDLE();
#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();
}
#endif
}