2,640
社区成员
发帖
与我相关
我的任务
分享
void CNO_SDRAM_DAQDlg::OnRecieveT()
{
// TODO: Add your control notification handler code here
// No search criteria, select all devices
GetDlgItem(IDC_Start_Receive)->EnableWindow(FALSE);
GetDlgItem(IDC_Start_Save)->EnableWindow(TRUE);
GetDlgItem(IDC_Stop_Receive)->EnableWindow(TRUE);
DWORD EventStatus;
framecount = 0;
int i = 0;
WaitIntr = 1;
b_write = 0;
ReceiveFlag = 0xF0;
rc = PlxBusIopWrite(hDevice,IopSpace1,0x00001000,TRUE,&ReceiveFlag,1,BitSize8);
if(rc == ApiSuccess)
{
m_status.Format("PlxBusIopWrite成功");
}
else
{
m_status.Format("PlxBusIopWrite失败");
}
SetDlgItemText(IDC_status,m_status);
memset(
&DmaDesc,
0,
sizeof(DMA_CHANNEL_DESC)
);
// Set up DMA configuration structure
DmaDesc.EnableReadyInput = 1;
DmaDesc.EnableBTERMInput = 0;
DmaDesc.EnableIopBurst = 1;
DmaDesc.EnableWriteInvalidMode = 0;
DmaDesc.EnableDmaEOTPin = 0;
DmaDesc.DmaStopTransferMode = AssertBLAST;
DmaDesc.HoldIopAddrConst = 1;
DmaDesc.DemandMode = 0;
DmaDesc.EnableTransferCountClear = 0;
DmaDesc.WaitStates = 0;
DmaDesc.IopBusWidth = 2; // 32-bit
DmaDesc.DmaChannelPriority = Rotational;
rc = PlxDmaSglChannelOpen(
hDevice,
PrimaryPciChannel0,
&DmaDesc
);
if (rc == ApiSuccess)
m_status.Format("成功打开DMA通道0");
else
m_status.Format("无法打开DMA通道0");
SetDlgItemText(IDC_status,m_status);
DmaData.u.UserVa = (U32)buffer;
DmaData.LocalAddr = 0x00008000;
DmaData.TransferCount = sizeof(buffer);
DmaData.LocalToPciDma = 1;// Local to PCI
DmaData.TerminalCountIntr = 0;
while(WaitIntr)
{
memset(
&buffer,
0,
sizeof(buffer)
);
// Clear INTR descriptor structure
memset(
&PlxInterrupt,
0,
sizeof(PLX_INTR)
);
rc=PlxIntrStatusGet(hDevice,&PlxInterrupt);
PlxInterrupt.PciDmaChannel0 = 1;
PlxInterrupt.PciMainInt = 1;
PlxInterrupt.IopToPciInt = 1;
rc = PlxIntrAttach(
hDevice,
PlxInterrupt,
&hInterruptEvent
);
rc = PlxIntrEnable(
hDevice,
&PlxInterrupt
);
EventStatus = WaitForSingleObject(
hInterruptEvent,
1000
);
switch(EventStatus)
{
case WAIT_OBJECT_0:
flag = 1;
m_status.Format("获取中断");
break;
case WAIT_TIMEOUT:
flag = 0;
m_status.Format("等待超时");
break;
case WAIT_FAILED:
flag = 0;
m_status.Format("等待失败");
break;
default:
flag = 0;
break;
}
SetDlgItemText(IDC_status,m_status);
if(flag == 1)
{
rc = PlxDmaSglTransfer(
hDevice,
PrimaryPciChannel0,
&DmaData,
0 // Wait for completion
);
if (rc == ApiSuccess)
{ i++;
m_status.Format("成功进行DMA传输");
m_TRANSFERTIME.Format("%d\n",i);
if(b_write)
{
FIFODATA.Write(buffer,buf_len);
m_status.Format("成功进行数据保存");
}
}
else if(rc == ApiDmaInProgress)
{
m_status.Format("ApiDmaInProgress");
}
else if(rc == ApiDmaChannelInvalid)
{
m_status.Format("ApiDmaChannelInvalid");
}
else if(rc == ApiPciTimeout)
{
m_status.Format("ApiPciTimeout");
}
else
m_status.Format("没有进行DMA传输");
SetDlgItemText(IDC_EDIT_TRANSFERTIME,m_TRANSFERTIME);
SetDlgItemText(IDC_status,m_status);
}
else break;
}
}
#define buf_len 223*16
#define FileLength 1024
U8 buffer[buf_len];