Exemple #1
0
uint8_t fifoPush(FIFO *fifo, uint8_t data){
	if(fifoIsFull(fifo)){	/*FIFO full*/
		return -1;
	}
	
	fifo->buffer[fifo->tail] = data;
	fifo->tail++;
	if(fifo->tail == fifo->size){
		fifo->tail = 0;
		fifo->r ++;
	}
	return 0;
}
/**--------------------------------------------------------------------------------------------------
  Name         :  fifoWrite.
  Description  :  Function to add a char to the buffer.
			   :  \note Before calling this function, user is responsable for checking in a loop if provided buffer is not full.
			   :  \example 
				  while( fifoFull(buffer) );
				  fifoWrite(buffer,'c');
  Argument(s)  :  Pointer to a fifoType buffer, character to add
  Return value :  0 - success; 1 - Buffer Full.
--------------------------------------------------------------------------------------------------**/
int8_t fifoWrite(fifoType * buffer, int8_t character)
{
	if ( !fifoIsFull(buffer) )
	{
		buffer->data[buffer->fempty] = character;
		buffer->fempty = (buffer->fempty + 1) % buffer->size;
		return 0; // return success
	}
	else
	{
        return -1; // return -1 if Buffer Full
	}
}
u8_t fifoPushElem(fifo_t* fifo, void* data)
{
	void* destAddr;
    CHECK_FIFO_NULL(fifo);
    if (fifoIsFull(fifo) == 0x01)
       return 0;
     
    destAddr = (u8_t*)fifo->buffer + fifo->head * fifo->elemSize;
    *((u32_t*)destAddr) = (u32_t)data;
    fifo->head++;
    if (fifo->head == fifo->size)
       fifo->head = 0;

    return 1;
}