/*****************************************************************************
Copyright (c) 2006 Analog Devices.  All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  
******************************************************************************

$File: fifo.h $
$Revision: 1.1 $
$Date: 2008/03/17 14:50:34 $

Project:    Audio Kit
Title:      FIFO
Author(s):  dwu
Revised by:

Description:
		This module implements a FIFO.

*********************************************************************************			
	
Modification History:
====================
$Log: fifo.h,v $
Revision 1.1  2008/03/17 14:50:34  gstephan
Updates for SDK 3.00

Revision 1.1  2007/05/22 18:24:37  gstephan
Creating VDSP 5.00 release folder.  Created from the head copy of
VDSP 4.50 release folder.

Revision 1.1  2006/11/10 05:00:09  randreol
Initial rev

Revision 1.1.1.1  2006/05/09 04:01:29  dwu
USB based audio demonstration


	
*********************************************************************************/

#ifndef FIFO__H
#define FIFO__H

// Maximum number of buffers to use for FIFO
#define MAX_NUM_BUFFERS 32

// Configuration identifiers
typedef enum {
	FIFO_CONFIG_SETBUFFER
} CONFIG_ENUM;

// Buffer structure for holding the information about each buffer in FIFO
typedef struct {
	char *buf_start;				// start address of the buffer
	char *rd_ptr;					// current read pointer
	char *wr_ptr;					// current write pointer
	long buf_size;					// buffer size in bytes
	long byte_count;				// number of data bytes in buffer
	volatile unsigned long flags;	// read/write flags
} BUFFER_INFO_STRUCT;


// FIFO structure
typedef struct {
	BUFFER_INFO_STRUCT buffer_list[MAX_NUM_BUFFERS];	// buffer list
	unsigned long buffer_count;		// Number of buffers available
	unsigned long write_buffer;		// buffer index for write
	unsigned long read_buffer;		// buffer index for read
	unsigned long free_buffers;		// number of free buffers for write
} FIFO_STRUCT;


// Function declarations

// Reset function
void FIFO_Reset(FIFO_STRUCT *fifo_obj);
// Configuration function
int FIFO_Configure(FIFO_STRUCT *fifo_obj,CONFIG_ENUM config_item,int param1,int param2);
// Function to get a block of memory to write data into FIFO
char* FIFO_GetFreeWriteBlock(FIFO_STRUCT *fifo_obj,unsigned long block_size);
// Function to set the number of data bytes written into the FIFO
void FIFO_SetDataCount(FIFO_STRUCT *fifo_obj,unsigned long data_count);
// Function to read a number of data bytes into dst
unsigned long FIFO_ReadDataBlock(FIFO_STRUCT *fifo_obj,unsigned long bytes_to_read,char *dst);
// Set the current write buffer for read
void FIFO_SetRDFlag(FIFO_STRUCT *fifo_obj);


extern void CopyFifoToDACbuf(char *pSrc, char *pDest,unsigned long num_of_bytes);

#endif // #ifndef FIFO__H

