libnds
Typedefs | Enumerations | Functions
fifocommon.h File Reference

low level FIFO API. More...

#include "ndstypes.h"
#include "interrupts.h"

Typedefs

typedef void(* FifoAddressHandlerFunc) (void *address, void *userdata)
 fifo callback function pointer with the sent address and the callback's user data. More...
 
typedef void(* FifoDatamsgHandlerFunc) (int num_bytes, void *userdata)
 fifo callback function pointer with the number of bytes sent and the callback's user data More...
 
typedef void(* FifoValue32HandlerFunc) (u32 value32, void *userdata)
 fifo callback function pointer with the sent value and the callback's user data. More...
 

Enumerations

Functions

bool fifoCheckAddress (int channel)
 checks if there is any addresses in the fifo queue. More...
 
bool fifoCheckDatamsg (int channel)
 checks if there is any data messages in the fifo queue. More...
 
int fifoCheckDatamsgLength (int channel)
 gets the number of bytes in the queue for the first data entry. More...
 
bool fifoCheckValue32 (int channel)
 checks if there is any values in the fifo queue. More...
 
void * fifoGetAddress (int channel)
 Get the first address in queue for a specific channel. More...
 
int fifoGetDatamsg (int channel, int buffersize, u8 *destbuffer)
 Reads a data message in a given buffer and returns the number of bytes written. More...
 
u32 fifoGetValue32 (int channel)
 Get the first value32 in queue for a specific channel. More...
 
bool fifoInit ()
 Initializes the fifo system. More...
 
bool fifoSendAddress (int channel, void *address)
 Send an address to an channel. More...
 
bool fifoSendDatamsg (int channel, int num_bytes, u8 *data_array)
 Send a sequence of bytes to the other CPU. More...
 
bool fifoSendValue32 (int channel, u32 value32)
 Send a 32bit value. More...
 
bool fifoSetAddressHandler (int channel, FifoAddressHandlerFunc newhandler, void *userdata)
 Set user address message callback. More...
 
bool fifoSetDatamsgHandler (int channel, FifoDatamsgHandlerFunc newhandler, void *userdata)
 Set user data message callback. More...
 
bool fifoSetValue32Handler (int channel, FifoValue32HandlerFunc newhandler, void *userdata)
 Set user value32 message callback. More...
 
static void fifoWaitValue32 (int channel)
 waits for any data messages in the fifo queue. More...
 

Detailed Description

low level FIFO API.

Typedef Documentation

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

fifo callback function pointer with the sent address and the callback's user data.

The handler is called when new data arrives.

Note
callback functions are called from interrupt level, but are well secured. not too much caution is necessary, but don't call alloc, free or printf from within them, just to be safe.
typedef void(* FifoDatamsgHandlerFunc) (int num_bytes, void *userdata)

fifo callback function pointer with the number of bytes sent and the callback's user data

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

Note
callback functions are called from interrupt level, but are well secured. not too much caution is necessary, but don't call alloc, free or printf from within them, just to be safe.
typedef void(* FifoValue32HandlerFunc) (u32 value32, void *userdata)

fifo callback function pointer with the sent value and the callback's user data.

The handler is called when new data arrives.

Note
callback functions are called from interrupt level, but are well secured. not too much caution is necessary, but don't call alloc, free or printf from within them, just to be safe.

Enumeration Type Documentation

Enum values for the different fifo channels.

Enumerator
FIFO_PM 

fifo channel reserved for power management.

FIFO_SOUND 

fifo channel reserved for sound access.

FIFO_SYSTEM 

fifo channel reserved for system functions.

FIFO_MAXMOD 

fifo channel reserved for the maxmod library.

FIFO_DSWIFI 

fifo channel reserved for the dswifi library.

FIFO_SDMMC 

fifo channel reserved for dsi sdmmc control.

FIFO_FIRMWARE 

fifo channel reserved for firmware access.

FIFO_RSVD_01 

fifo channel reserved for future use.

FIFO_USER_01 

fifo channel available for users.

FIFO_USER_02 

fifo channel available for users.

FIFO_USER_03 

fifo channel available for users.

FIFO_USER_04 

fifo channel available for users.

FIFO_USER_05 

fifo channel available for users.

FIFO_USER_06 

fifo channel available for users.

FIFO_USER_07 

fifo channel available for users.

FIFO_USER_08 

fifo channel available for users.

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

bool fifoCheckAddress ( int  channel)

checks if there is any addresses in the fifo queue.

Parameters
channelthe channel to check.
Returns
true if there is any addresses in the queue and if there isn't an address handler in place for the channel.
bool fifoCheckDatamsg ( int  channel)

checks if there is any data messages in the fifo queue.

Parameters
channelthe channel to check.
Returns
true if there is any data messages in the queue and if there isn't a data message handler in place for the channel.
int fifoCheckDatamsgLength ( int  channel)

gets the number of bytes in the queue for the first data entry.

Parameters
channelthe channel to check.
Returns
the number of bytes in the queue for the first data entry, or -1 if there are no entries.
bool fifoCheckValue32 ( int  channel)

checks if there is any values in the fifo queue.

Parameters
channelthe channel to check.
Returns
true if there is any values in the queue and if there isn't a value handler in place for the channel.
void* fifoGetAddress ( int  channel)

Get the first address in queue for a specific channel.

Parameters
channelthe channel to check.
Returns
the first address in queue, or NULL if there is none.
int fifoGetDatamsg ( int  channel,
int  buffersize,
u8 destbuffer 
)

Reads a data message in a given buffer and returns the number of bytes written.

Parameters
channelthe channel to check.
buffersizethe size of the buffer where the message will be copied to.
destbuffera pointer to the buffer where the message will be copied to.
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 data length first if you're not sure what the size is.
u32 fifoGetValue32 ( int  channel)

Get the first value32 in queue for a specific channel.

Parameters
channelthe channel to check.
Returns
the first value32 in queue, or 0 if there is no message.
bool fifoInit ( )

Initializes the fifo system.

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

Note
call irqInit() before calling this function.
Returns
true if syncing worked, false if something went wrong.
bool fifoSendAddress ( int  channel,
void *  address 
)

Send an address to an channel.

Transmits an address in the range 0x02000000-0x023FFFFF to the other CPU.

Parameters
channelchannel number to send to.
addressaddress to send.
Returns
true if the address has been send, false if something went wrong.
bool fifoSendDatamsg ( int  channel,
int  num_bytes,
u8 data_array 
)

Send a sequence of bytes to the other CPU.

num_bytes can be between 0 and FIFO_MAX_DATA_BYTES - sending 0 bytes can be useful sometimes...

Parameters
channelchannel number to send to
num_bytesnumber of bytes to send
data_arraypointer to data array
Returns
true if the data message has been send, false if something went wrong.
bool fifoSendValue32 ( int  channel,
u32  value32 
)

Send a 32bit value.

Transmits a 32bit value to the other CPU.

Parameters
channelchannel number to send to
value3232bit value to send
Returns
true if the value has been send, false if something went wrong.
Note
Transfer is more efficient if the top 8 bits are zero. So sending smaller values or bitmasks that don't include the top bits is preferred.
bool fifoSetAddressHandler ( int  channel,
FifoAddressHandlerFunc  newhandler,
void *  userdata 
)

Set user address message callback.

Set a callback to receive incoming address messages on a specific channel.

Parameters
channelchannel number to send to.
newhandlera function pointer to the new handler function.
userdataa pointer that will be passed on to the handler when it will be called.
Returns
true if the handler has been set, false if something went wrong.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler, if there are any unread messages.
bool fifoSetDatamsgHandler ( int  channel,
FifoDatamsgHandlerFunc  newhandler,
void *  userdata 
)

Set user data message callback.

Set a callback to receive incoming data messages on a specific channel.

Parameters
channelchannel number to send to.
newhandlera function pointer to the new handler function.
userdataa pointer that will be passed on to the handler when it will be called.
Returns
true if the handler has been set, false if something went wrong.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler, if there are any unread messages.
bool fifoSetValue32Handler ( int  channel,
FifoValue32HandlerFunc  newhandler,
void *  userdata 
)

Set user value32 message callback.

Set a callback to receive incoming value32 messages on a specific channel.

Parameters
channelchannel number to send to.
newhandlera function pointer to the new handler function.
userdataa pointer that will be passed on to the handler when it will be called.
Returns
true if the handler has been set, false if something went wrong.
Note
Setting the handler for a channel feeds the queue of buffered messages to the new handler, if there are any unread messages.
static void fifoWaitValue32 ( int  channel)
inlinestatic

waits for any data messages in the fifo queue.

Parameters
channelthe channel to check.