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.

## Data Structures

struct | dspHookCookie
| DSP hook cookie. More...

## Typedefs

typedef void(* | dspHookFn) (DSP_HookType hook)
| DSP hook function.

## Enumerations

enum | DSP_InterruptType { DSP_INTERRUPT_PIPE = 2 }
| DSP interrupt types. More...
enum | DSP_HookType { DSPHOOK_ONSLEEP = 0 , DSPHOOK_ONWAKEUP = 1 , DSPHOOK_ONCANCEL = 2 }
| DSP hook types. More...

## Functions

Result | dspInit (void)
| Initializes the dsp service. More...
void | dspExit (void)
| Closes the dsp service. More...
bool | dspIsComponentLoaded (void)
| Returns true if a component is loaded, false otherwise.
void | dspHook (dspHookCookie *cookie, dspHookFn callback)
| Sets up a DSP status hook. More...
void | dspUnhook (dspHookCookie *cookie)
| Removes a DSP status hook. 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)
| Writes to a pipe. More...
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_HookType

enum DSP_HookType

DSP hook types.

Enumerator
DSPHOOK_ONSLEEP | DSP is going to sleep.
DSPHOOK_ONWAKEUP | DSP is waking up.
DSPHOOK_ONCANCEL | DSP was sleeping and the app was cancelled.

## DSP_InterruptType

enum DSP_InterruptType

DSP interrupt types.

Enumerator
DSP_INTERRUPT_PIPE | Pipe interrupt.

## 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_address | Address to convert.
  arm_address | Pointer to output the converted address to.

## DSP_FlushDataCache()

Result DSP_FlushDataCache | ( | const void * | address,
|  | u32 | size
| ) |  |

Flushes the cache.

Parameters

  address | Beginning of the memory range to flush, inside the Linear or DSP memory regions
  size | Size 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_inserted | Pointer to output the insertion status to.

## DSP_GetSemaphoreHandle()

Result DSP_GetSemaphoreHandle | ( | Handle * | semaphore | ) |

Retrieves the handle of the DSP semaphore.

Parameters

  semaphore | Pointer to output the semaphore to.

## DSP_InvalidateDataCache()

Result DSP_InvalidateDataCache | ( | const void * | address,
|  | u32 | size
| ) |  |

Invalidates the cache.

Parameters

  address | Beginning of the memory range to invalidate, inside the Linear or DSP memory regions
  size | Size 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

  component | The program file address in memory
  size | The size of the program
  prog_mask | DSP memory block related ? Default is 0xff.
  data_mask | DSP memory block related ? Default is 0xff.
  is_loaded | Indicates 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

  channel | unknown. Usually 2
  peer | unknown. Usually 0
  buffer | The buffer that will store the values read from the pipe
  length | Length of the buffer
  length_read | Number of bytes read by the command

## DSP_RecvData()

Result DSP_RecvData | ( | u16 | regNo,
|  | u16 * | value
| ) |  |

Reads a DSP register.

Parameters

  regNo | Offset of the hardware register, base address is 0x1EC40000
  value | Pointer 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

  regNo | Offset of the hardware register, base address is 0x1EC40000
  is_ready | Pointer 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

  handle | Event handle to register.
  interrupt | The type of interrupt that will trigger the event. Usual value is DSP_INTERRUPT_PIPE.
  channel | The 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

  regNo | Offset of the hardware register, base address is 0x1EC40000
  value | Value 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

  regNo | Offset of the hardware register, base address is 0x1EC40000
  is_empty | Pointer to write the empty status to.

## DSP_SetSemaphore()

Result DSP_SetSemaphore | ( | u16 | value | ) |

Sets the DSP hardware semaphore value.

Parameters

  value | Value to set.

## DSP_SetSemaphoreMask()

Result DSP_SetSemaphoreMask | ( | u16 | mask | ) |

Masks the DSP hardware semaphore value.

Parameters

  mask | Mask to apply.

## DSP_WriteProcessPipe()

Result DSP_WriteProcessPipe | ( | u32 | channel,
|  | const void * | buffer,
|  | u32 | length
| ) |  |

Writes to a pipe.

Parameters

  channel | unknown. Usually 2
  buffer | The message to send to the DSP process
  length | Length of the message

## dspExit()

void dspExit | ( | void |  | ) |

Closes the dsp service.

Note
  This will also unload the DSP binary.

## dspHook()

void dspHook | ( | dspHookCookie * | cookie,
|  | dspHookFn | callback
| ) |  |

Sets up a DSP status hook.

Parameters

  cookie | Hook cookie to use.
  callback | Function to call when DSP's status changes.

## 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.

## dspUnhook()

void dspUnhook | ( | dspHookCookie * | cookie | ) |

Removes a DSP status hook.

Parameters

  cookie | Hook cookie to remove.