/*!**************************************************************************
*!                                                            
*! FILE NAME  : dmadescr.h
*!                                                            
*! DESCRIPTION: 
*!                                                            
*! FUNCTIONS  : None.
*! (EXPORTED)
*!                                                            
*!---------------------------------------------------------------------------
*! HISTORY                                                    
*!                                                            
*! DATE         NAME               CHANGES                       
*! ----         ----               -------                       
*! Feb 16 1998  Pontus Soderstrom  Initial version.
*!
*!---------------------------------------------------------------------------
*!
*! (C) Copyright 1998, Axis Communications AB, LUND, SWEDEN
*!
*!**************************************************************************/
/* %Z% %M% %I% %G% */

/********************** INCLUDE FILES SECTION ******************************/
#ifndef _DMA_DECR_H
#define _DMA_DESCR_H

#include "compiler.h"

/********************** CONSTANT AND MACRO SECTION *************************/
#define RESET_DMA( n ) \
  *R_DMA_CH##n##_CMD = IO_STATE( R_DMA_CH0_CMD, cmd, reset )

#define WAIT_RESET_DMA( n ) \
  while( (*R_DMA_CH##n##_CMD & IO_MASK( R_DMA_CH0_CMD, cmd )) != \
         IO_STATE( R_DMA_CH0_CMD, cmd, hold ) )

#define DESCR( buf, len, next, flags ) \
{ len, flags, 0, next, buf, 0, 0, 0 }

#define START_DMA( n, desc ) \
  *R_DMA_CH##n##_FIRST = (udword) desc; \
  *R_DMA_CH##n##_CMD   = IO_STATE( R_DMA_CH0_CMD, cmd, start )
    
#define APPEND_DESCR( n, old_last, new_first ) \
  old_last->next = new_first; \
  old_last->flags &= ~d_eol; \
  *R_DMA_CH##n##_CMD = IO_STATE( R_DMA_CH0_CMD, cmd, restart )

#define HOLD_DMA( n ) \
  *R_DMA_CH##n##_CMD = IO_STATE( R_DMA_CH0_CMD, cmd, hold )

#define CONTINUE_DMA( n ) \
  *R_DMA_CH##n##_CMD = IO_STATE( R_DMA_CH0_CMD, cmd, continue )

#define DMA_INT_CLR( n ) \
  *R_DMA_CH##n##_CLR_INTR = \
    ( IO_STATE( R_DMA_CH0_CLR_INTR, clr_eop, do ) | \
      IO_STATE( R_DMA_CH0_CLR_INTR, clr_descr, do ) )
    
#define FORCE_EOP( n ) \
  (*R_SET_EOP = (1 << ((n - 3) / 2)))

/********************** TYPE DEFINITION SECTION ****************************/
        
typedef struct dma_descr {
  uword             sw_len;   /* Allocated length of data buffer buf.   */
  byte              flags;    /* Control information to DMA and IO-If.  */
  byte              unused;
  struct dma_descr *next;     /* Link to next descriptor in list.       */
  void             *buf;      /* Data buffer.                           */
  uword             hw_len;   /* How much data DMA read or wrote in buf */
  byte              status;   /* What happened during the transfer.     */
  byte              fifo_len; /* How much data is in the FIFO.          */
} dma_descr;

enum {                    /* Available in:  */
  d_eol      = (1 << 0),  /* flags          */
  d_eop      = (1 << 1),  /* flags & status */
  d_wait     = (1 << 2),  /* flags          */
  d_int      = (1 << 3),  /* flags          */
  d_txerr    = (1 << 4),  /* flags          */
  d_stop     = (1 << 4),  /*         status */
  d_ecp      = (1 << 5),  /* flags & status */
  d_pri      = (1 << 5),  /* flags & status */
  d_alignerr = (1 << 6),  /*         status */
  d_crcerr   = (1 << 7)   /*         status */
};

#endif

/********************** END OF FILE dmadescr.h *****************************/



