A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

GPDMA Class Reference

Wrapper for the General Purpose DMA controller. More...

#include <GPDMA.h>

Public Member Functions

void init ()
 Initializes the GPDMA.
void deinit ()
 Shuts down the GPDMA.
DMAChannels acquireChannel (void(*irqfunc)(void), DMAChannels suggested=DMACh3)
 Get a free GPDMA channel for one DMA connection.
void releaseChannel (DMAChannels ch)
 Release a previously acquired channel.
LPC_GPDMACH_TypeDef * getDirectRegisters (DMAChannels ch)
 Returns the raw registers for the GPDMA channel for direct manipulation.
bool transfer (GPDMA_Channel_CFG_T *cfg, uint32_t CtrlWord, uint32_t LinkListItem, uint8_t SrcPeripheral, uint8_t DstPeripheral)
 Does the actual DMA transfer.

Static Public Member Functions

static GPDMAinstance ()
 Get the only instance of the GPDMA.

Detailed Description

Wrapper for the General Purpose DMA controller.

The GPDMA class allows multiple users of DMA to claim one or more of the eight available DMA channels and to register handlers for the interrupts. This centralized control is needed as there are eight channels but only one DMA IRQ.

By having to request a channel to use it is possible to avoid having hardcoded DMA channel number in the code

An example of use:

 void handler() {
   _eventSuccess = LPC_GPDMA->IntTCStat & (1<<ch);
   LPC_GPDMA->IntTCClear = (1<<ch);
 }

 void foo() {
    GPDMA* dma = &GPDMA::instance();
    dma->init();

    DMAChannels ch = dma->acquireChannel(handler)
    if (ch == DMACh_Unavailable) {
      // handle error
    }

    // prepare the channel data (see e.g. gpdma_transfer_from_mci() in MCIFileSystem)
    ...

    // start the transfer
    dma->transfer(&cfg, ctrl_word, 0, GPDMA_CONN_SDC, GPDMA_CONN_MEMORY);

    // wait for transfer to complete (e.g. by handler() setting a flag)
    ...

    // return the channel now that it is no longer needed
    dma->releaseChannel(ch);
 }

Definition at line 137 of file GPDMA.h.


Member Function Documentation

GPDMA::DMAChannels acquireChannel ( void(*)(void)  irqfunc,
DMAChannels  suggested = DMACh3 
)

Get a free GPDMA channel for one DMA connection.

The function will start to look for the suggested channel. If it is in use then the next, higher, channel number will be tested. The default is set to use DMACh3 which has medium priority.

To acquire a channel with the highest available priority call this function with DMACh0 as parameter.

Parameters:
functhe interrupt callback function
suggestedthe first channel to look for
Returns:
DMACh0 to DMACh7 on success DMACh_Unavailable if there are no channels available

Definition at line 118 of file GPDMA.cpp.

void deinit (  )

Shuts down the GPDMA.

Call will be ignored if there are any acquired channels

Definition at line 99 of file GPDMA.cpp.

LPC_GPDMACH_TypeDef * getDirectRegisters ( DMAChannels  ch )

Returns the raw registers for the GPDMA channel for direct manipulation.

Parameters:
chthe DMA channel
Returns:
The registers on success NULL if the channel is invalid

Definition at line 153 of file GPDMA.cpp.

void init (  )

Initializes the GPDMA.

Safe to call even with multiple DMA users

Definition at line 72 of file GPDMA.cpp.

static GPDMA& instance (  ) [static]

Get the only instance of the GPDMA.

Returns:
The Registry

Definition at line 174 of file GPDMA.h.

void releaseChannel ( DMAChannels  ch )

Release a previously acquired channel.

Parameters:
chthe DMA channel to release

Definition at line 139 of file GPDMA.cpp.

bool transfer ( GPDMA_Channel_CFG_T *  cfg,
uint32_t  CtrlWord,
uint32_t  LinkListItem,
uint8_t  SrcPeripheral,
uint8_t  DstPeripheral 
)

Does the actual DMA transfer.

Parameters:
cfgthe DMA configuration
CtrlWorddata for the DMA channel's CONTROL register
LinkListItemaddress to the linked list or 0 if not used
SrcPeripheralsource of the transfer (GPDMA_CONN_MEMORY or GPDMA_CONN_SDC)
DstPeripheraldestination of the transfer (GPDMA_CONN_MEMORY or GPDMA_CONN_SDC)
Returns:
True on success, false on failure

Definition at line 183 of file GPDMA.cpp.