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

📄 ddk_sdma.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  FREESCALE SEMICONDUCTOR, INC.
//
//------------------------------------------------------------------------------
//
//  File:  ddk_sdma.c
//
//  This file contains the platform-dependent CSPDDK SDMA support.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include "bsp.h"

//-----------------------------------------------------------------------------
// External Functions


//-----------------------------------------------------------------------------
// External Variables
extern DMA_ADAPTER_OBJECT g_DmaAdapter;
extern PSDMA_HOST_SHARED_REGION g_pHostSharedUA;
extern PSDMA_HOST_SHARED_REGION g_pHostSharedPA;


//-----------------------------------------------------------------------------
// Defines


//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables


//-----------------------------------------------------------------------------
// Local Variables


//-----------------------------------------------------------------------------
// Local Functions


//-----------------------------------------------------------------------------
//
//  Function:  BSPSdmaGetSharedSize
//
//  This function returns the size of the static memory region
//  reserved for the SDMA shared data structures.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE.
//
//-----------------------------------------------------------------------------
UINT32 BSPSdmaGetSharedSize(VOID)
{
#if (BSP_SDMA_MC0PTR == IMAGE_SHARE_IRAM_SDMA_PA_START)
    return IMAGE_SHARE_IRAM_SDMA_SIZE;
#else
    return IMAGE_SHARE_SDMA_SIZE;
#endif
}


//-----------------------------------------------------------------------------
//
//  Function:  BSPSdmaAllocChain
//
//  This function allocates a chain of buffer descriptors for
//  a virtual DMA channel from platform-specific storage.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE.
//
//-----------------------------------------------------------------------------
PVOID BSPSdmaAllocChain(UINT8 chan, UINT32 numBufDesc, PPHYSICAL_ADDRESS pPhyAddr)
{
    BOOL bStaticBufDesc = TRUE;
    PVOID pBufDesc = NULL;
    
    // Check if number of buffer descriptors requested exceeds number
    // supported with static buffer descriptor storage
    if (numBufDesc > SDMA_STATIC_BUF_DESC)
    {
        bStaticBufDesc = FALSE;
    }
    
    // Make sure we can support this channel since limited static buffer
    // descriptor storage may not be sufficient to support all channels
    if (((UINT32) g_pHostSharedPA < CSP_BASE_MEM_PA_CSD0) &&
        (((UINT32) &(g_pHostSharedPA->chanBufDesc[chan][0])) >
            (IMAGE_SHARE_IRAM_SDMA_PA_START+IMAGE_SHARE_IRAM_SDMA_SIZE)))
    {
            bStaticBufDesc = FALSE;
    }
    else if (((UINT32) &(g_pHostSharedPA->chanBufDesc[chan][0])) > 
            (IMAGE_SHARE_SDMA_PA_START+IMAGE_SHARE_SDMA_SIZE))
    {
            bStaticBufDesc = FALSE;
    }
    
    // If buffer descriptors can be allocated from static storage
    if (bStaticBufDesc)
    {
        pBufDesc = &(g_pHostSharedUA->chanBufDesc[chan-1][0]);
        pPhyAddr->HighPart = 0;
        pPhyAddr->LowPart = (UINT32) &(g_pHostSharedPA->chanBufDesc[chan-1][0]);
    }

    // Else attempt dynamic allocation
    else
    {
        if (g_pHostSharedUA->chanDesc[chan].bExtended)
        {
            pBufDesc = HalAllocateCommonBuffer(&g_DmaAdapter,
                numBufDesc*sizeof(SDMA_BUF_DESC_EXT), pPhyAddr, FALSE);
        }
        else
        {
            pBufDesc = HalAllocateCommonBuffer(&g_DmaAdapter,
                numBufDesc*sizeof(SDMA_BUF_DESC), pPhyAddr, FALSE);
        }
    }

    // Keep track of the buffer descriptor storage method
    g_pHostSharedUA->chanDesc[chan].bStaticBufDesc = bStaticBufDesc;
    
    return pBufDesc;

}


//-----------------------------------------------------------------------------
//
//  Function:  BSPSdmaFreeChain
//
//  This function frees a chain of buffer descriptors for
//  a virtual DMA channel from platform-specific storage.
//
//  Parameters:
//      None.
//
//  Returns:
//      Returns TRUE.
//
//-----------------------------------------------------------------------------
VOID BSPSdmaFreeChain(UINT8 chan)
{
    PHYSICAL_ADDRESS phyAddr;
    
    // If chain does not reside in static buffer descriptor storage
    if (!(g_pHostSharedUA->chanDesc[chan].bStaticBufDesc))
    {
        phyAddr.QuadPart = g_pHostSharedUA->chanCtrlBlk[chan].baseBufDescPA;
    
        HalFreeCommonBuffer(&g_DmaAdapter, 0, phyAddr,
            g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA, FALSE);
    }
}


//-----------------------------------------------------------------------------
//
//  Function:  BSPSdmaUsePerDma
//
//  This function determines if the script associated with the specified
//  DMA request line should use the peripheral DMA (used for
//  peripheral transfers to/from internal memory).
//
//  Parameters:
//      dmaReq
//          [in] Specifies the DMA request line.
//
//
//  Returns:  
//      Returns TRUE if the peripheral DMA should be used for the
//      specified DMA request.  Otherwise, returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL BSPSdmaUsePerDma(DDK_DMA_REQ dmaReq)
{
    BOOL rc = FALSE;

    switch(dmaReq)
    {
    case DDK_DMA_REQ_SSI2_TX0:
#ifdef BSP_AUDIO_DMA_BUF_ADDR
#if (BSP_AUDIO_DMA_BUF_ADDR == IMAGE_SHARE_IRAM_AUDIO_PA_START)
        rc = TRUE;
#endif
#endif
        break;
    }

    return rc;
}

⌨️ 快捷键说明

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