//===============================================================================
//
//
// T O H O S T F I F O R O U T I N E S
//
//
//===============================================================================
#define Waiting_ToHOST() Buffer_ToHOST[BUFFER_HOST_SIZE-3]
//******************************************************************************
void FlushFIFO_ToHOST(void) // clear FIFO structure (without resetting the data)
//******************************************************************************
{
Buffer_ToHOST[BUFFER_HOST_SIZE-3] = 0; // counter
Buffer_ToHOST[BUFFER_HOST_SIZE-2] = 0; // head
Buffer_ToHOST[BUFFER_HOST_SIZE-1] = 0; // tail
}
//******************************************************************************
void PushFIFO_ToHOST(unsigned char new_data) // push into FIFO one byte
//******************************************************************************
{
unsigned char var_head; // we create temporary variable
var_head = Buffer_ToHOST[BUFFER_HOST_SIZE-2]; // read the head
Buffer_ToHOST[ var_head ] = new_data; // save the data in FIFO head
Buffer_ToHOST[BUFFER_HOST_SIZE-3]++; // increment counter of waiting bytes
if (Buffer_ToHOST[BUFFER_HOST_SIZE-3] > BUFFER_HOST_SIZE-5)
{
Buffer_ToHOST[BUFFER_HOST_SIZE-3] = BUFFER_HOST_SIZE-5; // to avoid overflowing
// when overflow we just don't increment the head
}
else
{
// ---- only when there is no overflow we increment the head
var_head++;
if (var_head > (BUFFER_HOST_SIZE-4)) // uups, overflow of the head, we have to wrap around the head
var_head = 0; // we wrap it around
}
Buffer_ToHOST[BUFFER_HOST_SIZE-2] = var_head; // we return back the head in the array
} // end of PushFIFO routine
//******************************************************************************
unsigned char PopFIFO_ToHOST(void) // pop from FIFO one byte
//******************************************************************************
{
unsigned char var_tail, to_return; // we create temporary variable
var_tail = Buffer_ToHOST[BUFFER_HOST_SIZE-1]; // read the tail
to_return = Buffer_ToHOST[ var_tail ]; // save the data in FIFO head
if (Buffer_ToHOST[BUFFER_HOST_SIZE-3])
{
Buffer_ToHOST[BUFFER_HOST_SIZE-3]--; // decrement by one the counter of waiting bytes
var_tail++;
if (var_tail > (BUFFER_HOST_SIZE-4)) // uups, overflow of the head, we have to wrap around the head
var_tail = 0; // we wrap it around
Buffer_ToHOST[BUFFER_HOST_SIZE-1] = var_tail; // we return back the tail in the array
}
return to_return;
} // end of PopFIFO routine