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

📄 adma.cpp

📁 Windows 2000下PCI数据采集卡WDM驱动,非常完整
💻 CPP
字号:
// ADMA.cpp : Defines the entry point for the console applicaDSPon.
//

#include "stdafx.h"
#include "ADMA.h"

#include "..\..\inc\DSP100.h"
#include "..\..\inc\reg.h"
#include "..\..\inc\Dvcseapi.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only applicaDSPon object

CWinApp theApp;

using namespace std;




int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// iniDSPalize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC iniDSPalizaDSPon failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your applicaDSPon's behavior here.
		CString strHello;
		strHello.LoadString(IDS_HELLO);
		cout << (LPCTSTR)strHello << endl;
	}

	//Add code 

	DSPSTATUS status	= DSP_OK;

	HDSP100 hdsp		= NULL;
	
	DWORD dwRVal		= 0;
	
	int nSize			= 0;

	DWORD dwMask		= 0;
	DWORD dwShift		= 0;
	DWORD dwData		= 0;

	DWORD dwSegment		= 0;
	DWORD dwOffset		= 0;

	HANDLE hMap			= NULL;
	BYTE *pBuffer		= NULL;

	HANDLE hFile        = INVALID_HANDLE_VALUE;
	HANDLE hMapFile		= NULL;

	BYTE *pDSPProg		= NULL;

	status = BeginDSP100(1, &hdsp);

	//Lock 4m memory window
	status = DSP100LockMem(hdsp, -1, -1 , &hMap, (PVOID *)&pBuffer);
	
	if (DSP_SUCCESS(status)) {
		//Read Dvcserv memory
		SECTION_MAP_INFO map_info;
		map_info.dwStartOffset = 0;
		map_info.dwLength = nSize = 0xfffc;
		DvcStaticMemLock(&map_info);

		ZeroMemory(map_info.pLinearAddress, nSize);
		
		printf("0x%x\n", *(DWORD *)map_info.pLinearAddress);
		
		//Reset DSP
		status = DSP100ReadPortULong(hdsp, HDCR, &dwData);
		if (DSP_SUCCESS(status)) {
			dwData |= 0x1;
			status = DSP100WritePortULong(hdsp, HDCR, dwData);
		}
		
		//Load bin to interal program RAM
		status = DSP100WritePortULong(hdsp, DSPP, 0x400);
		status = DSP100LoadProgram(pBuffer, "test01_adma2.bin");
		
		//Initialize PCI only read zone
		dwSegment	=  0x8000ffc0 / 0x400000;
		dwSegment	|= 0x400;
		dwOffset	=  0x8000ffc0 % 0x400000;
		DSP100WritePortULong(hdsp, DSPP, dwSegment);
		ZeroMemory(pBuffer + dwOffset, 32 * 4);
		
		printf("PCI zone 0x%0x \n", *(DWORD *)(pBuffer + dwOffset));

		*(DWORD *)(pBuffer + dwOffset) = map_info.dwPhysicalAddress;

		printf("PCI zone 0x%0x \n", *(DWORD *)(pBuffer + dwOffset));

		//Initialize DSP Write only zone
		dwSegment	=  0x8000ffe0 / 0x400000;
		dwSegment	|= 0x400;
		dwOffset	=  0x8000ffe0 % 0x400000;
		DSP100WritePortULong(hdsp, DSPP, dwSegment);
		ZeroMemory(pBuffer + dwOffset, 32 * 4);
		printf("DSP Write only zone 1 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset));
		printf("DSP Write only zone 2 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset + 4));

/*
		//Initialize external sdram zone
		dwSegment	=  0x02000000 / 0x400000;
		dwSegment	|= 0x400;
		dwOffset	=  0x02000000 % 0x400000;
		DSP100WritePortULong(hdsp, DSPP, dwSegment);
		ZeroMemory(pBuffer + dwOffset, 32 * 4);
		printf("external sdram zone 1 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset));

		*(DWORD *)(pBuffer + dwOffset) = 0x1a1a1a1a;

		printf("external sdram zone 1 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset));
*/
		//Set DSPINT and release dsp from reset
		status = DSP100ReadPortULong(hdsp, HDCR, &dwData);
		if (DSP_SUCCESS(status)) {
			dwData |= 0x2;
			status = DSP100WritePortULong(hdsp, HDCR, dwData);
		}

		//Read DSP write only zone
		dwSegment	=  0x8000ffe0 / 0x400000;
		dwSegment	|= 0x400;
		dwOffset	=  0x8000ffe0 % 0x400000;
		DSP100WritePortULong(hdsp, DSPP, dwSegment);

		printf("DSP Write only zone 1 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset));							
		printf("DSP Write only zone 2 is 0x%x \n", *(DWORD *)(pBuffer + dwOffset + 4));							

		for (int i = 0; i < nSize; i++){
			printf("Data %-4d : 0x%x\n", i, *((BYTE *)map_info.pLinearAddress + i));
		}
		
		//Unlock static memory
		DvcStaticMemUnlock(&map_info);

		//Unlock dsp memory
		status = DSP100UnlockMem(hdsp, hMap);
	}
	
	status = EndDSP100(hdsp);

	return nRetCode;

}
































































⌨️ 快捷键说明

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