/*  ============================================================================
 *  Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
 *
 *  Use of this software is controlled by the terms and conditions found in the
 *  license agreement under which this software has been supplied.
 *  ===========================================================================
 */

/** @file csl_dmaxHwSetupGpParam.c
 *
 *  @brief File for functional layer of CSL API @a CSL_dmaxGetHwSetupGenXFRParamEntry()
 *
 *  Description
 *    - The @a CSL_dmaxHwSetupGenXFRParamEntry() function definition & it's associated
 *      functions
 *
 *  Modification 1
 *    - Modified on: 11/March/2005
 *    - Reason: created the sources
 * 
 *  @author asr.
 */

#include <csl_dmax.h>
/** =======================================================================
 *   @n@b CSL_dmaxGetHwSetupGenXFRParamEntry
 *
 *   @b Description
 *   @n This function formats the parameter table entry for a General Purpose
 *      transfer.
 *   @a CSL_dmaxHwSetup.
 *
 *   @b Arguments
 *   @verbatim
 *    
 *          paramEntry  Pointer to Prameter Table Entry where data is to be stored.
 *
 *			cc			Counter configuration.
 *
 *          setup  		Pointer to a dmax General Purpose Transfer Object.
 *           
 *   @endverbatim
 *
 *   <b> Return Value </b>  CSL_Status
 *   @li                    CSL_SOK - Successful completion of hardware     
 *                                    setup
 *   @li                    CSL_ESYS_ INVPARAMS - Hardware structure is not properly 
 *                                    initialized
 *   @li                    CSL_ESYS_ BADHANDLE - Invalid CSL handle
 *
 *
 *   <b> Pre Condition </b>
 *   @n  Both CSL_dmaxInit() and a CSL_dmaxOpen() must be called
 *
 *   <b> Post Condition </b>
 *   @n  DMAX registers are configured 
 *
 *   @b  Modifies
 *   @n  DMAX registers
 *
 *   @b Example
 *   @verbatim  
      CSL_DmaxParameterEntry 		paramEntry;
      Uint8							cc;
      CSL_DmaxGPXFRParameterSetup 	hwSetup;
      
    hwSetup.srcReloadAddr0  = paramEntry[0];
    .
    .
    hwSetup.dstReloadAddr0 	= paramEntry[1];
    
      CSL_dmaxGetHwSetupGenXFRParamEntry(paramEntry, cc, &hwSetup);
     @endverbatim
 * 
 * ============================================================================
 */
#pragma CODE_SECTION (CSL_dmaxGetHwSetupGenXFRParamEntry, ".text:csl_section:dmax");

CSL_Status CSL_dmaxGetHwSetupGenXFRParamEntry (
    CSL_DmaxParameterEntry 		*paramEntry,
    Uint8 						cc,
    CSL_DmaxGPXFRParameterSetup *setup
)
{
    CSL_Status	st;
    Uint32		*tmpPtr = (Uint32 *) paramEntry;

    st = CSL_SOK;
    setup->srcReloadAddr0 = tmpPtr[0];
    setup->dstReloadAddr0 = tmpPtr[1];

    switch (cc) {
	    case 0:
	        {
	            setup->count0 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT0_CC00);
	            setup->count1 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT1_CC00);
	            setup->count2 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT2_CC00);
	            break;
	        }
	
	    case 1:
	        {
	            setup->count0 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT0_CC01);
	            setup->count1 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT1_CC01);
	            setup->count2 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT2_CC01);
	            break;
	        }
	
	    case 2:
	        {
	            setup->count0 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT0_CC10);
	            setup->count1 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT1_CC10);
	            setup->count2 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT2_CC10);
	            break;
	        }
	
	    case 3:
	        {
	            setup->count0 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT0_CC11);
	            setup->count1 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT1_CC11);
	            setup->count2 = CSL_FEXT (tmpPtr[2], DMAX_GENERAL_COUNT2_CC11);
	            break;
	        }
	
	    default:
	        st = CSL_ESYS_OVFL;
    }

    if (st == CSL_SOK) {

        setup->srcIndex0 = CSL_FEXT (tmpPtr[3], DMAX_GENERAL_SRCINDEX0);
        setup->dstIndex0 = CSL_FEXT (tmpPtr[3], DMAX_GENERAL_DSTINDEX0);

        setup->srcIndex1 = CSL_FEXT (tmpPtr[4], DMAX_GENERAL_SRCINDEX1);
        setup->dstIndex1 = CSL_FEXT (tmpPtr[4], DMAX_GENERAL_DSTINDEX1);

        setup->srcIndex2 = CSL_FEXT (tmpPtr[5], DMAX_GENERAL_SRCINDEX2);
        setup->dstIndex2 = CSL_FEXT (tmpPtr[5], DMAX_GENERAL_DSTINDEX2);

        setup->srcReloadAddr0 = tmpPtr[7];
        setup->dstReloadAddr0 = tmpPtr[8];
        setup->srcReloadAddr1 = tmpPtr[9];
        setup->dstReloadAddr1 = tmpPtr[10];
    }
    return st;
}
