📄 csdma.c
字号:
//**********************************************************************
//
// Filename: CsDma.c
//
// Description:
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
// use this source code. For a copy of the EULA, please see the
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
//**********************************************************************
#include "csdma.h"
//
// Global pointer to the virtual memory starting address of DMA buffers
//
static DWORD g_pvDmaVirtualBase;
static DWORD g_CurrVirMemAddr;
static DWORD VirtualToPhysAddress(DWORD Virtual);
//****************************************************************************
// DMAInitMem()
//****************************************************************************
BOOL DMAInitMem(PCHIP pChip)
{
BOOL status=TRUE;
g_pvDmaVirtualBase = CS8950_VIRTUAL_MEMORY;
g_CurrVirMemAddr = CS8950_VIRTUAL_MEMORY;
memset((PVOID)g_pvDmaVirtualBase, 0, CS8950_MEMORY_SIZE);
return status;
}
//****************************************************************************
// DMARelMem()
//****************************************************************************
void DMARelMem(PCHIP pChip)
{
g_pvDmaVirtualBase = CS8950_VIRTUAL_MEMORY;
g_CurrVirMemAddr = CS8950_VIRTUAL_MEMORY;
}
//****************************************************************************
// VirtualToPhysAddress()
//****************************************************************************
static DWORD VirtualToPhysAddress(DWORD addrVirtual)
{
//
// Make sure that the given virtual address is within the range of our buffer.
//
ASSERT((addrVirtual >= g_pvDmaVirtualBase) &&
(addrVirtual < (g_pvDmaVirtualBase + CS8950_MEMORY_SIZE)));
//
// Physical address is the base physical address plus the offset
// in the virtual address space. (Make this more flexible later.)
//
return (addrVirtual + (ULONG)CS8950_PHYSICAL_MEMORY - (ULONG)CS8950_VIRTUAL_MEMORY);
}
/*************************************************************************
*
* VosAllocSharedMemory()
*
*************************************************************************/
BOOL VosAllocSharedMemory
(
PCHIP pChip,
WORD Size,
PVOID *ppMemory,
DWORD *pPhysAddr
)
{
*ppMemory=(PVOID) g_CurrVirMemAddr;
*pPhysAddr=VirtualToPhysAddress(g_CurrVirMemAddr);
g_CurrVirMemAddr += (DWORD)Size;
//The address must start with 32 bits aligment
switch (g_CurrVirMemAddr & 3 )
{
case 1 :
g_CurrVirMemAddr += 3;
break;
case 2 :
g_CurrVirMemAddr += 2;
break;
case 3 :
g_CurrVirMemAddr += 1;
break;
default: // do nothing
break;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -