class::hal::Fifo

class hal::Fifo
  : public hal::Device

The Fifo class connects to Fifo devices which can be used for:

  • Inter-process communication
  • Buffering serial I/O from SPI, I2S, USB, etc

For example, the default STDIO is implemented as two fifo buffers: one for input and one for output. A typical application will write the STDOUT fifo while the USB protocol will read the fifo and display it on the screen. Alternatively, a separate application or the kernel could read the STDOUT and print it on a display or send it out the UART.

Fifo’s can be opened in blocking and non-blocking modes when both reading and writing. If Fifo::set_writeblock() is called, a write will block when the Fifo is full. Otherwise, the Fifo will overflow and FifoInfo::is_overflow() will return true.

#include <cstdio>
#include <sapi/hal.hpp>

Fifo fifo;
FifoInfo attr;

if( fifo.open("/dev/fifo", Fifo::RDWR) < 0 ){
   perror("failed to open fifo");
}

if( fifo.attr().used() > 0){
   //fifo is not empty
}

//write some data to the fifo
fifo.write("Testing fifo write\n");

fifo.close();

Summary

Fifo()

int finalize() const

int flush() const

int get_info(

FifoInfo & info
) const

FifoInfo get_info() const

int initialize() const

int set_writeblock(

bool value
) const

enum fifo_flags

Members

Fifo()

int finalize() const

int flush() const

Flushes the FIFO.


int get_info(

FifoInfo & info
) const

Reads the Fifo Attributes.


FifoInfo get_info() const

Returns the fifo info.


int initialize() const

Initialize the FIFO. This function should only be called once even if several contexts access the FIFO.

Returns

Less than zero for an error.


int set_writeblock(

bool value
) const

Sets the FIFO in write block mode.

Parameters

  • value True to enable write block or false to disable it

If write blocking is enabled, the FIFO will block (or return EAGAIN is O_NONBLOCK is on) if no bytes can be written to the FIFO. If a single byte can be written, write() will return 1.

With write blocking disable, write() will never block. It will simply overwrite the data that is already in the FIFO.


enum fifo_flags
  • SET_WRITEBLOCK
  • IS_OVERFLOW
  • IS_NOTIFY_WRITE
  • IS_NOTIFY_READ
  • INIT
  • EXIT
  • FLUSH

X

Thanks for Coming!

Subscribe to news and updates