/*  ============================================================================
 *   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_dmaxHwControl.c
 *
 *    @brief    File for functional layer of CSL API @a CSL_dmaxHwControl()
 *
 *  Description
 *    - The @a CSL_dmaxHwControl() function definition & it's associated
 *      functions
 *
 *  Modification 1
 *    - Modified on: 1/Mar/2005
 *    - Reason: created the sources
 *
 *    @author asr.
 */


#include <csl_dmax.h>
#include <csl_dmaxAux.h>

/** ============================================================================
 *   @n@b CSL_dmaxHwControl
 *
 *   @b Description
 *   @n Takes a command of DMAX with an optional argument and implements it.
 *
 *   @b Arguments
 *   @verbatim
 * 
 *          hDmax       Handle to the DMAX instance 
 *          cmd         The command to this API indicates the action to be
 *                      taken on DMAX. 
 *          arg         An optional argument.

 *   @endverbatim
 *
 *   <b> Return Value </b>  CSL_Status
 *   @li         CSL_SOK               - Status info return successful.
 *   @li         CSL_ESYS_BADHANDLE    - Invalid handle
 *   @li         CSL_ESYS_INVCMD       - Invalid command
 *   @li         CSL_ESYS_INVPARAMS    - Invalid parameter
 *
 *   <b> Pre Condition </b>
 *   @n  dmax opened properly
 *
 *   <b> Post Condition </b>
 *   @n  Device register programmed accordingly
 *
 *   @b Modifies
 *   @n The hardware registers of DMAX.
 *
 *   @b Example
 *   @verbatim
        CSL_DmaxHandle         hDmax;
        CSL_DmaxHwControlCmd   cmd;
        void*                  arg;

        status = CSL_dmaxHwControl (hDmax, cmd, &arg);

     @endverbatim
 * =============================================================================
 */

#pragma CODE_SECTION (CSL_dmaxHwControl, ".text:csl_section:dmax");

CSL_Status CSL_dmaxHwControl (
    CSL_DmaxHandle 			hDmax,
    CSL_DmaxHwControlCmd 	cmd,
    void 					*arg
)
{
    CSL_Status	status = CSL_SOK;

    if (hDmax == NULL)
        return CSL_ESYS_BADHANDLE;

    switch (cmd) {
	    case CSL_DMAX_CMD_SETPRIORITY:
	        CSL_dmaxSetPriority (hDmax, arg);
	        break;
	
	    case CSL_DMAX_CMD_SETPOLARITY:
	        CSL_dmaxSetPolarity (hDmax, arg);
	        break;
	
	    case CSL_DMAX_CMD_EVENTENABLE:
	        CSL_dmaxEventEnable (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_CLEARTCC:
	        CSL_dmaxClearTcc (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_EVENTDISABLE:
	        CSL_dmaxEventDisable (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_CLEAREVENTENTRY:
	        CSL_dmaxClearEventEntry (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_CLEARPARAMENTRY:
	        CSL_dmaxClearParameterEntry (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_STARTASYNCTRANSFER:
	        CSL_dmaxStartAsyncTransfer (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_CLEARFIFOSTATUS:
	        CSL_dmaxClearFifoStatus (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_WATERMARK_ENABLE:
	        CSL_dmaxWatermarkEnable (hDmax);
	        break;
	
	    case CSL_DMAX_CMD_WATERMARK_DISABLE:
	        CSL_dmaxWatermarkDisable (hDmax);
	        break;
	
	    default:
	        status = CSL_ESYS_INVCMD;
	        break;
    }

    return status;
}
