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

📄 xsdma.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************
**
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:      xsdma.c
**
**  PURPOSE:       Contains the API implementation for the DMA controller 
**                 driver.
**
**  Valid for    :  Cotulla processor
**
**  EAS VERSION  :
**
**  LAST MODIFIED: $Modtime: 7/17/03 1:01p $
******************************************************************************/



/*******************************************************************************
*   HEADER FILES
*******************************************************************************/

#include <string.h>
#include <stdio.h>
#include "systypes.h"
#include "XsIntCtrlApi.h"
#include "XsDmaApi.h"
#include "xsdma.h"
#include "dm_errors.h"
#include "mallocx.h"
#include "cotulla.h"
#include "DM_Debug.h"
#include "serialCommon.h"
#include "timedelays.h"

/*******************************************************************************
*   MACRO DEFINITIONS
*******************************************************************************/
#define DM_ReturnMem(virtualAddr) free(virtualAddr)



/*******************************************************************************
*   GLOBAL DEFINITIONS
*******************************************************************************/

volatile XsDmaCtrlT *XsDmaControlRegsP = (XsDmaCtrlT *)DMA_REGISTER_BASE;
static UINT XsDmaChannelsUsedWord = 0;



/*******************************************************************************
This table contains the DMA specific data for the peripheral devices.
Refer to table 6-4 in the Cotulla EAS August, 2000.
*******************************************************************************/


XsDmaToDeviceT DmaDeviceTable[] = {

/*   Name                    receive     transmit    width           burst */

    {XSDMA_DN_MEMORY,            0,          0,      DCMD_WIDTH_4,              0},
    {XSDMA_DN_I2S,           0x40400080, 0x40400080, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BTUART,        0x40200000, 0x40200000, DCMD_WIDTH_1,   DCMD_SIZE_32},
    {XSDMA_DN_FFUART,        0x40100000, 0x40100000, DCMD_WIDTH_1,   DCMD_SIZE_32},
    {XSDMA_DN_AC97_MIC,      0x40500060, 0,          DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_AC97_MODEM,    0x40500140, 0x40500140, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_AC97_AUDIO,    0x40500040, 0x40500040, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_SSP1,          0x41000010, 0x41000010, DCMD_WIDTH_2,   DCMD_SIZE_16},
    {XSDMA_DN_ICP,           0x4080000C, 0x4080000C, DCMD_WIDTH_1,   DCMD_SIZE_8},
    {XSDMA_DN_STUART,        0x40700000, 0x40700000, DCMD_WIDTH_1,   DCMD_SIZE_32},
    {XSDMA_DN_MMC,           0x41100040, 0x41100044, DCMD_WIDTH_1,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_0,      0x40600300, 0x40600300, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_A,      0x40600304, 0x40600304, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_B,      0x40600308, 0x40600308, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_C,      0x4060030C, 0x4060030C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_D,      0x40600310, 0x40600310, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_E,      0x40600314, 0x40600314, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_F,      0x40600318, 0x40600318, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_G,      0x4060031C, 0x4060031C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_H,      0x40600320, 0x40600320, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_I,      0x40600324, 0x40600324, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_J,      0x40600328, 0x40600328, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_K,      0x4060032C, 0x4060032C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_L,      0x40600330, 0x40600330, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_M,      0x40600334, 0x40600334, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_N,      0x40600338, 0x40600338, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_P,      0x4060033C, 0x4060033C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_Q,      0x40600340, 0x40600340, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_R,      0x40600344, 0x40600344, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_S,      0x40600348, 0x40600348, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_T,      0x4060034C, 0x4060034C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_U,      0x40600350, 0x40600350, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_V,      0x40600354, 0x40600354, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_W,      0x40600358, 0x40600358, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USB_EP_X,      0x4060035C, 0x4060035C, DCMD_WIDTH_4,   DCMD_SIZE_32},
//SHAWN- DCMD_WIDTH from 1 to 4 now.. any issues?

    {XSDMA_DN_BASEBAND_1,    0x41400004, 0x41400004, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_2,    0x41400008, 0x41400008, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_3,    0x4140000C, 0x4140000C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_4,    0x41400010, 0x41400010, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_5,    0x41400014, 0x41400014, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_6,    0x41400018, 0x41400018, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_BASEBAND_7,    0x4140001C, 0x4140001C, DCMD_WIDTH_4,   DCMD_SIZE_32},
    {XSDMA_DN_USIM,          0x41600000, 0x41600004, DCMD_WIDTH_1,   DCMD_SIZE_32},
    {XSDMA_DN_SSP2,          0x41700010, 0x41700010, DCMD_WIDTH_2,   DCMD_SIZE_16},
    {XSDMA_DN_MEM_STICK,     0x41800018, 0x4180001C, DCMD_WIDTH_1,   DCMD_SIZE_8},
    {XSDMA_DN_SSP3,          0x41900010, 0x41900010, DCMD_WIDTH_2,   DCMD_SIZE_16}
};



/*******************************************************************************
*   FUNCTION DEFINITIONS
*******************************************************************************/

/*
*******************************************************************************
*
* FUNCTION:         DM_GetDmaDescriptorAlignedBlock
*
* DESCRIPTION:      Get a single block of memory that is the size of a DMA 
*                   descriptor structure, with the appropriate alignment.
*
* INPUT PARAMETERS: 
*            XsDmaDescriptorElementsTPT* virtualPP: 
*                   Address of a pointer to the new descriptor block.
*            PUINT32 physicalAddrP: 
*                   Address of a variable to hold the new descriptor block's 
*                   physical address.
*
* RETURNS:         UINT32 
*           Success: ERR_NONE (0)
*           Failure: Anything other than ERR_NONE.  Memory not allocated.
*
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      malloc() provides allocates memory units that are 
*                   DMA descriptor-aligned.
*
* CALLS:            malloc
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 DM_GetDmaDescriptorAlignedBlock 
*                                       (XsDmaDescriptorElementsTPT*, 
*                                        PUINT32);
*
*******************************************************************************
*/

UINT32 DM_GetDmaDescriptorAlignedBlock(XsDmaDescriptorElementsTPT* virtualPP,
                                       PUINT32 physicalAddrP)
{
    *((VOID **)physicalAddrP) = *virtualPP = malloc(sizeof(XsDmaDescriptorElementsT));
    return mallocErr();
} // DM_GetDmaDescriptorAlignedBlock()


/*
*******************************************************************************
*
* FUNCTION:         DM_GetBufferDma
*
* DESCRIPTION:      Get a single DMA buffer of the specified number of 
*                   kilobytes, with the appropriate alignment.
*
* INPUT PARAMETERS: 
*            INT bufSizeKb: 
*                   Number of kilobytes of buffer desired.
*            XsDmaDescriptorElementsTPT* virtualPP: 
*                   Address of a pointer to the new DMA buffer.
*            PUINT32 physicalAddrP: 
*                   Address of a variable to hold the new buffer's physical 
*                   address.
*
* RETURNS:         UINT32 
*           Success: ERR_NONE (0)
*           Failure: Anything other than ERR_NONE.  Memory not allocated.
*
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      malloc() provides allocates memory units that are 
*                   DMA buffer-aligned.
*
* CALLS:            malloc
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 DM_GetBufferDma (INT, PVOID*, PUINT32);
*
*******************************************************************************
*/

UINT32 DM_GetBufferDma(INT bufSizeKb,
                       PVOID* virtualPP,
                       PUINT32 physicalAddrP) 
{
    *((VOID **)physicalAddrP) = *virtualPP = malloc((bufSizeKb)*1024);
    return mallocErr();
} //  DM_GetBufferDma()


/*
*******************************************************************************
*
* FUNCTION:         XsDmaGetRemainingLength
*
* DESCRIPTION:      For the specified channel, obtains the remaining transfer 
*                   length of the currently active descriptor.   (Reads the 
*                   value from that channel's DMCD and masks it from other bit 
*                   fields in the register.  No normalization is needed because 
*                   the length field is held in the register's lowest-order 
*                   bits.)
*
* INPUT PARAMETERS: INT channel:  which channel's current transfer length 
*                                 remaining to obtain.
*
* RETURNS:          INT - The currently remaining transfer length.
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      Channel number has been validated elsewhere.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        INT XsDmaGetRemainingLength (INT);
*
*******************************************************************************
*/

INT XsDmaGetRemainingLength (INT channel)
{
    // Don't check for bad channel ID: assume tested before this.
    UINT32 length = XsDmaControlRegsP->DDG[channel].DCMD;
    return ((INT) (length & DCMD_LEN_MASK) );
    
} // XsDmaGetRemainingLength()


/*
*******************************************************************************
*
* FUNCTION:         XsDmaReadChannelStatus
*
* DESCRIPTION:      Reports the value of the DCSR for the specified channel.
*
* INPUT PARAMETERS: INT channel:  which channel's DCSR to read.
*
* RETURNS:          UINT32 - the value of the channel's DCSR.
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      Channel number has been validated elsewhere.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsDmaReadChannelStatus (INT);
*
*******************************************************************************
*/

UINT32 XsDmaReadChannelStatus (INT channel)
{
    return (XsDmaControlRegsP->DCSR[channel]);
} // XsDmaReadChannelStatus()


/*
*******************************************************************************
*
* FUNCTION:         XsDmaSWInit
*
* DESCRIPTION:      Required API function.  Does nothing.
*
* INPUT PARAMETERS: None
*
* RETURNS:          None
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      Memory is 0-initialized.
*
* CALLS:            None
*
* CALLED BY:        System initialization code
*
* PROTOTYPE:        void XsDmaSWInit (void);
*
*******************************************************************************
*/

void XsDmaSWInit (void)
{
    // This function intentionally left blank

} // End XsDmaSWInit ()



/*
*******************************************************************************
*
* FUNCTION:         XsDmaHWSetup
*
* DESCRIPTION:      Initializes all main processor DMA registers to a benign
*                     state (0).
*                   Registers the DMA interrupt handling subroutine with the 
*                     main processor Interrupt Controller driver module.  
*                   Enables DMA interrupts at the IC.
*
* INPUT PARAMETERS: None
*
* RETURNS:   
*       Success:    0 (ERR_NONE)
*       Failure:    NonZero: Internal error invoking XsIcRegisterHandler()
*
* GLOBAL EFFECTS:   

⌨️ 快捷键说明

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