#include "fifo.h"

uint8_t fifo_push(Fifo_t * fifo, uint8_t byte)
{
  //if (fifo.write >= FIFO_SIZE)
  //  fifo.write = 0; // erhöht sicherheit
  

  if ( ( fifo->write + 1 == fifo->read ) ||
       ( fifo->read == 0 && fifo->write + 1 == FIFO_SIZE ) )
    return FIFO_FAIL; // voll

  fifo->data[fifo->write] = byte;

  fifo->write++;
  if (fifo->write >= FIFO_SIZE)
    fifo->write = 0;

  return FIFO_SUCCESS;
}

uint8_t fifo_pop(Fifo_t * fifo, uint8_t *pByte)
{
  if (fifo->read == fifo->write){
    return FIFO_FAIL;
  }

  *pByte = fifo->data[fifo->read];

  fifo->read++;
  if (fifo->read >= FIFO_SIZE)
    fifo->read = 0;

  return FIFO_SUCCESS;
}

uint8_t fifo_peek(Fifo_t * fifo){
    return fifo->data[fifo->read];
}
