libnds
Loading...
Searching...
No Matches
Macros | Functions
dma.h File Reference

Wrapper functions for direct memory access hardware. More...

#include <nds/ndstypes.h>

Macros

#define DMA_DISP_FIFO   (4 << 27)
 Auto-start DMA on display FIFO fill (8 pixels at a time)
 
#define DMA_START_CARD   (2 << 28)
 Auto-start DMA on Slot-1 card transfer.
 
#define DMA_START_CARD   (5 << 27)
 Auto-start DMA on Slot-1 card transfer.
 
#define DMA_START_FIFO   (7 << 27)
 Auto-start DMA for 3D geometry FIFO queue.
 
#define DMA_START_HBL   (2 << 27)
 Auto-start DMA on each visible scanline's horizontal blank.
 
#define DMA_START_LINE   (3 << 27)
 Auto-start DMA on the beginning of each visible scanline.
 
#define DMA_START_NOW   0
 Start DMA immediately.
 
#define DMA_START_SLOT1   (2 << 28)
 Auto-start DMA on Slot-1 card transfer.
 
#define DMA_START_SLOT1   (5 << 27)
 Auto-start DMA on Slot-1 card transfer.
 
#define DMA_START_SLOT2   (3 << 28)
 Auto-start DMA on Slot-2 interrupt request (DMA1/DMA3 only)
 
#define DMA_START_SLOT2   (6 << 27)
 Auto-start DMA on Slot-2 interrupt request (DMA1/DMA3 only)
 
#define DMA_START_VBL   (1 << 28)
 Auto-start DMA on vertical blank.
 
#define DMA_START_VBL   (1 << 27)
 Auto-start DMA on vertical blank.
 
#define DMA_START_WIFI   (3 << 28)
 Auto-start DMA on NTR Wi-Fi interrupt request (DMA0/DMA2 only)
 

Functions

static int dmaBusy (uint8_t channel)
 Determines if the specified channel is busy.
 
static void dmaCopy (const void *source, void *dest, uint32_t size)
 Copies from source to destination using channel 3 of DMA available channels in half words.
 
static void dmaCopyAsynch (const void *source, void *dest, uint32_t size)
 Copies from source to destination using channel 3 of DMA available channels in half words.
 
static void dmaCopyHalfWords (uint8_t channel, const void *src, void *dest, uint32_t size)
 Copies from source to destination on one of the 4 available channels in half words.
 
static void dmaCopyHalfWordsAsynch (uint8_t channel, const void *src, void *dest, uint32_t size)
 Copies from source to destination on one of the 4 available channels in half words.
 
static void dmaCopyWords (uint8_t channel, const void *src, void *dest, uint32_t size)
 Copies from source to destination on one of the 4 available channels in words.
 
static void dmaCopyWordsAsynch (uint8_t channel, const void *src, void *dest, uint32_t size)
 Copies from source to destination on one of the 4 available channels in half words.
 
static void dmaFillHalfWords (u16 value, void *dest, uint32_t size)
 Fills the source with the supplied value using DMA channel 3.
 
static void dmaFillWords (u32 value, void *dest, uint32_t size)
 Fills the source with the supplied value using DMA channel 3.
 
void dmaSetParams (uint8_t channel, const void *src, void *dest, uint32_t ctrl)
 Starts a DMA transfer safely from ITCM.
 
void dmaStopSafe (uint8_t channel)
 Stops a DMA channel safely from ITCM.
 

Detailed Description

Wrapper functions for direct memory access hardware.

The DS has 4 hardware direct memory access devices per CPU which can be used to transfer or fill chunks of memeory without CPU intervention. Using DMA is generaly faster than CPU copies (memcpy, swiCopy, for loops, etc..).

DMA has no access to data caches on the DS and as such will give unexpected results when DMAing data from main memory. The cache must be flushed as follows when using DMA to ensure proper opertion on the ARM9:

DC_FlushRange(source, sizeof(dataToCopy));
dmaCopy(source, destination, sizeof(dataToCopy));
static void DC_FlushRange(const void *base, u32 size)
Flush the data cache of a range of addresses to memory.
Definition cache.h:51
static void dmaCopy(const void *source, void *dest, uint32_t size)
Copies from source to destination using channel 3 of DMA available channels in half words.
Definition dma.h:174

Very important note: Don't write to the DMA registers directly from the ARM9, it is unsafe. Enabling and disabling the DMA must not be done from code in main RAM, and special care is required to disable an enabled DMA channel. You should use dmaSetParams() and dmaStopSafe() instead.

Macro Definition Documentation

◆ DMA_START_SLOT2 [1/2]

#define DMA_START_SLOT2   (3 << 28)

Auto-start DMA on Slot-2 interrupt request (DMA1/DMA3 only)

Auto-start DMA on Slot-2 interrupt request.

◆ DMA_START_SLOT2 [2/2]

#define DMA_START_SLOT2   (6 << 27)

Auto-start DMA on Slot-2 interrupt request (DMA1/DMA3 only)

Auto-start DMA on Slot-2 interrupt request.

◆ DMA_START_VBL [1/2]

#define DMA_START_VBL   (1 << 28)

Auto-start DMA on vertical blank.

Auto-start DMA on each frame's vertical blank.

◆ DMA_START_VBL [2/2]

#define DMA_START_VBL   (1 << 27)

Auto-start DMA on vertical blank.

Auto-start DMA on each frame's vertical blank.

Function Documentation

◆ dmaBusy()

static int dmaBusy ( uint8_t  channel)
inlinestatic

Determines if the specified channel is busy.

Parameters
channelThe DMA channel to check (0 - 3).
Returns
Non zero if busy, 0 if channel is free.

◆ dmaCopy()

static void dmaCopy ( const void *  source,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination using channel 3 of DMA available channels in half words.

Parameters
sourceThe source to copy from.
destThe destination to copy to
sizeThe size in bytes of the data to copy. Will be truncated to the nearest half word (2 bytes).

◆ dmaCopyAsynch()

static void dmaCopyAsynch ( const void *  source,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination using channel 3 of DMA available channels in half words.

This function returns immediately after starting the transfer.

Parameters
sourceThe source to copy from.
destThe destination to copy to.
sizeThe size in bytes of the data to copy. Will be truncated to the nearest half word (2 bytes)

◆ dmaCopyHalfWords()

static void dmaCopyHalfWords ( uint8_t  channel,
const void *  src,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination on one of the 4 available channels in half words.

Parameters
channelThe DMA channel to use (0 - 3).
srcThe source to copy from.
destThe destination to copy to
sizeThe size in bytes of the data to copy. Will be truncated to the nearest half word (2 bytes)

◆ dmaCopyHalfWordsAsynch()

static void dmaCopyHalfWordsAsynch ( uint8_t  channel,
const void *  src,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination on one of the 4 available channels in half words.

This function returns immediately after starting the transfer.

Parameters
channelThe DMA channel to use (0 - 3).
srcThe source to copy from.
destThe destination to copy to.
sizeThe size in bytes of the data to copy. Will be truncated to the nearest half word (2 bytes)

◆ dmaCopyWords()

static void dmaCopyWords ( uint8_t  channel,
const void *  src,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination on one of the 4 available channels in words.

Parameters
channelThe DMA channel to use (0 - 3).
srcThe source to copy from.
destThe destination to copy to.
sizeThe size in bytes of the data to copy. Will be truncated to the nearest word (4 bytes).

◆ dmaCopyWordsAsynch()

static void dmaCopyWordsAsynch ( uint8_t  channel,
const void *  src,
void *  dest,
uint32_t  size 
)
inlinestatic

Copies from source to destination on one of the 4 available channels in half words.

This function returns immediately after starting the transfer.

Parameters
channelThe DMA channel to use (0 - 3).
srcThe source to copy from.
destThe destination to copy to.
sizeThe size in bytes of the data to copy. Will be truncated to the nearest word (4 bytes)

◆ dmaFillHalfWords()

static void dmaFillHalfWords ( u16  value,
void *  dest,
uint32_t  size 
)
inlinestatic

Fills the source with the supplied value using DMA channel 3.

Parameters
valueThe 16 byte value to fill memory with.
destThe destination to copy to.
sizeThe size in bytes of the area to fill. Will be truncated to the nearest half word (2 bytes).

◆ dmaFillWords()

static void dmaFillWords ( u32  value,
void *  dest,
uint32_t  size 
)
inlinestatic

Fills the source with the supplied value using DMA channel 3.

Parameters
valueThe 32 byte value to fill memory with.
destThe destination to copy to.
sizeThe size in bytes of the area to fill. Will be truncated to the nearest word (4 bytes).

◆ dmaSetParams()

void dmaSetParams ( uint8_t  channel,
const void *  src,
void *  dest,
uint32_t  ctrl 
)

Starts a DMA transfer safely from ITCM.

Parameters
channelThe DMA channel to use (0 - 3).
srcThe source to copy from.
destThe destination to copy to.
ctrlValue to write to the control register.

◆ dmaStopSafe()

void dmaStopSafe ( uint8_t  channel)

Stops a DMA channel safely from ITCM.

Parameters
channelThe DMA channel to use (0 - 3).