⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csl_edma.c

📁 Dm6455 driver,magbe useful to you!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ===========================================================================
 *   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_edma.c
 *
 *  @path $(CSLPATH)\src\edma
 *
 *  @brief File for functional layer of CSL API 
 *
 */

/*****************************************************************************\
* FILENAME...... csl_edma.c
* DATE CREATED.. 06/11/1999
* LAST MODIFIED. 16-SEP-2005 Changes according to the review comments
* LAST MODIFIED. 04-AUG-2005 Beautified and added a EDMA instance structure
*                25/05/2005 Modified to support the spec EDMA 3.0.2 and to use
*                           the CSL 3.x internally
*                08/13/2004 Modified tccAllocTable type from static to global. 
*                06/17/2003 Added support for 6712C
*                05/28/2003 Added support for 6711C
*                12/05/2000

\*****************************************************************************/
#define _EDMA_MOD_
#include <csl_edma2.h>

extern far Uint32 _lmbd (Uint32 src1, Uint32 src2
);

/*****************************************************************************\
*                         L O C A L   S E C T I O N
\*****************************************************************************/


/*****************************************************************************\
* static macro declarations
\*****************************************************************************/
#define _EDMA_OPT_PRI_MASK       0xE0000000
#define _EDMA_OPT_PRI_SHIFT      29

#define _EDMA_OPT_ESIZE_MASK     0x18000000
#define _EDMA_OPT_ESIZE_SHIFT    27

#define _EDMA_OPT_2DS_MASK       0x04000000
#define _EDMA_OPT_2DS_SHIFT      26

#define _EDMA_OPT_SUM_MASK       0x03000000
#define _EDMA_OPT_SUM_SHIFT      24

#define _EDMA_OPT_2DD_MASK       0x00800000
#define _EDMA_OPT_2DD_SHIFT      23

#define _EDMA_OPT_DUM_MASK       0x00600000
#define _EDMA_OPT_DUM_SHIFT      21

#define _EDMA_OPT_TCINT_MASK     0x00100000
#define _EDMA_OPT_TCINT_SHIFT    20

#define _EDMA_OPT_TCC_MASK       0x000F0000
#define _EDMA_OPT_TCC_SHIFT      16

#define _EDMA_OPT_TCCM_MASK      0x00006000
#define _EDMA_OPT_TCCM_SHIFT     13

#define _EDMA_OPT_ATCINT_MASK    0x00001000
#define _EDMA_OPT_ATCINT_SHIFT   12

#define _EDMA_OPT_ATCC_MASK      0x000007E0
#define _EDMA_OPT_ATCC_SHIFT     5

#define _EDMA_OPT_PDTS_MASK      0x00000008
#define _EDMA_OPT_PDTS_SHIFT     3

#define _EDMA_OPT_PDTD_MASK      0x00000004
#define _EDMA_OPT_PDTD_SHIFT     2

#define _EDMA_OPT_LINK_MASK      0x00000002
#define _EDMA_OPT_LINK_SHIFT     1

#define _EDMA_OPT_FS_MASK        0x00000001
#define _EDMA_OPT_FS_SHIFT       0


#define _EDMA_RLD_LINK_MASK      0x0000FFFF
#define _EDMA_RLD_LINK_SHIFT     0

#define _EDMA_RLD_ELERLD_MASK    0xFFFF0000
#define _EDMA_RLD_ELERD_SHIFT    16

#define _EDMA_CNT_FRMCNT_MASK    0xFFFF0000
#define _EDMA_CNT_FRMCNT_SHIFT   16

#define _EDMA_CNT_ELECNT_MASK    0x0000FFFF
#define _EDMA_CNT_ELECNT_SHIFT   0

#define _EDMA_IDX_FRMIDX_MASK    0xFFFF0000
#define _EDMA_IDX_FRMIDX_SHIFT   16

#define _EDMA_IDX_ELEIDX_MASK    0x0000FFFF
#define _EDMA_IDX_ELEIDX_SHIFT   0

/*****************************************************************************\
* static typedef declarations
\*****************************************************************************/


/*****************************************************************************\
* static function declarations
\*****************************************************************************/


/*****************************************************************************\
* static variable definitions
\*****************************************************************************/
static Uint32 allocMaskCL = 0x00000000;
static Uint32 allocMaskCH = 0x00000000;

static Uint32 allocMaskT[(Uint32) ((EDMA_TABLE_CNT -
            1) / (sizeof (Uint32) * 8)) + 1] = { 0, 0, 0, 0, 0, 0 };


/*****************************************************************************\
* static function definitions
\*****************************************************************************/

/*****************************************************************************\
*                        G L O B A L   S E C T I O N
\*****************************************************************************/


/*****************************************************************************\
* global variable definitions
\*****************************************************************************/
Uint8 tccAllocTable[EDMA_CHA_CNT] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

/* Objects needed to maintain the 3x data */
EDMA_Wrapper_Data EDMA_Wrapper_Data_Objs[EDMA_CHA_CNT];

/* A global structure to maintain the EDMA object instance */
CSL_Edma3Obj edmaObj = {
    (CSL_Edma3ccRegsOvly)CSL_EDMA3CC_0_REGS,
    CSL_EDMA3
};

/*****************************************************************************\
* global function definitions
\*****************************************************************************/
/** 
 * ============================================================================
 *   @n@b EDMA_reset
 *
 *   @b Description
 *   @n Resets the given DMA channel.
 *
 *   @b Arguments
 *   @verbatim
       hEdma      Handle to the channel to be reset

     @endverbatim
 *
 *   <b> Return Value </b>
 *   @n  None
 *
 *   <b> Pre Condition </b>
 *   @n  Channel must have been opened, previously.
 *
 *   <b> Post Condition </b>
 *   @li 1. The corresponding PaRAM entry is cleared to 0.
 *   @li 2. The channel is disabled and event register bit is cleared.
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *
 *   @b Example
 *   @verbatim
     EDMA_handle handle;
     Uint32 chan_no = 1;
     handle = EDMA_open(chan_no, EDMA_OPEN_RESET);
      ...
     EDMA_reset(handle);
      ...
     @endverbatim
 * ============================================================================
 */
void EDMA_reset (
    EDMA_Handle    hEdma
)
{
    Uint32 gie;
    CSL_Edma3ParamSetup config = { 0 };
    gie = _disable_interrupts ();

    if (hEdma != EDMA_HINV) {
        if (_EDMA_CHANNEL_NUMBER (hEdma) < EDMA_CHA_CNT) {
            /* Clear event enable bit  */
            CSL_edma3HwChannelControl (_EDMA_CHANNEL_HANDLE_2X_TO_3X (hEdma),
                CSL_EDMA3_CMD_CHANNEL_DISABLE, NULL);

            /* Clear event bit  */
            CSL_edma3HwChannelControl (_EDMA_CHANNEL_HANDLE_2X_TO_3X (hEdma),
                CSL_EDMA3_CMD_CHANNEL_CLEAR, NULL);
            CSL_edma3ParamSetup (
                _EDMA_CHANNEL_HANDLE_2X_TO_3X_PARAM_HANDLE (hEdma),
                &config);
        }
    }
    _restore_interrupts (gie);
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_resetAll
 *
 *   @b Description
 *   @n Resets all EDMA channels.
 *
 *   @b Arguments </b>
 *   @n  None
 *
 *   <b> Return Value </b>
 *   @n  None
 *
 *   <b> Pre Condition </b>
 *   @n  None
 *
 *   <b> Post Condition </b>
 *   @li 1. The PaRAM words corresponding to all of the DMA channels is are
 *          cleared to 0.
 *   @li 2. All channels are disabled and their interrupts reset.
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *   @b Example
 *   @verbatim
      ...
     EDMA_resetAll();
      ...
     @endverbatim
 * ============================================================================
 */
void EDMA_resetAll (
    void
)
{

    Uint32 gie;
    Uint32 index;

    gie = _disable_interrupts ();

    /* start by disabling and clearing EDMA channels */
    /* Clear Event enable */
    _EDMA_MODULE_HANDLE->EECR = 0xFFFFFFFF;
    _EDMA_MODULE_HANDLE->EECRH = 0xFFFFFFFF;

    /* Clear Event */
    _EDMA_MODULE_HANDLE->ECR = 0xFFFFFFFF;
    _EDMA_MODULE_HANDLE->ECRH = 0xFFFFFFFF;

    /* Clear interrupt enable bits */
    _EDMA_MODULE_HANDLE->IECR = 0xFFFFFFFF;
    _EDMA_MODULE_HANDLE->IECRH = 0xFFFFFFFF;

    /* Clear pending interrupts */
    _EDMA_MODULE_HANDLE->ICR = 0xFFFFFFFF;
    _EDMA_MODULE_HANDLE->ICRH = 0xFFFFFFFF;

    EDMA_clearPram (0x00000000);
    for (index = 0; index < (sizeof (allocMaskT) / sizeof (Uint32)); ++index) {
        allocMaskT[index] = 0;
    }
    _restore_interrupts (gie);
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_open
 *
 *   @b Description
 *   @n Opens a DMA channel for use by the application.
 *
 *   @b Arguments </b>
 *   @verbatim
     1. Channel number or EDMA_CHA_ANY (to open any channel)
     2. Flags - EDMA_OPEN_RESET or EDMA_OPEN_ENABLE or 0
        EDMA_OPEN_RESET  - resets the channel
        EDMA_OPEN_ENABLE - enables the transfers


     @endverbatim
 *   <b> Return Value </b>
 *   @li  A valid handle on success
 *   @li  EDMA_HINV on failure
 *
 *   <b> Pre Condition </b>
 *   @n  None
 *
 *   <b> Post Condition </b>
 *   @li 1. The channel is enabled or reset (PaRAM entry is cleared, channel
 *          disabled and interrupts cleared) depending on the flags passed. 
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *   @b Example
 *   @verbatim
     Uint32 chan_no = 4;
     EDMA_handle handle;
      ...
     handle = EDMA_open(chan_no, 0);
      ...
     @endverbatim
 * ============================================================================
 */
EDMA_Handle EDMA_open (
    int       channel,
    Uint32    flags
)
{
    Uint32 gie;
    EDMA_Handle hEdma = EDMA_HINV;
    Uint32 cha;
    Int32 t_cha = -1;
    CSL_Status status;

    CSL_Edma3ChannelAttr chParam;
    CSL_Status edmaStatus;

    gie = _disable_interrupts ();

    if (channel == EDMA_CHA_ANY) {
        for (cha = 0; cha < EDMA_CHA_CNT; cha++) {
            if (cha < 32) {  /* There are 64 channels; One register can hold
                                bits corresponding to 32 channels */
                if (!(allocMaskCL & (1 << cha))) {
                    t_cha = cha;
                    break;
                }
            }
            else {
                if (!(allocMaskCH & (1 << (cha - 32)))) {
                    t_cha = cha;
                    break;
                }
            }
        }
    }
    else {
        if (channel < 32) {  /* There are 64 channels; One register can hold
                                bits corresponding to 32 channels */
            if (!(allocMaskCL & (1 << channel))) {
                t_cha = channel;
            }
        }
        else if (t_cha < 64) {
            if (!(allocMaskCH & (1 << (channel - 32)))) {
                t_cha = channel;
            }
        }
    }

    if (t_cha == -1) {
        return hEdma;
    }

    /*
     * Channel is opened which is allocated to Global Region 1
     * instance of the EDMA
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -