

/*-----------------------------------------------------------------------*/
/*  These are the include files that are needed for edma/qdma.           */
/*-----------------------------------------------------------------------*/

#include "csl_edma.h"
#include "cslr_edmacc.h"
#include "eve.h"    
#include "tistdtypes.h"


/*-----------------------------------------------------------------------*/
/*  We define an enumerated data type that tells us whether this is an   */
/*  EDMA channel or a qdma channel.                                      */
/*-----------------------------------------------------------------------*/

typedef enum chan_attr
{
    EDMA_CHAN,
    QDMA_CHAN
}DMA_Chan_Attr;

/*-----------------------------------------------------------------------*/
/*  This is the number of logical channels that we need for this test    */
/*-----------------------------------------------------------------------*/

#define NUM_CHANNELS    2
#define NUM_EEVTS       16
#define NUM_QEVTS        8
#define NUM_TCCS        16
#define NUM_PRMS        57    // include space for 6 consecutive params
#define NUM_QUES         2


unsigned int ed_pack2 (unsigned short hi, unsigned short lo);


typedef struct dma_state_struct
{
    unsigned int              physical_chan[NUM_CHANNELS];
    unsigned int              tcc_val[NUM_CHANNELS];
    unsigned int              que_no [NUM_CHANNELS];
    unsigned int              region_no[NUM_CHANNELS];
    volatile unsigned int     *trig_param[NUM_CHANNELS];
    volatile unsigned int     *base_param[NUM_CHANNELS];
    volatile unsigned int     num_param[NUM_CHANNELS];
    unsigned int              num_channels;
    DMA_Chan_Attr             dma_attr[NUM_CHANNELS]; 
    Bool                      *trf_pend[NUM_CHANNELS];
    unsigned int              *int_mem_ptr;
    unsigned int               int_mem_size;
    volatile unsigned int      dchmap[NUM_CHANNELS];
    volatile unsigned int      qchmap[NUM_CHANNELS];
    volatile unsigned int      dmaqnum[NUM_CHANNELS];
    volatile unsigned int      qdmaqnum;
    volatile unsigned int      trig_word[NUM_CHANNELS];
    volatile unsigned int      drae[NUM_CHANNELS];
    volatile unsigned int      qrae[NUM_CHANNELS];
    volatile unsigned int      que_tc_map;
    volatile unsigned int      que_pri;
    volatile unsigned int      qeer;
    volatile unsigned int      eer;
    volatile unsigned int      eerh;
}DMA_State_Struct;

void ed_dma_assign_channels
(
    unsigned int    *evt_no, 
    unsigned int    *tcc_no, 
    unsigned int    *que_no, 
    unsigned int    *reg_no, 
    DMA_Chan_Attr   dma_attr,
    unsigned int    num_channels
);




void ed_dma_state_struct_populate
(
    CSL_EdmaccRegsOvly         edma_cc,
    DMA_State_Struct           *dma_state_struct,
    unsigned int               *evt_no,
    unsigned int               *tcc_no,
    unsigned int               *reg_no,
    unsigned int               *que_no,
    unsigned int               num_param,
    unsigned int               num_channels,
    DMA_Chan_Attr              dma_attr,
    Bool                       *trf_pend
);

void ed_params_2d_to_1d_eve
(
    DMA_State_Struct    *dma_state_struct, 
    unsigned int        chan_no, 
    unsigned int        opt_word, 
    unsigned char       *src_ptr, 
    unsigned char       *dst_ptr, 
    unsigned int        no_bytes, 
    unsigned int        no_lines, 
    unsigned int        line_pitch, 
    unsigned int        next_blk_offset,
    unsigned int        num_auto_incr
);

void ed_params_1d_to_2d_eve
(
    DMA_State_Struct    *dma_state_struct, 
    unsigned int        chan_no, 
    unsigned int        opt_word, 
    unsigned char       *src_ptr, 
    unsigned char       *dst_ptr, 
    unsigned int        no_bytes, 
    unsigned int        no_lines, 
    unsigned int        line_pitch, 
    unsigned int        next_blk_offset,
    unsigned int        num_auto_incr
);


void ed_params_2d_to_1d_link_eve
(
    DMA_State_Struct    *dma_state_struct, 
    unsigned int        chan_no,
    unsigned int        tparam_offset, 
    unsigned int        opt_word, 
    unsigned char       *src_ptr, 
    unsigned char       *dst_ptr, 
    unsigned int        no_bytes, 
    unsigned int        no_lines, 
    unsigned int        line_pitch, 
    unsigned int        link_addr
);



void ed_dma_global_regs_setup
(
    CSL_EdmaccRegsOvly  edma_cc,
    DMA_State_Struct   *dma_state_struct
);

void ed_dma_global_regs_teardown
(
    CSL_EdmaccRegsOvly  edma_cc,
    DMA_State_Struct   *dma_state_struct
);
