/*********************************  fifos.h  *********************************
 * $Source: /home/cvs/ESP/gen2/software/msp430/lib/common/fifos.c,v $
 *  Copyright (C) 2003 MBARI
 *
 *  MBARI Proprietary Information. All rights reserved.
 * $Id: fifos.c,v 1.2 2004/06/11 23:58:55 brent Exp $
 *
 * Efficient Byte oriented FIFO primitives
 *
 *****************************************************************************/

#include "fifos.h"


byte *FIFOaddBlock (fifo *r, byte *src, byte *dst, unsigned len)
/*
  append len byte block to FIFO at specified tail dst
  returns new tail
  Assumes that len > 0 and that the block will fit in the fifo
*/
{
  do {
    unsigned chunkLen = FIFOpoke(r);
    if (chunkLen > len) chunkLen = len;
    dst = FIFOaddChunk (r, src, dst, chunkLen);
    src += chunkLen;
    len -= chunkLen;
  } while (len);
  return dst;
}
  

byte *FIFOreadBlockAhead (fifo *r, byte *src, byte *dst, unsigned len)
/*
   move len bytes of src, the specified head of fifo r, to dst
   without verifying that there really is that much in the fifo. See FIFOpeek.
   assumes len is > 0
   returns new head
*/
{
  do {
    unsigned chunkLen = FIFOpeek(r);
    if (chunkLen > len) chunkLen = len;
    src = FIFOreadChunkAhead (r, src, dst, chunkLen);
    dst += chunkLen;     
    len -= chunkLen;
  } while (len);
  return src;
}

