libctru  v1.6.0
Enumerations | Functions
dsp.h File Reference

DSP Service to access the DSP processor commands (sound) More...

#include <3ds/types.h>

Go to the source code of this file.

Enumerations

enum  DSP_InterruptType { DSP_INTERRUPT_PIPE = 2 }
 DSP interrupt types. More...
 
enum  DSP_PipeDirection {
  DSP_PIPE_INPUT = 0,
  DSP_PIPE_OUTPUT = 1
}
 DSP pipe directions. More...
 

Functions

Result dspInit (void)
 Initializes the dsp service. More...
 
void dspExit (void)
 Closes the dsp service. More...
 
Result DSP_GetHeadphoneStatus (bool *is_inserted)
 Checks if a headphone is inserted. More...
 
Result DSP_FlushDataCache (const void *address, u32 size)
 Flushes the cache. More...
 
Result DSP_InvalidateDataCache (const void *address, u32 size)
 Invalidates the cache. More...
 
Result DSP_GetSemaphoreHandle (Handle *semaphore)
 Retrieves the handle of the DSP semaphore. More...
 
Result DSP_SetSemaphore (u16 value)
 Sets the DSP hardware semaphore value. More...
 
Result DSP_SetSemaphoreMask (u16 mask)
 Masks the DSP hardware semaphore value. More...
 
Result DSP_LoadComponent (const void *component, u32 size, u16 prog_mask, u16 data_mask, bool *is_loaded)
 Loads a DSP binary and starts the DSP. More...
 
Result DSP_UnloadComponent (void)
 Stops the DSP by unloading the binary.
 
Result DSP_RegisterInterruptEvents (Handle handle, u32 interrupt, u32 channel)
 Registers an event handle with the DSP through IPC. More...
 
Result DSP_ReadPipeIfPossible (u32 channel, u32 peer, void *buffer, u16 length, u16 *length_read)
 Reads a pipe if possible. More...
 
Result DSP_WriteProcessPipe (u32 channel, const void *buffer, u32 length)
 
Result DSP_ConvertProcessAddressFromDspDram (u32 dsp_address, u32 *arm_address)
 Converts a DSP memory address to a virtual address usable by the process. More...
 
Result DSP_RecvData (u16 regNo, u16 *value)
 Reads a DSP register. More...
 
Result DSP_RecvDataIsReady (u16 regNo, bool *is_ready)
 Checks if you can read a DSP register. More...
 
Result DSP_SendData (u16 regNo, u16 value)
 Writes to a DSP register. More...
 
Result DSP_SendDataIsEmpty (u16 regNo, bool *is_empty)
 Checks if you can write to a DSP register ? More...
 

Detailed Description

DSP Service to access the DSP processor commands (sound)

The DSP has access to the Linear memory region, and to the DSP memory region if allowed in the exheader.

Enumeration Type Documentation

◆ DSP_InterruptType

DSP interrupt types.

Enumerator
DSP_INTERRUPT_PIPE 

Pipe interrupt.

◆ DSP_PipeDirection

DSP pipe directions.

Enumerator
DSP_PIPE_INPUT 

DSP to ARM.

DSP_PIPE_OUTPUT 

ARM to DSP.

Function Documentation

◆ DSP_ConvertProcessAddressFromDspDram()

Result DSP_ConvertProcessAddressFromDspDram ( u32  dsp_address,
u32 arm_address 
)

Converts a DSP memory address to a virtual address usable by the process.

Parameters
dsp_addressAddress to convert.
arm_addressPointer to output the converted address to.

◆ DSP_FlushDataCache()

Result DSP_FlushDataCache ( const void *  address,
u32  size 
)

Flushes the cache.

Parameters
addressBeginning of the memory range to flush, inside the Linear or DSP memory regions
sizeSize of the memory range to flush

Flushes the cache for the specified memory range and invalidates the cache

Examples
audio/filters/source/main.c, and audio/streaming/source/main.c.

◆ DSP_GetHeadphoneStatus()

Result DSP_GetHeadphoneStatus ( bool *  is_inserted)

Checks if a headphone is inserted.

Parameters
is_insertedPointer to output the insertion status to.

◆ DSP_GetSemaphoreHandle()

Result DSP_GetSemaphoreHandle ( Handle semaphore)

Retrieves the handle of the DSP semaphore.

Parameters
semaphorePointer to output the semaphore to.

◆ DSP_InvalidateDataCache()

Result DSP_InvalidateDataCache ( const void *  address,
u32  size 
)

Invalidates the cache.

Parameters
addressBeginning of the memory range to invalidate, inside the Linear or DSP memory regions
sizeSize of the memory range to flush

Invalidates the cache for the specified memory range

◆ DSP_LoadComponent()

Result DSP_LoadComponent ( const void *  component,
u32  size,
u16  prog_mask,
u16  data_mask,
bool *  is_loaded 
)

Loads a DSP binary and starts the DSP.

Parameters
componentThe program file address in memory
sizeThe size of the program
prog_maskDSP memory block related ? Default is 0xff.
data_maskDSP memory block related ? Default is 0xff.
is_loadedIndicates if the DSP was succesfully loaded.
Note
The binary must be signed (http://3dbrew.org/wiki/DSP_Binary)
Seems to be called when the 3ds leaves the Sleep mode

◆ DSP_ReadPipeIfPossible()

Result DSP_ReadPipeIfPossible ( u32  channel,
u32  peer,
void *  buffer,
u16  length,
u16 length_read 
)

Reads a pipe if possible.

Parameters
channelunknown. Usually 2
peerunknown. Usually 0
bufferThe buffer that will store the values read from the pipe
lengthLength of the buffer
length_readNumber of bytes read by the command

◆ DSP_RecvData()

Result DSP_RecvData ( u16  regNo,
u16 value 
)

Reads a DSP register.

Parameters
regNoOffset of the hardware register, base address is 0x1EC40000
valuePointer to read the register value to.

◆ DSP_RecvDataIsReady()

Result DSP_RecvDataIsReady ( u16  regNo,
bool *  is_ready 
)

Checks if you can read a DSP register.

Parameters
regNoOffset of the hardware register, base address is 0x1EC40000
is_readyPointer to write the ready status to.
Warning
This call might hang if the data is not ready. See DSP_SendDataIsEmpty.

◆ DSP_RegisterInterruptEvents()

Result DSP_RegisterInterruptEvents ( Handle  handle,
u32  interrupt,
u32  channel 
)

Registers an event handle with the DSP through IPC.

Parameters
handleEvent handle to register.
interruptThe type of interrupt that will trigger the event. Usual value is DSP_INTERRUPT_PIPE.
channelThe pipe channel. Usual value is 2
Note
It is possible that interrupt are inverted

◆ DSP_SendData()

Result DSP_SendData ( u16  regNo,
u16  value 
)

Writes to a DSP register.

Parameters
regNoOffset of the hardware register, base address is 0x1EC40000
valueValue to write.
Warning
This call might hang if the SendData is not empty. See DSP_SendDataIsEmpty.

◆ DSP_SendDataIsEmpty()

Result DSP_SendDataIsEmpty ( u16  regNo,
bool *  is_empty 
)

Checks if you can write to a DSP register ?

Parameters
regNoOffset of the hardware register, base address is 0x1EC40000
is_emptyPointer to write the empty status to.

◆ DSP_SetSemaphore()

Result DSP_SetSemaphore ( u16  value)

Sets the DSP hardware semaphore value.

Parameters
valueValue to set.

◆ DSP_SetSemaphoreMask()

Result DSP_SetSemaphoreMask ( u16  mask)

Masks the DSP hardware semaphore value.

Parameters
maskMask to apply.

◆ DSP_WriteProcessPipe()

Result DSP_WriteProcessPipe ( u32  channel,
const void *  buffer,
u32  length 
)
Parameters
Writesto a pipe.
channelunknown. Usually 2
bufferThe message to send to the DSP process
lengthLength of the message

◆ dspExit()

void dspExit ( void  )

Closes the dsp service.

Note
This will also unload the DSP binary.

◆ dspInit()

Result dspInit ( void  )

Initializes the dsp service.

Call this before calling any DSP_* function.

Note
This will also unload any previously loaded DSP binary. It is done this way since you have to provide your binary when the 3DS leaves sleep mode anyway.