libnds
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
fifocommon.h File Reference

Low level FIFO API. More...

#include <nds/cothread.h>
#include <nds/interrupts.h>
#include <nds/ndstypes.h>

Typedefs

typedef void(* FifoAddressHandlerFunc) (void *address, void *userdata)
 Callback that is called with the address sent from the other CPU and the callback's user data.
 
typedef void(* FifoDatamsgHandlerFunc) (int num_bytes, void *userdata)
 Callback that is called with the number of bytes sent from the other CPU and the callback's user data.
 
typedef void(* FifoValue32HandlerFunc) (u32 value32, void *userdata)
 Callback that is called with the 32-bit value sent from the other CPU and the callback's user data.
 

Enumerations

enum  FifoChannels {
  FIFO_PM = 0 ,
  FIFO_SOUND = 1 ,
  FIFO_SYSTEM = 2 ,
  FIFO_MAXMOD = 3 ,
  FIFO_DSWIFI = 4 ,
  FIFO_STORAGE = 5 ,
  FIFO_FIRMWARE = 6 ,
  FIFO_CAMERA = 7 ,
  FIFO_USER_01 = 8 ,
  FIFO_USER_02 = 9 ,
  FIFO_USER_03 = 10 ,
  FIFO_USER_04 = 11 ,
  FIFO_USER_05 = 12 ,
  FIFO_USER_06 = 13 ,
  FIFO_USER_07 = 14 ,
  FIFO_USER_08 = 15 ,
  FIFO_SDMMC = 5
}
 Enum values for the different FIFO channels. More...
 
enum  FifoPMCommands
 Enum values for the FIFO power management commands.
 
enum  FifoSoundCommand
 Enum values for the FIFO sound commands.
 
enum  FifoSystemCommands
 Enum values for the FIFO system commands.
 
enum  FifoWifiCommands
 Enum values for the FIFO wifi commands.
 
enum  PM_LedBlinkMode {
  PM_LED_ON = 0 ,
  PM_LED_SLEEP = 1 ,
  PM_LED_BLINK = 3
}
 Power Management LED blink mode control bits. More...
 

Functions

bool fifoCheckAddress (u32 channel)
 Checks if there are any address messages in the queue.
 
bool fifoCheckDatamsg (u32 channel)
 Checks if there are any data messages in the queue.
 
int fifoCheckDatamsgLength (u32 channel)
 Gets the size of the first message in the queue of a specific channel.
 
bool fifoCheckValue32 (u32 channel)
 Checks if there are any value32 messages in the queue.
 
void * fifoGetAddress (u32 channel)
 Gets the first address in the queue of a specific channel.
 
int fifoGetDatamsg (u32 channel, int buffersize, u8 *destbuffer)
 Reads a data message in a given buffer.
 
u32 fifoGetValue32 (u32 channel)
 Gets the first value32 in the queue of a specific channel.
 
bool fifoInit (void)
 Initializes the FIFO system.
 
void fifoMutexAcquire (u32 channel)
 Acquires the mutex of the specified FIFO channel.
 
void fifoMutexRelease (u32 channel)
 Releases the mutex of the specified FIFO channel.
 
bool fifoMutexTryAcquire (u32 channel)
 Tries to acquire the mutex of the specified FIFO channel.
 
bool fifoSendAddress (u32 channel, void *address)
 Sends a main RAM address to the other CPU.
 
bool fifoSendDatamsg (u32 channel, u32 num_bytes, u8 *data_array)
 Sends a sequence of bytes to the other CPU.
 
bool fifoSendSpecialCommand (u32 cmd)
 Sends a special command to the other CPU.
 
bool fifoSendValue32 (u32 channel, u32 value32)
 Sends a 32-bit value to the other CPU.
 
bool fifoSetAddressHandler (u32 channel, FifoAddressHandlerFunc newhandler, void *userdata)
 Sets user address message callback.
 
bool fifoSetDatamsgHandler (u32 channel, FifoDatamsgHandlerFunc newhandler, void *userdata)
 Sets user data message callback.
 
bool fifoSetValue32Handler (u32 channel, FifoValue32HandlerFunc newhandler, void *userdata)
 Sets user value32 message callback.
 
static void fifoWaitAddress (u32 channel)
 Waits for any address message in a FIFO channel and blocks until there is one available.
 
static void fifoWaitAddressAsync (u32 channel)
 Waits for any address message in a FIFO channel and yields until there isn't one available.
 
static void fifoWaitDatamsg (u32 channel)
 Waits for any data message in a FIFO channel and blocks until there is one available.
 
static void fifoWaitDatamsgAsync (u32 channel)
 Waits for any data message in a FIFO channel and yields until there isn't one available.
 
static void fifoWaitValue32 (u32 channel)
 Waits for any value32 message in a FIFO channel and blocks until there is one available.
 
static void fifoWaitValue32Async (u32 channel)
 Waits for any value32 message in a FIFO channel and yields until there isn't one available.
 

Detailed Description

Low level FIFO API.

Typedef Documentation

◆ FifoAddressHandlerFunc

typedef void(* FifoAddressHandlerFunc) (void *address, void *userdata)

Callback that is called with the address sent from the other CPU and the callback's user data.

The handler is called when new data arrives.

Note
Callback functions are called from an interrupt handler. Try to not use too much stack from the callback.

◆ FifoDatamsgHandlerFunc

typedef void(* FifoDatamsgHandlerFunc) (int num_bytes, void *userdata)

Callback that is called with the number of bytes sent from the other CPU and the callback's user data.

The handler is called when new data arrives. This callback must call fifoGetDatamsg() to actually retrieve the data. If it doesn't, the data will be destroyed on return.

Note
Callback functions are called from an interrupt handler. Try to not use too much stack from the callback.

◆ FifoValue32HandlerFunc

typedef void(* FifoValue32HandlerFunc) (u32 value32, void *userdata)

Callback that is called with the 32-bit value sent from the other CPU and the callback's user data.

The handler is called when new data arrives.

Note
Callback functions are called from an interrupt handler. Try to not use too much stack from the callback.

Enumeration Type Documentation

◆ FifoChannels

Enum values for the different FIFO channels.

Enumerator
FIFO_PM 

Channel used for power management.

FIFO_SOUND 

Channel used for sound access.

FIFO_SYSTEM 

Channel used for system functions.

FIFO_MAXMOD 

Channel used for the maxmod library.

FIFO_DSWIFI 

Channel used for the dswifi library.

FIFO_STORAGE 

Channel used for DS cart, DLDI, DSi SD and NAND access.

FIFO_FIRMWARE 

Channel used for firmware access.

FIFO_CAMERA 

Channel used for camera access.

FIFO_USER_01 

Channel available for users.

FIFO_USER_02 

Channel available for users.

FIFO_USER_03 

Channel available for users.

FIFO_USER_04 

Channel available for users.

FIFO_USER_05 

Channel available for users.

FIFO_USER_06 

Channel available for users.

FIFO_USER_07 

Channel available for users.

FIFO_USER_08 

Channel available for users.

FIFO_SDMMC 

Deprecated name of FIFO_STORAGE.

◆ PM_LedBlinkMode

Power Management LED blink mode control bits.

Enumerator
PM_LED_ON 

Steady on.

PM_LED_SLEEP 

Blinking, mostly off.

PM_LED_BLINK 

Blinking, mostly on.

Function Documentation

◆ fifoCheckAddress()

bool fifoCheckAddress ( u32  channel)

Checks if there are any address messages in the queue.

Parameters
channelChannel number.
Returns
Returns true if there are messages in the queue and there isn't a message handler in place for the channel.

◆ fifoCheckDatamsg()

bool fifoCheckDatamsg ( u32  channel)

Checks if there are any data messages in the queue.

Parameters
channelChannel number.
Returns
Returns true if there are messages in the queue and there isn't a message handler in place for the channel.

◆ fifoCheckDatamsgLength()

int fifoCheckDatamsgLength ( u32  channel)

Gets the size of the first message in the queue of a specific channel.

Parameters
channelChannel number.
Returns
Returns the number of bytes of the first message in the queue, -1 if there are no messages.

◆ fifoCheckValue32()

bool fifoCheckValue32 ( u32  channel)

Checks if there are any value32 messages in the queue.

Parameters
channelChannel number.
Returns
Returns true if there are messages in the queue and there isn't a message handler in place for the channel.

◆ fifoGetAddress()

void * fifoGetAddress ( u32  channel)

Gets the first address in the queue of a specific channel.

Parameters
channelChannel number.
Returns
Returns the first address in the queue, or NULL if there is none.

◆ fifoGetDatamsg()

int fifoGetDatamsg ( u32  channel,
int  buffersize,
u8 destbuffer 
)

Reads a data message in a given buffer.

Parameters
channelChannel number.
buffersizeSize of the provided buffer.
destbufferPointer to the buffer to store the message.
Returns
The number of bytes written, or -1 if there is no message.
Warning
If your buffer is not big enough, you may lose data. Check the actual size first with fifoCheckDatamsgLength().

◆ fifoGetValue32()

u32 fifoGetValue32 ( u32  channel)

Gets the first value32 in the queue of a specific channel.

Parameters
channelChannel number.
Returns
Returns the first value32 in the queue, or 0 if there is no message.

◆ fifoInit()

bool fifoInit ( void  )

Initializes the FIFO system.

Attempts to sync with the other CPU. If it fails, FIFO services won't be provided.

Returns
Returns true on success, false on error.
Note
Call irqInit() before calling this function.

◆ fifoMutexAcquire()

void fifoMutexAcquire ( u32  channel)

Acquires the mutex of the specified FIFO channel.

Parameters
channelChannel number.

◆ fifoMutexRelease()

void fifoMutexRelease ( u32  channel)

Releases the mutex of the specified FIFO channel.

Parameters
channelChannel number.

◆ fifoMutexTryAcquire()

bool fifoMutexTryAcquire ( u32  channel)

Tries to acquire the mutex of the specified FIFO channel.

Parameters
channelChannel number.
Returns
Returns true if the lock was acquired, false if not.

◆ fifoSendAddress()

bool fifoSendAddress ( u32  channel,
void *  address 
)

Sends a main RAM address to the other CPU.

Parameters
channelChannel number.
addressAddress to send (0x02000000-0x02FFFFFF).
Returns
Returns true if the data message has been sent, false on error.

◆ fifoSendDatamsg()

bool fifoSendDatamsg ( u32  channel,
u32  num_bytes,
u8 data_array 
)

Sends a sequence of bytes to the other CPU.

Parameters
channelChannel number.
num_bytesNumber of bytes to send (0 to FIFO_MAX_DATA_BYTES).
data_arrayPointer to data array
Returns
Returns true if the data message has been sent, false on error.

◆ fifoSendSpecialCommand()

bool fifoSendSpecialCommand ( u32  cmd)

Sends a special command to the other CPU.

Parameters
cmdCommand identifier.
Returns
Returns true if the message has been sent, false on error.

◆ fifoSendValue32()

bool fifoSendValue32 ( u32  channel,
u32  value32 
)

Sends a 32-bit value to the other CPU.

Parameters
channelChannel number.
value32Value to send.
Returns
Returns true if the data message has been sent, false on error.
Note
Sending a value with the top 8 bits set to zero is faster.

◆ fifoSetAddressHandler()

bool fifoSetAddressHandler ( u32  channel,
FifoAddressHandlerFunc  newhandler,
void *  userdata 
)

Sets user address message callback.

Sets a callback to receive incoming address messages of a specific channel.

Parameters
channelChannel number.
newhandlerFunction pointer to the new handler.
userdataPointer that will be passed on to the handler when it will be called (as "userdata").
Returns
Returns true if the handler has been set, false on error.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler if there are any unread messages.

◆ fifoSetDatamsgHandler()

bool fifoSetDatamsgHandler ( u32  channel,
FifoDatamsgHandlerFunc  newhandler,
void *  userdata 
)

Sets user data message callback.

Sets a callback to receive incoming data messages of a specific channel.

Parameters
channelChannel number.
newhandlerFunction pointer to the new handler.
userdataPointer that will be passed on to the handler when it will be called (as "userdata").
Returns
Returns true if the handler has been set, false on error.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler if there are any unread messages.

◆ fifoSetValue32Handler()

bool fifoSetValue32Handler ( u32  channel,
FifoValue32HandlerFunc  newhandler,
void *  userdata 
)

Sets user value32 message callback.

Sets a callback to receive incoming value32 messages of a specific channel.

Parameters
channelChannel number.
newhandlerFunction pointer to the new handler.
userdataPointer that will be passed on to the handler when it will be called (as "userdata").
Returns
Returns true if the handler has been set, false on error.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler if there are any unread messages.

◆ fifoWaitAddress()

static void fifoWaitAddress ( u32  channel)
inlinestatic

Waits for any address message in a FIFO channel and blocks until there is one available.

Parameters
channelChannel number.

◆ fifoWaitAddressAsync()

static void fifoWaitAddressAsync ( u32  channel)
inlinestatic

Waits for any address message in a FIFO channel and yields until there isn't one available.

Parameters
channelChannel number.

◆ fifoWaitDatamsg()

static void fifoWaitDatamsg ( u32  channel)
inlinestatic

Waits for any data message in a FIFO channel and blocks until there is one available.

Parameters
channelChannel number.

◆ fifoWaitDatamsgAsync()

static void fifoWaitDatamsgAsync ( u32  channel)
inlinestatic

Waits for any data message in a FIFO channel and yields until there isn't one available.

Parameters
channelChannel number.

◆ fifoWaitValue32()

static void fifoWaitValue32 ( u32  channel)
inlinestatic

Waits for any value32 message in a FIFO channel and blocks until there is one available.

Parameters
channelChannel number.

◆ fifoWaitValue32Async()

static void fifoWaitValue32Async ( u32  channel)
inlinestatic

Waits for any value32 message in a FIFO channel and yields until there isn't one available.

Parameters
channelChannel number.