lib/fifo.h File Reference

A FIFO implementation. More...

#include <stdint.h>

Data Structures

struct  fifo
 The structure forming the FIFO. More...

Functions

void init_fifo (struct fifo *fifo, uint8_t *buffer, unsigned int size)
 Initialise a Fifo.
int writeByte_fifo (struct fifo *fifo, unsigned char data)
 Write one byte to the fifo.
uint32_t write_fifo (struct fifo *fifo, const uint8_t *buffer, uint32_t size)
 Write upto the requested number of bytes into the fifo.
int readByte_fifo (struct fifo *fifo, uint8_t *data)
 Read a byte from the fifo.
uint32_t read_fifo (struct fifo *fifo, uint8_t *buffer, uint32_t size)
 Read upto the requested number of bytes from the fifo.
uint32_t getSize_fifo (struct fifo *fifo)
 Get the current size of the fifo.


Detailed Description

A FIFO implementation.

A First In First Out implementation. The size of data written to and read from the fifo is one byte.

NOTE: These fifo functions are not re-entrant so protect them.


Function Documentation

uint32_t getSize_fifo ( struct fifo fifo  )  [inline]

Get the current size of the fifo.

Parameters:
fifo The FIFO on which the operation will be performed.
Returns:
The number of bytes currently in the fifo.

void init_fifo ( struct fifo fifo,
uint8_t *  buffer,
unsigned int  size 
)

Initialise a Fifo.

Initialise the fifo to be empty. Set the buffer to the supplied buffer and set the fifo maximum size accordingly. The read and write pointers are positioned at the start of the buffer.

Parameters:
fifo The FIFO on which the operation will be performed.
buffer The buffer to be used by the fifo.
size The size of the buffer in bytes.

uint32_t read_fifo ( struct fifo fifo,
uint8_t *  buffer,
uint32_t  size 
)

Read upto the requested number of bytes from the fifo.

Parameters:
fifo The FIFO on which the operation will be performed.
buffer The buffer into which the fifo data will be place.
size The maximum number of bytes to move.
Returns:
The number of bytes moved into the buffer.

int readByte_fifo ( struct fifo fifo,
uint8_t *  data 
)

Read a byte from the fifo.

Attempts to read the next byte from the fifo.

Parameters:
fifo The FIFO on which the operation will be performed.
data Pointer to the location to which the read byte value is written.
Returns:
Zero if the fifo is empty and the read failed, non-zero otherwise.

uint32_t write_fifo ( struct fifo fifo,
const uint8_t *  buffer,
uint32_t  size 
)

Write upto the requested number of bytes into the fifo.

Data is written into the fifo from the supplied buffer. Data at the start of the buffer is written first. Writing will stop if the fifo becomes fall.

Parameters:
fifo The FIFO on which the operation will be performed.
buffer The buffer from which the data will be taken.
size The maximum number of bytes to write into the fifo.
Returns:
The number of bytes written into the fifo.

int writeByte_fifo ( struct fifo fifo,
unsigned char  data 
)

Write one byte to the fifo.

Attempts to write the supplied byte to the fifo.

Parameters:
fifo The FIFO on which the operation will be performed.
data The data to be added to the fifo
Returns:
Zero if the fifo is full and the write failed, non-zero otherwise.


Generated on Sat Aug 12 18:40:55 2006 for Nintendo DS SPI UART Bridge Driver by  doxygen 1.4.7