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

📄 csl_edma.c

📁 Dm6455 driver,magbe useful to you!
💻 C
📖 第 1 页 / 共 2 页
字号:
    chParam.regionNum = CSL_EDMA3_REGION_GLOBAL;
    chParam.chaNum = t_cha;
    EDMA_Wrapper_Data_Objs[t_cha].hChannel =
        CSL_edma3ChannelOpen (&EDMA_Wrapper_Data_Objs[t_cha].ChObj, CSL_EDMA3,
        &chParam, &edmaStatus);

    if (edmaStatus != CSL_ESYS_FAIL) {
        EDMA_Wrapper_Data_Objs[t_cha].param =
            CSL_edma3GetParamHandle (EDMA_Wrapper_Data_Objs[t_cha].hChannel,
            t_cha, &status);
        if (status != CSL_SOK) {
            edmaStatus =
                CSL_edma3ChannelClose (EDMA_Wrapper_Data_Objs[t_cha].hChannel);
            return hEdma;
        }
    }
    else {
        return hEdma;
    }

    if (t_cha < 32) {  /* There are 64 channels; One register can hold
                          bits corresponding to 32 channels */
        allocMaskCL |= (1 << t_cha);
    }
    else if (t_cha < 64) {
        allocMaskCH |= (1 << (t_cha - 32));
    }

    hEdma =
        _EDMA_MK_HANDLE ((Uint32) EDMA_Wrapper_Data_Objs[t_cha].param, t_cha,
        _EDMA_TYPE_C);

    _restore_interrupts (gie);

    if (flags & EDMA_OPEN_RESET) {
        EDMA_reset (hEdma);
    }

    if (flags & EDMA_OPEN_ENABLE) {
        EDMA_enableChannel (hEdma);
    }
    return hEdma;
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_close
 *
 *   @b Description
 *   @n Closes a previously opened DMA channel, after its use
 *      by the application.
 *
 *   @b Arguments
 *   @verbatim
       hEdma      Handle to the channel to be closed

     @endverbatim
 *
 *   <b> Return Value </b>
 *   @li None
 *
 *   <b> Pre Condition </b>
 *   @n  The channel to be closed must have been opened previously.
 *
 *   <b> Post Condition </b>
 *   @li 1. The channel is closed and reset.
 *
 *   @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_close(handle);
      ...
     @endverbatim
 * ============================================================================
 */
void EDMA_close (
    EDMA_Handle    hEdma
)
{

    Uint32 cha = _EDMA_CHANNEL_NUMBER (hEdma);
    Uint32 gie;
    gie = _disable_interrupts ();
    if (cha < 32) {  /* There are 64 channels; One register can hold
                        bits corresponding to 32 channels */
        allocMaskCL &= ~(1 << cha);
    }
    else if (cha < 64) {
        allocMaskCH &= ~(1 << (cha - 32));
    }
    EDMA_reset (hEdma);
    _restore_interrupts (gie);
    CSL_edma3ChannelClose (_EDMA_CHANNEL_HANDLE_2X_TO_3X (hEdma));
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_allocTable
 *
 *   @b Description
 *   @n Allocates a PaRAM table entry for use by the application.
 *
 *   @b Arguments
 *   @verbatim
       tableNum         - PaRAM table entry number (0 to EDMA_TABLE_CNT)
        or
       EDMA_ALLOC_ANY   - to allocate any available entry of PaRAM table
     @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 A PaRAM table entry is allocated from the free pool.
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *
 *   @b Example
 *   @verbatim
     EDMA_handle handle;
     Uint32 tabNum = 1;
      ...
     handle = EDMA_allocTable(tabNum);
      ...
     @endverbatim
 * ============================================================================
 */
EDMA_Handle EDMA_allocTable (
    int    tableNum
)
{

    Uint32 addr;
    EDMA_Handle hEdma = EDMA_HINV;
    Uint32 tbl, major, minor;
    Uint32 gie;

    gie = _disable_interrupts ();

    if (tableNum == EDMA_ALLOC_ANY) {
        for (tbl = 0; tbl < EDMA_TABLE_CNT; tbl++) {
            major = ((tbl) & (~0x1F)) >> 5;
            minor = (tbl) & (0x1F);
            if (!(allocMaskT[major] & (1 << minor))) {
                allocMaskT[major] |= (1 << minor);
                addr = (tbl * _EDMA_ENTRY_SIZE) + _EDMA_LINK_START;
                hEdma =
                    _EDMA_MK_HANDLE (addr,
                    tbl + (_EDMA_LINK_START / _EDMA_ENTRY_SIZE), _EDMA_TYPE_T);
                break;
            }
        }
        if (tbl >= EDMA_TABLE_CNT) {
            hEdma = EDMA_HINV;
        }
    }
    else {
        if ((tableNum < EDMA_TABLE_CNT)) {
            major = ((tableNum) & (~0x1F)) >> 5;
            minor = (tableNum) & (0x1F);
            if (!(allocMaskT[major] & (1 << minor))) {
                allocMaskT[major] |= (1 << minor);
                addr = (tableNum * _EDMA_ENTRY_SIZE) + _EDMA_LINK_START;
                hEdma =
                    _EDMA_MK_HANDLE (addr,
                    tableNum + (_EDMA_LINK_START / _EDMA_ENTRY_SIZE),
                    _EDMA_TYPE_T);
            }
            else {
                hEdma = EDMA_HINV;
            }
        }
    }

    _restore_interrupts (gie);

    return hEdma;
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_freeTable
 *
 *   @b Description
 *   @n Frees a previously allocated PaRAM table entry.
 *
 *   @b Arguments
 *   @verbatim
       hEdma      Handle to the PaRAM entry to be freed

     @endverbatim
 *
 *   <b> Return Value </b>
 *   @n  None
 *
 *   <b> Pre Condition </b>
 *   @n  The channel to be closed must have been allocated previously.
 *
 *   <b> Post Condition </b>
 *   @li One more entry in the free PaRAM table.
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *
 *   @b Example
 *   @verbatim
     EDMA_handle handle;
     Uint32 tabNum = 1;
      ...
     handle = EDMA_allocTable(tabNum);
      ...
     EDMA_freeTable(handle);
      ...
     @endverbatim
 * ============================================================================
 */
void EDMA_freeTable (
    EDMA_Handle    hEdma
)
{

    Uint32 tbl, major, minor, tmp;
    Uint32 gie;

    gie = _disable_interrupts ();
    if (hEdma & _EDMA_TYPE_T) {
        tbl = _EDMA_CHANNEL_NUMBER (hEdma);
        tmp = (_EDMA_LINK_START / _EDMA_ENTRY_SIZE) & 0x000000FF;
        tbl -= tmp;
        major = ((tbl) & (~0x1F)) >> 5;
        minor = (tbl) & (0x1F);
        allocMaskT[major] &= ~(1 << minor);
    }
    _restore_interrupts (gie);
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_allocTableEx
 *
 *   @b Description
 *   @n Allocates a number of PaRAM table entries from the free pool.
 *
 *   @b Arguments
 *   @verbatim
       cnt        number of channels to be allocaed
       array      pointer to the first element of array of EDMA_handles
                  to return handles for the allocated entries

     @endverbatim
 *
 *   <b> Return Value </b>
 *   @li  The number of allocated entries, if success
 *   @li  0, if failure
 *
 *   <b> Pre Condition </b>
 *   @n  None
 *
 *   <b> Post Condition </b>
 *   @li 1. The number of entries in free PaRAM table are less by 'cnt'
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *
 *   @b Example
 *   @verbatim
     EDMA_handle hArray[4];
     Uint32 cnt = 4, retCnt;
     retCnt = EDMA_allocTableEx(cnt, &hArray[0]);
      ...

     @endverbatim
 * ============================================================================
 */
Uint32 EDMA_allocTableEx (
    int    cnt,
    EDMA_Handle    * array
)
{

    Uint32 index, numAllocated = 0;
    EDMA_Handle hEdma;
    Uint32 gie;

    gie = _disable_interrupts ();
    for (index = 0; index < cnt; index++) {
        hEdma = EDMA_allocTable (EDMA_ALLOC_ANY);
        if (hEdma != EDMA_HINV) {
            numAllocated++;
            array[index] = hEdma;
        }
        else {
            EDMA_freeTableEx (numAllocated, array);
            numAllocated = 0;
        }
    }
    _restore_interrupts (gie);
    return numAllocated;
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_freeTableEx
 *
 *   @b Description
 *   @n Frees previously allocated PaRAM table entries.
 *
 *   @b Arguments
 *   @verbatim
       cnt        number of channels to be freed
       array      pointer to the first element of array of EDMA_handles
                  that are to be freed

     @endverbatim
 *
 *   <b> Return Value </b>
 *   @n  None
 *
 *   <b> Pre Condition </b>
 *   @n  Freed entries must have been allocated previously
 *
 *   <b> Post Condition </b>
 *   @li 1. The number of entries in free PaRAM table are more by 'cnt' 
 *
 *   @b Modifies
 *   @n The system data structures are modified.
 *
 *
 *   @b Example
 *   @verbatim
     EDMA_handle hArray[4];
     Uint32 cnt = 4, retCnt;
     retCnt = EDMA_allocTableEx(cnt, &hArray[0]);
      ...
     EDMA_freeTableEx(cnt, &hArray[0]);
      ...
     @endverbatim
 * ============================================================================
 */
void EDMA_freeTableEx (
    int            cnt,
    EDMA_Handle    * array
)
{

    Uint32 index;
    Uint32 gie;

    gie = _disable_interrupts ();
    for (index = 0; index < cnt; index++) {
        EDMA_freeTable (array[index]);
        array[index] = EDMA_HINV;
    }
    _restore_interrupts (gie);
}

/*---------------------------------------------------------------------------*/
/** 
 * ============================================================================
 *   @n@b EDMA_clearPram
 *
 *   @b Description
 *   @n The PaRAM words corresponding to all of the DMA channels  are set to
 *      憊al

⌨️ 快捷键说明

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