资源简介
Altera EP4CGX15 start kit DEMO 驱动源码
代码片段和文件信息
#include
#include “wdc_defs.h“
#include “wdc_lib.h“
#include “stdio.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define NUMBER_OF_DESCRPT 2
unsigned int OnRCSlaveRead(WDC_DEVICE_HANDLE hDev int bar unsigned int addr){
unsigned int u32Data=0;
WDC_ReadAddr32(hDev bar addr &u32Data);
return u32Data;
}
void OnRCSlaveWrite(WDC_DEVICE_HANDLE hDev int bar unsigned int addr unsigned int wdata){
WDC_WriteAddr8(hDevbaraddr wdata & 0xFF);
WDC_WriteAddr8(hDevbaraddr+1 (wdata>>8) & 0xFF);
WDC_WriteAddr8(hDevbaraddr+2 (wdata>>16) & 0xFF);
WDC_WriteAddr8(hDevbaraddr+3 (wdata>>24) & 0xFF);
}
// PC -> FPGA
void DMA_Read(WDC_DEVICE_HANDLE hDev unsigned int target_addr int length){
int l;
clock_t startend;
double accum_time = 0;
LARGE_INTEGER IFreq IStart IEnd;
int test = 0;
int iteration = 100;
int i;
unsigned int address_offset=0;
int data_pattern = 1;
int data_check_option = 1;
DWORD dwStatus;
HANDLE hWD;
WD_DMA dma_buff;
// getting low level driver handle
hWD = WD_Open();
if (hWD == INVALID_HANDLE_VALUE)
printf(“DMA read : Cannot open WinDriver device“);
// This cardReg is required to use low level driver
WD_CARD_REGISTER cardReg;
BZERO(cardReg);
cardReg.Card.dwItems = 1;
cardReg.Card.Item[0].item = ITEM_IO;
cardReg.Card.Item[0].fNotSharable = TRUE;
cardReg.Card.Item[0].I.IO.dwAddr = 0x378;
cardReg.Card.Item[0].I.IO.dwBytes = 8;
WD_CardRegister(hWD &cardReg);
if (cardReg.hCard == 0){
printf(“DMA read : Failed locking device“);
return;
}
// allocating the user memory area
BZERO(dma_buff);
dma_buff.dwBytes = length + 32; // additional 32byte will be used to detect the end of process.
// Set contiguous Buffer
dma_buff.dwOptions = DMA_KERNEL_BUFFER_ALLOC | DMA_KBUF_BELOW_16M;
dma_buff.hCard = cardReg.hCard;
dwStatus = WD_DMALock(hWD &dma_buff);
if(dwStatus){
printf(“DMA read : Failed to allocate memory“);
return;
}
// generating random data
DWORD random_data;
unsigned current_time = (unsigned)time(NULL);
srand(current_time);
random_data=rand();
DWORD *pSBuf; // Soft Buffer
// This is the data send to FPGA
pSBuf= (DWORD *) dma_buff.pUserAddr;
for (i = 0; i < length / 4 ; i++) {
if(data_pattern == 1){
random_data=rand();
double tmp = (double)random_data / 17737;
DWORD t = tmp * 0xFFFFFFFF;
pSBuf[i] = t;
}else
pSBuf[i] = i;
}
// clearing out the location for DMA end detection
for (i = length / 4; i < (length+32) / 4 ; i++) {
pSBuf[i] = 0;
}
// Set up the variable for DMA end detection at here.
DWORD expected_data = pSBuf[32/4 - 1];
DWORD read_data = pSBuf[(length + 32)/4 - 1]; // Not yet transmitted so it should get 0 at here.
// trying and check the address translation path through
OnRCSlaveWrite(hDev 2 0x1000 0xFFFFF
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-04-21 08:41 altpcie_demo_10.0SP1\
文件 3960912 2011-10-27 08:53 altpcie_demo_10.0SP1\altpcie_demo.exe
目录 0 2010-08-17 06:46 altpcie_demo_10.0SP1\JungoDrivers\
文件 4260 2006-11-17 02:04 altpcie_demo_10.0SP1\JungoDrivers\altpcie_perf_demo_e001.inf
文件 89 2006-11-30 09:06 altpcie_demo_10.0SP1\JungoDrivers\install.bat
文件 102400 2006-08-25 01:43 altpcie_demo_10.0SP1\JungoDrivers\wdapi810.dll
文件 135253 2006-06-06 22:44 altpcie_demo_10.0SP1\JungoDrivers\wdreg.exe
文件 2819 2006-08-15 20:33 altpcie_demo_10.0SP1\JungoDrivers\windrvr6.inf
文件 194200 2006-08-15 20:32 altpcie_demo_10.0SP1\JungoDrivers\windrvr6.sys
文件 32768 2006-10-18 22:28 altpcie_demo_10.0SP1\pci_lib.dll
文件 6419 2012-04-21 09:10 altpcie_demo_10.0SP1\pcie_log.txt
文件 102400 2006-08-25 01:43 altpcie_demo_10.0SP1\wdapi810.dll
文件 102400 2006-10-18 22:29 altpcie_demo_10.0SP1\wdapi811.dll
文件 7332240 2012-10-25 15:49 ug_pci_express.pdf
目录 0 2012-10-27 03:27 alt_pcie_qsys_simple_sw\
文件 15054 2011-04-26 17:28 alt_pcie_qsys_simple_sw\altpcie_demo.cpp
文件 4196 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple.inf
文件 2500 2012-10-27 03:27 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple.wdp
文件 2500 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple.wdp.bak
文件 887 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_diag.sln
文件 14848 2011-04-26 17:55 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_diag.suo
文件 7297 2011-04-26 17:52 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_diag.vcxproj
文件 143 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_diag.vcxproj.user
文件 1987 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_files.txt
文件 18961 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_lib.c
文件 3735 2011-04-26 15:25 alt_pcie_qsys_simple_sw\alt_pcie_qsys_simple_lib.h
文件 31945 2011-04-26 17:49 alt_pcie_qsys_simple_sw\main.cpp
评论
共有 条评论