/// \file buffer.h
/// \brief byte buffers used for UARTS
#ifndef BUFFER_H
#define BUFFER_H
/// FIFO buffers with no rollover(if full new bytes are tossed out)
struct ByteBuffer_s{        
    volatile unsigned char* data;   ///<memory location of buffer
    volatile int head;              ///<position of newest byte
    volatile int tail;              ///<position of oldest byte
    int ptr_mask;                   ///<mask for rollover checks
}

;
/// typedef that struct
typedef struct ByteBuffer_s ByteBuffer;

/// @brief add a byte to a buffer
/// @param b Byte to be added
/// @param buff buffer to add to
/// @return FALSE if buffer is full, else TRUE

int bufPut(unsigned char b, ByteBuffer* buff);  

/// @brief remove a byte from a buffer
/// @param b [out] place for removed byte
/// @param buff  buffer to remove from
/// @return FALSE if buffer is empty

int bufGet(unsigned char* b, ByteBuffer* buff); 

/// @brief clear out a buffer reset head and tail
/// @param buff  buffer to clear

void bufClear(ByteBuffer* buff);    

/// @brief find out if a buffer is full
/// @param buff buffer to check on
/// @return TRUE if full, otherwise FALSE

int bufIsFull(ByteBuffer* buff); 

/// @brief find out if a buffer is empty
/// @param buff Buffer to check on
/// @return TRUE if nothing in buffer, otherwise FALSE

int bufIsEmpty(ByteBuffer* buff);   

/// @brief find out how many bytes in a buffer
/// @param buff Buffer to check on
/// @return number of bytes in buffer

int bufContains(ByteBuffer* buff); 
#endif