📄 dma.cpp
字号:
// DMA.cpp : implementation file
//
#include "stdafx.h"
#include "pctest.h"
#include "DMA.h"
#include "adc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDMA dialog
extern PCHAR mDynVxDName ;
#define addoff 0x00
#define addout 0x80
#define CLEAR_F 0x7c //F/L flip fiop for write
#define CH0_A 0x70 //channel 0 base address for write
#define CH1_A 0x72 //channel 1 base address for write
#define CH1_C 0x73 //channel 1 count for write
#define MASK8237 0X7a //mask for write
#define MODE8237 0x7b //mode for write
#define CMMD8237 0x78 //command for write
#define MASKS 0x7f //masks for write
#define RESET8237 0x7d //reset for write
#define REQ8237 0x79 //request register for write
#define STATUS 0x78 //status register for read
CDMA::CDMA(CWnd* pParent /*=NULL*/)
: CDialog(CDMA::IDD, pParent)
{
//{{AFX_DATA_INIT(CDMA)
m_Status =0;
//}}AFX_DATA_INIT
hDevice=NULL;
}
void CDMA::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDMA)
DDX_Text(pDX, IDC_EDIT5, m_Status);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDMA, CDialog)
//{{AFX_MSG_MAP(CDMA)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_BUTTON1, OnWrite1)
ON_BN_CLICKED(IDC_BUTTON2, OnRead1)
ON_BN_CLICKED(IDC_BUTTON3, OnWrite2)
ON_BN_CLICKED(IDC_BUTTON4, OnRead2)
ON_BN_CLICKED(IDC_BUTTON5, OnDma)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDMA message handlers
BOOL CDMA::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
UpdateData(FALSE);
m_data1.SubclassDlgItem(IDC_EDIT1, this );
m_data1.m_bShowAddress=FALSE;
m_data1.m_bShowHex=FALSE;
m_data2.SubclassDlgItem(IDC_EDIT2, this );
m_data2.m_bShowAddress=FALSE;
m_data2.m_bShowHex=FALSE;
m_data3.SubclassDlgItem(IDC_EDIT3, this );
m_data3.m_bShowAddress=FALSE;
m_data3.m_bShowHex=FALSE;
m_data4.SubclassDlgItem(IDC_EDIT4, this );
m_data4.m_bShowAddress=FALSE;
m_data4.m_bShowHex=FALSE;
if(hDevice==NULL)
{
hDevice = CreateFile(mDynVxDName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hDevice==INVALID_HANDLE_VALUE)
{
AfxMessageBox("请检查板卡和驱动程序");
CDialog::OnCancel();
return FALSE;
}
pMem=(Mem_Param*)malloc(sizeof(Mem_Param));
BOOL status = DeviceIoControl(
hDevice,
IOCTL_MEM,
NULL,
0,
pMem,
sizeof(pMem),
&nRet,
NULL);
}
W_AD=(Write_AD*)malloc(sizeof(Write_AD));
W_AD->Data=0x00;
W_AD->Address=0x2a;
DeviceIoControl(hDevice,
IOCTL_IO0W,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x43;
W_AD->Address=0x51;
DeviceIoControl(hDevice,
IOCTL_IO0W,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDMA::OnRadio1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data1.m_length=120;
m_data1.m_pData =(LPBYTE)malloc(m_data1.m_length);
for(int x=0;x<120;x++)
{
m_data1.m_pData [x]=0x55;
}
m_data1.m_bUpdate=TRUE;
m_data1.m_bShowAddress=TRUE;
m_data1.m_bShowHex=TRUE;
m_data1.SetScrollPos(SB_VERT,0);
m_data1.Invalidate ();
}
void CDMA::OnRadio2()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data1.m_length=120;
m_data1.m_pData =(LPBYTE)malloc(m_data1.m_length);
for(int x=0;x<120;x++)
{
m_data1.m_pData [x]=0xAA;
}
m_data1.m_bUpdate=TRUE;
m_data1.m_bShowAddress=TRUE;
m_data1.m_bShowHex=TRUE;
m_data1.SetScrollPos(SB_VERT,0);
m_data1.Invalidate ();
}
void CDMA::OnRadio3()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data1.m_length=120;
m_data1.m_pData =(LPBYTE)malloc(m_data1.m_length);
for(int x=0;x<120;x++)
{
m_data1.m_pData [x]=(BYTE)rand();
}
m_data1.m_bUpdate=TRUE;
m_data1.m_bShowAddress=TRUE;
m_data1.m_bShowHex=TRUE;
m_data1.SetScrollPos(SB_VERT,0);
m_data1.Invalidate ();
}
void CDMA::OnRadio6()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data3.m_length=120;
m_data3.m_pData =(LPBYTE)malloc(m_data3.m_length);
for(int x=0;x<120;x++)
{
m_data3.m_pData [x]=(BYTE)rand();
}
m_data3.m_bUpdate=TRUE;
m_data3.m_bShowAddress=TRUE;
m_data3.m_bShowHex=TRUE;
m_data3.SetScrollPos(SB_VERT,0);
m_data3.Invalidate ();
}
void CDMA::OnRadio5()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data3.m_length=120;
m_data3.m_pData =(LPBYTE)malloc(m_data3.m_length);
for(int x=0;x<120;x++)
{
m_data3.m_pData [x]=0xAA;
}
m_data3.m_bUpdate=TRUE;
m_data3.m_bShowAddress=TRUE;
m_data3.m_bShowHex=TRUE;
m_data3.SetScrollPos(SB_VERT,0);
m_data3.Invalidate ();
}
void CDMA::OnRadio4()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_data3.m_length=120;
m_data3.m_pData =(LPBYTE)malloc(m_data3.m_length);
for(int x=0;x<120;x++)
{
m_data3.m_pData [x]=0x55;
}
m_data3.m_bUpdate=TRUE;
m_data3.m_bShowAddress=TRUE;
m_data3.m_bShowHex=TRUE;
m_data3.SetScrollPos(SB_VERT,0);
m_data3.Invalidate ();
}
void CDMA::OnWrite1()
{
// TODO: Add your control notification handler code here
PBYTE m_d;
m_d=(PBYTE)pMem->mdr_LinearAddress+addoff;
for(int x=0;x<m_data1.m_length;x++)
{
*m_d=m_data1.m_pData [x];
m_d=m_d+1;
}
}
void CDMA::OnRead1()
{
// TODO: Add your control notification handler code here
m_data2.m_length=m_data1.m_length;
PBYTE m_d;
m_d=(PBYTE)pMem->mdr_LinearAddress+addoff;
m_data2.m_pData =(LPBYTE)malloc(m_data2.m_length);
for(int x=0;x<m_data2.m_length;x++)
{
m_data2.m_pData [x]=*m_d;
m_d=m_d+1;
}
m_data2.m_bUpdate=TRUE;
m_data2.m_bShowAddress=TRUE;
m_data2.m_bShowHex=TRUE;
m_data2.SetScrollPos(SB_VERT,0);
m_data2.Invalidate ();
}
void CDMA::OnWrite2()
{
// TODO: Add your control notification handler code here
PBYTE m_d;
m_d=(PBYTE)pMem->mdr_LinearAddress+addout;
for(int x=0;x<m_data3.m_length;x++)
{
*m_d=m_data3.m_pData [x];
m_d=m_d+1;
}
}
void CDMA::OnRead2()
{
// TODO: Add your control notification handler code here
m_data4.m_length=120;
//addout=0x800;
PBYTE m_d;
m_d=(PBYTE)pMem->mdr_LinearAddress+addout; //0x80
m_data4.m_pData =(LPBYTE)malloc(m_data4.m_length);
for(int x=0;x<m_data4.m_length;x++)
{
m_data4.m_pData [x]=*m_d;
m_d=m_d+1;
}
m_data4.m_bUpdate=TRUE;
m_data4.m_bShowAddress=TRUE;
m_data4.m_bShowHex=TRUE;
m_data4.SetScrollPos(SB_VERT,0);
m_data4.Invalidate ();
}
void CDMA::OnDma()
{
// TODO: Add your control notification handler code here
BYTE lastsend,aa,bb;
m_Status=0;
UpdateData(false);
PBYTE m_d;
m_d=(PBYTE)pMem->mdr_LinearAddress+addout;
W_AD->Data=0x67;
W_AD->Address=RESET8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x00;
W_AD->Address=CLEAR_F;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x48;
W_AD->Address=MODE8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x45;
W_AD->Address=MODE8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x00;
W_AD->Address=MASK8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x01;
W_AD->Address=MASK8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x01;
W_AD->Address=CMMD8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x0c;
W_AD->Address=MASKS;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
for (bb=0;bb<120;bb++)
{
aa=bb+0x80;
W_AD->Data=0x0c;
W_AD->Address=MASKS;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=bb;
W_AD->Address=0x70;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=00;
W_AD->Address=0x70;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=aa;
W_AD->Address=0x72;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x00;
W_AD->Address=0x72;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x00;
W_AD->Address=0x73;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x00;
W_AD->Address=0x73;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
W_AD->Data=0x04;
W_AD->Address=REQ8237;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
Sleep(5);
BYTE off=0x7d;
DeviceIoControl(
hDevice,
IOCTL_IOR,
&off,
sizeof(BYTE),
&lastsend,
0,
&nRet,
NULL);
*m_d=lastsend;
m_d=m_d+1;
}
m_Status=lastsend;
UpdateData(false);
}
void CDMA::OnOK()
{
// TODO: Add extra validation here
W_AD->Address=0x51;
W_AD->Data=0x42;
DeviceIoControl(hDevice,
IOCTL_IO0W,
W_AD,
sizeof(Write_AD)+1,
NULL,
0,
&nRet,
NULL);
if(hDevice!=NULL)
{
CloseHandle(hDevice);
hDevice=NULL;
}
// _outp(pci->IOBase[0]+0x51,0x42);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -