
#include <std.h>
#include <pip.h>
#include <log.h>
#include <trc.h>
#include <clk.h>

#include "dss.h"
#include "dss_priv.h"


#ifdef _EDMA_
#include <csl_cache.h>
#endif

Int     DSS_error = 0;

Int     DSS_rxCnt = 0;
Int     DSS_txCnt = 0;

Int     *DSS_rxPtr = NULL;
Int     *DSS_txPtr = NULL;

DSS_Obj DSS_config = {
        0                       /*  enable tracing */
};







    /* Reset McBsp then enable Transmit and Receive bits */
    MCBSP_RSETH(DSS_hMcbsp0, SPCR, 0x0);
    MCBSP_enableRcv(DSS_hMcbsp0);
    MCBSP_enableXmt(DSS_hMcbsp0);
    
    
    
    
    /*
 *  ======== DSS_dmaInit ========
 *  Initialise EDMA Controller
 */
Void DSS_dmaInit(Void)
{
    LOG_message("DSS_dmaInit(): %u", CLK_gethtime());

    /* General EDMA Initialization */
    EDMA_RSET(EER, 0x0000);     /* Disable all events */
    EDMA_RSET(ECR, 0xffff);     /* Clear all pending events */
    EDMA_RSET(CIER, 0x0000);    /* Disable all events to Interrupt */
    EDMA_RSET(CIPR, 0xffff);    /* Clear all pending Queued EDMA ints */

    /* Enable Rx/Tx DMA Complete Interrupts to the CPU */
    EDMA_RSET(CIER, DSS_RXDONE | DSS_TXDONE);
}





/*
 *  ======= DSS_dmaRxStart ========
 */
Void DSS_dmaRxStart(Void *dst, Int nsamps)
{
    LOG_message("DSS_dmaRxstart(): %u", CLK_gethtime());
    
    CACHE_clean(CACHE_L2, dst, nsamps);

    /* Reconfig EDMA channel for next receive buffer */
    EDMA_RSETH(DSS_hEdmaRint0, CNT, (Uns) nsamps);
    EDMA_RSETH(DSS_hEdmaRint0, DST, (Uns) dst);

    EDMA_RSET(EER, 0x3000);     /* Enable McBSP0 Rx/Tx Events to the DMA */
}

/*
 *  ======= DSS_dmaTxStart ========
 */
Void DSS_dmaTxStart(Void *src, Int nsamps)
{
    static Int startup = 1;

    LOG_message("DSS_dmaTxstart(): %u", CLK_gethtime());
    
    CACHE_flush(CACHE_L2, src, nsamps);

    if (startup) {
        startup = 0;
        DSS_spWrite(0); DSS_spWrite(0);
        /* EDMA_RSET(ECR, 0x3000);    /Clear any previous McBSP Events */
    }

    /* Reconfig EDMA channel for next transmit buffer */
    EDMA_RSETH(DSS_hEdmaXint0, SRC, (Uns) src);
    EDMA_RSETH(DSS_hEdmaXint0, CNT, (Uns) nsamps);

    EDMA_RSET(EER, 0x3000);     /* Enable McBSP0 Rx/Tx Events to the DMA */
}



