/*  ============================================================================
 *  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_dmaxHwSetupFifoParam.c
 *
 *  @brief File for functional layer of CSL API @a CSL_dmaxHwSetupFifoParam()
 *
 *  Description
 *    - The @a CSL_dmaxHwSetupFifoParam() 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_dmaxSetupGeneralXFRParameterEntry
 *
 *   @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  = 0x10000100;
      hwSetup.dstReloadAddr0  = 0x20000100;
      .
      .
      hwSetup.count0        = 3;
      hwSetup.count1		= 4;
      hwSetup.count2		= 2;
    
      CSL_dmaxHwSetupGenXFRParamEntry (paramEntry, cc, &hwSetup);
     @endverbatim
 * 
 * ============================================================================
 */
#pragma CODE_SECTION (CSL_dmaxSetupGeneralXFRParameterEntry, \
											".text:csl_section:dmax");

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

    st = CSL_SOK;
    /*
     * The src/dstReloadAddr0 address (for general purpose transfers) 
     * values are copied into BOTH the reload address registers AND the 
     * active address registers.    
     */
    tmpPtr[0] = setup->srcReloadAddr0;
    tmpPtr[1] = setup->dstReloadAddr0;

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

    if (st == CSL_SOK) {
        tmpPtr[2] = val;
        tmpPtr[3] = CSL_FMK (DMAX_GENERAL_SRCINDEX0, setup->srcIndex0) |
            CSL_FMK (DMAX_GENERAL_DSTINDEX0, setup->dstIndex0);
        tmpPtr[4] = CSL_FMK (DMAX_GENERAL_SRCINDEX1, setup->srcIndex1) |
            CSL_FMK (DMAX_GENERAL_DSTINDEX1, setup->dstIndex1);
        tmpPtr[5] = CSL_FMK (DMAX_GENERAL_SRCINDEX2, setup->srcIndex2) |
            CSL_FMK (DMAX_GENERAL_DSTINDEX2, setup->dstIndex2);
        tmpPtr[6] = val;
        tmpPtr[7] = setup->srcReloadAddr0;
        tmpPtr[8] = setup->dstReloadAddr0;
        tmpPtr[9] = setup->srcReloadAddr1;
        tmpPtr[10] = setup->dstReloadAddr1;
    }
    return st;
}
