libnds
Macros | Enumerations | Functions
dsp.h File Reference

DSP general utilities. More...

#include <nds/ndstypes.h>

Macros

#define REG_DSP_CMD0   (*(vu16 *)0x4004320)
 DSP Command Register 0 (R/W) (ARM9 to DSP)
 
#define REG_DSP_CMD1   (*(vu16 *)0x4004328)
 DSP Command Register 1 (R/W) (ARM9 to DSP)
 
#define REG_DSP_CMD2   (*(vu16 *)0x4004330)
 DSP Command Register 2 (R/W) (ARM9 to DSP)
 
#define REG_DSP_PADR   (*(vu16 *)(0x04004304))
 DSP Transfer Address (W)
 
#define REG_DSP_PCFG   (*(vu16 *)0x4004308)
 DSP Configuration (R/W)
 
#define REG_DSP_PCLEAR   (*(vu16 *)0x4004318)
 DSP-to-ARM9 Semaphore Clear (W)
 
#define REG_DSP_PDATA   (*(vu16 *)(0x04004300))
 DSP Transfer Data Read FIFO (R/W)
 
#define REG_DSP_PMASK   (*(vu16 *)0x4004314)
 DSP-to-ARM9 Semaphore Mask (R/W)
 
#define REG_DSP_PSEM   (*(vu16 *)0x4004310)
 ARM9-to-DSP Semaphore (R/W)
 
#define REG_DSP_PSTS   (*(vu16 *)0x400430C)
 DSP Status (R)
 
#define REG_DSP_REP0   (*(vu16 *)0x4004324)
 DSP Reply Register 0 (R) (DSP to ARM9)
 
#define REG_DSP_REP1   (*(vu16 *)0x400432C)
 DSP Reply Register 1 (R) (DSP to ARM9)
 
#define REG_DSP_REP2   (*(vu16 *)0x4004334)
 DSP Reply Register 2 (R) (DSP to ARM9)
 
#define REG_DSP_SEM   (*(vu16 *)0x400431C)
 DSP-to-ARM9 Semaphore Data (R)
 

Enumerations

enum  DSPExecResult {
  DSP_EXEC_OK = 0 ,
  DSP_NOT_AVAILABLE = -1 ,
  DSP_TLF_BAD_MAGIC = -2 ,
  DSP_TLF_BAD_VERSION = -3
}
 Possible error codes returned by dspExecuteTLF() and dspExecuteDefaultTLF(). More...
 

Functions

static void apbpClearSemaphore (uint16_t mask)
 Clears semaphore flags to be seen by the DSP in REG_APBP_SEM. More...
 
static void dspAckSemaphore (u16 mask)
 Clears semaphore bits that the DSP has set in REG_APBP_PSEM. More...
 
DSPExecResult dspExecuteDefaultTLF (const void *tlf)
 This sets up NWRAM, powers on the DSP, loads a TLF file and executes it. More...
 
DSPExecResult dspExecuteTLF (const void *tlf)
 This powers on the DSP, loads a TLF file and executes it. More...
 
static u16 dspGetSemaphore (void)
 Gets semaphore bits that the DSP has set in REG_APBP_PSEM. More...
 
u16 dspReceiveData (int id)
 Receives data from one of the REP registers. More...
 
bool dspReceiveDataReady (int id)
 Checks if a REP register has any data available. More...
 
void dspSendData (int id, u16 data)
 Sends data using one of the CMD registers. More...
 
bool dspSendDataReady (int id)
 Checks if a CMD register is available to receive new data. More...
 
static void dspSetSemaphore (u16 mask)
 Sets semaphore flags to be seen by the DSP in REG_APBP_SEM. More...
 
static void dspSetSemaphoreMask (u16 mask)
 Masks interrupts caused by DSP-to-ARM semaphores. More...
 
void dspSpinWait (void)
 Function that executes a delay of a few cycles.
 

Detailed Description

DSP general utilities.

This file contains general definitions and helpers to use the DSP of the DSi.

Enumeration Type Documentation

◆ DSPExecResult

Possible error codes returned by dspExecuteTLF() and dspExecuteDefaultTLF().

Enumerator
DSP_EXEC_OK 

No error.

DSP_NOT_AVAILABLE 

DSP or NWRAM not available in SCFG_EXT or MBK9.

DSP_TLF_BAD_MAGIC 

Invalid TLF magic value.

DSP_TLF_BAD_VERSION 

Invalid TLF version.

Function Documentation

◆ apbpClearSemaphore()

static void apbpClearSemaphore ( uint16_t  mask)
inlinestatic

Clears semaphore flags to be seen by the DSP in REG_APBP_SEM.

Parameters
maskBits to clear.

◆ dspAckSemaphore()

static void dspAckSemaphore ( u16  mask)
inlinestatic

Clears semaphore bits that the DSP has set in REG_APBP_PSEM.

Parameters
maskBits to clear.

◆ dspExecuteDefaultTLF()

DSPExecResult dspExecuteDefaultTLF ( const void *  tlf)

This sets up NWRAM, powers on the DSP, loads a TLF file and executes it.

This function uses a sensible default NWRAM mapping. If you prefer to define it manually, use dspExecuteTLF() instead.

Parameters
tlfPointer to the TLF data in RAM.
Returns
DSP_EXEC_OK on success, an error code on failure.

◆ dspExecuteTLF()

DSPExecResult dspExecuteTLF ( const void *  tlf)

This powers on the DSP, loads a TLF file and executes it.

The user must allocate NWRAM to the ARM9 before calling this function by using nwramSetBlockMapping(). Remember that the default MPU setup only allows mapping it to the range 0x03000000 - 0x03800000. If you prefer to use a sensible default mapping without doing it manually, use dspExecuteDefaultTLF() instead.

Parameters
tlfPointer to the TLF data in RAM.
Returns
DSP_EXEC_OK on success, an error code on failure.

◆ dspGetSemaphore()

static u16 dspGetSemaphore ( void  )
inlinestatic

Gets semaphore bits that the DSP has set in REG_APBP_PSEM.

Returns
Bits set by the DSP to 1.

◆ dspReceiveData()

u16 dspReceiveData ( int  id)

Receives data from one of the REP registers.

This function waits until there is a value to be read.

Parameters
idID of the REP register (0 to 2).
Returns
Received data.

◆ dspReceiveDataReady()

bool dspReceiveDataReady ( int  id)

Checks if a REP register has any data available.

Parameters
idID of the REP register (0 to 2).
Returns
true if there is data to be read.

◆ dspSendData()

void dspSendData ( int  id,
u16  data 
)

Sends data using one of the CMD registers.

This function waits until the previous value has been read by the DSP.

Parameters
idID of the CMD register (0 to 2).
dataData to send.

◆ dspSendDataReady()

bool dspSendDataReady ( int  id)

Checks if a CMD register is available to receive new data.

Parameters
idID of the CMD register (0 to 2).
Returns
true if it is available.

◆ dspSetSemaphore()

static void dspSetSemaphore ( u16  mask)
inlinestatic

Sets semaphore flags to be seen by the DSP in REG_APBP_SEM.

Parameters
maskBits to set on top of the currently set bits.

◆ dspSetSemaphoreMask()

static void dspSetSemaphoreMask ( u16  mask)
inlinestatic

Masks interrupts caused by DSP-to-ARM semaphores.

Parameters
maskBits set to 1 will disable interrupts for that semaphore.