📄 mainfrm.~cp
字号:
ULONG returnCode;
DWORD comemID=0;
theApp.Out("Checking Driver Version.\n");
returnCode = getRev(comemID);
if(!returnCode)
theApp.Out("ERROR: Read Driver Version failure.\n");
else
{
theApp.Out("Driver Version: Major=0x%04x Minor=0x%04x\n",
((returnCode & 0xffff0000)>>16), (returnCode & 0xffff));
theApp.Out("Read Driver Version OK.\n");
}
}
void CMainFrame::OnHelpAnchorchipswebsite()
{
// For URL, open it in the browser
HINSTANCE h = ShellExecute(NULL, "open", "http://www.cypress.com/", NULL, NULL, SW_SHOWNORMAL);
if(!((UINT)h > 32))
{
AfxMessageBox("Sorry: cannot access web location", MB_OK | MB_ICONEXCLAMATION);
}
}
void CMainFrame::OnHelpContactanchorchips()
{
HINSTANCE h = ShellExecute(NULL, "open", "mailto:siv@cypress.com", NULL, NULL, SW_SHOWNORMAL);
if(!((UINT)h > 32))
{
AfxMessageBox("Sorry: cannot access email", MB_OK | MB_ICONEXCLAMATION);
}
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
// **** These button enable/disable and activate/deactivate variables are designed to
// restrict the button/menu options that the user has for transmitting and receiving
// data blocks. Changed as needed for the application.
//
// 924 Eval Board global vars
bool initActive = false , txActive = false, rxActive = false;
bool txEnable = true, rxEnable = true;
const DWORD regWait = 10;
const DWORD longWait = 100;
DWORD evalBoardInit(DWORD comemID);
DWORD evalBoardRx(DWORD comemID);
DWORD evalBoardTx(DWORD comemID);
DWORD evalBoardRx2(DWORD comemID, DWORD linPage1, DWORD physPage1, WORD block_id);
DWORD evalBoardTx2(DWORD comemID, DWORD linPage, DWORD physPage, WORD block_id);
void evalBoardAddW(DWORD, DWORD, DWORD, int);
void evalBoardAddR(DWORD, DWORD, int);
bool hex2dec(DWORD & outInt, CString inStr);
// Initialize the board
void CMainFrame::OnEvalboardInit()
{
ULONG returnCode;
DWORD comemID = 0;
theApp.Out("\n***** Starting the EvalBoard Initialization procedure...\n");
// Call the init routine and make sure it was successful
returnCode = evalBoardInit(comemID);
if (returnCode == 0)
{
initActive = true;
theApp.Out("OK: evalBoardInit passed.\n");
}
else
{
initActive = false;
theApp.Out("ERROR: evalBoardInit failed.\n");
}
}
// Receive a block of data
void CMainFrame::OnEvalboardRx()
{
DWORD comemID = 0;
theApp.Out("\n***** Starting the EvalBoard Receive procedure...\n");
ULONG returnCode = evalBoardRx(comemID);
if (returnCode == 0)
{
txActive = false;
theApp.Out("OK: evalBoardRx passed.\n");
}
else
{
theApp.Out("ERROR: evalBoardRx failed.\n");
}
}
// Transmit a block of data
void CMainFrame::OnEvalboardTx()
{
DWORD comemID = 0;
theApp.Out("\n***** Starting the EvalBoard Transmit procedure...\n");
ULONG returnCode = evalBoardTx(comemID);
if (returnCode == 0)
{
txActive = true;
theApp.Out("OK: evalBoardTx passed.\n");
}
else
{
theApp.Out("ERROR: evalBoardTx failed.\n");
}
}
void CMainFrame::OnUpdateEvalboardInit(CCmdUI* pCmdUI)
{
// Enable the user-interface object (menu item or tool-
// bar button) if not initialized.
pCmdUI->SetCheck(initActive);
}
void CMainFrame::OnUpdateEvalboardRx(CCmdUI* pCmdUI)
{
// Enable the user-interface object (menu item or tool-
// bar button) if not initialized.
pCmdUI->Enable( rxEnable);
// pCmdUI->SetCheck( rxActive );
}
void CMainFrame::OnUpdateEvalboardTx(CCmdUI* pCmdUI)
{
// Enable the user-interface object (menu item or tool-
// bar button) if not initialized.
pCmdUI->Enable( txEnable);
// pCmdUI->SetCheck( txActive);
}
// Dialog box initialization values
CString WrRdAdd = "4000", WrData = "12345678";
int WrRdSize = 2, WrRdType = 1; // default to 32-bit addressing
DWORD WrRdLoops = 1, MulRWLoops = 0, MulRLoops = 1000, MulWLoops = 0;
// Open the Address Write dialog box and process it
// NOTE: ---- The dialog box data input field is suppose to accept values
// between 0 and 2^32. But, somehow, it accepts 0 to any positive integer and
// only writes a max value of 2^32 into the Eval Board's PCI-DP.
void CMainFrame::OnEvalboardAddresswrite()
{
DWORD comemID=0, address, maxAdd, incSize;
AddWriteDlg dlg;
// Initialize dialog data. Can be overridden by the OnInitDialog() member function.
dlg.m_EvalWriteAdd = WrRdAdd;
dlg.m_EvalWriteData = WrData;
dlg.m_EvalRadioWrite = WrRdSize;
dlg.m_EvalRadioWrType = WrRdType;
dlg.m_EvalWriteLoops = WrRdLoops;
// theApp.Out("Opening the Address Write Dialog Box...\n");
if(dlg.DoModal() == IDOK)
{
WrRdAdd = dlg.m_EvalWriteAdd;
WrData = dlg.m_EvalWriteData;
WrRdSize = dlg.m_EvalRadioWrite;
WrRdType = dlg.m_EvalRadioWrType;
WrRdLoops = dlg.m_EvalWriteLoops;
address = dlg.m_HexWriteAdd;
switch (dlg.m_EvalRadioWrite)
{
case 0: maxAdd = 0x7fff; incSize = 1; break;
case 1: maxAdd = 0x7ffe; incSize = 2; break;
case 2: maxAdd = 0x7ffc; incSize = 4; break;
default: theApp.Out ("Unexpected error.\n"); return;
}
for (DWORD i = 0; i < dlg.m_EvalWriteLoops; ++i)
{
evalBoardAddW(comemID, address, dlg.m_HexWriteData,
dlg.m_EvalRadioWrite);
if (dlg.m_EvalRadioWrType == 1)
{
address += incSize;
// The selection statement below has a little glitch.
// If a read/write starts at an address that is not a multiple
// of the word size, The last few bytes are never accessed.
// For example, writing 10 32-bit words starting at 0x7ff2 will
// not write/read anything from 0x7ffe-0x7fff since the program
// cannot read a full 32-bit word starting at 0x7ffe.
if (address > maxAdd)
address = 0x4000;
}
}
theApp.Out ("-----\n");
}
}
// Open the Address Read dialog box and process it
void CMainFrame::OnEvalboardAddressread()
{
DWORD comemID=0, address, maxAdd, incSize;
AddReadDlg dlg;
// Initialize dialog data. Can be overridden by the OnInitDialog() member function.
dlg.m_EvalReadAdd = WrRdAdd;
dlg.m_EvalRadioRead = WrRdSize;
dlg.m_EvalRadioRdType = WrRdType;
dlg.m_EvalReadLoops = WrRdLoops;
// theApp.Out("Opening the Address Read Dialog Box...\n");
if(dlg.DoModal() == IDOK)
{
WrRdAdd = dlg.m_EvalReadAdd;
WrRdSize = dlg.m_EvalRadioRead;
WrRdType = dlg.m_EvalRadioRdType;
WrRdLoops = dlg.m_EvalReadLoops;
address = dlg.m_HexReadAdd;
switch (dlg.m_EvalRadioRead)
{
case 0: maxAdd = 0x7fff; incSize = 1; break;
case 1: maxAdd = 0x7ffe; incSize = 2; break;
case 2: maxAdd = 0x7ffc; incSize = 4; break;
default: theApp.Out ("Unexpected error.\n"); return;
}
for (DWORD i = 0; i < dlg.m_EvalReadLoops; ++i)
{
evalBoardAddR(comemID, address, dlg.m_EvalRadioRead);
if (dlg.m_EvalRadioRdType == 1)
{
address += incSize;
// The selection statement below has a little glitch.
// If a read/write starts at an address that is not a multiple
// of the word size, The last few bytes are never accessed.
// For example, writing 10 32-bit words starting at 0x7ff2 will
// not write/read anything from 0x7ffe-0x7fff since the program
// cannot read a full 32-bit word starting at 0x7ffe.
if (address > maxAdd)
address = 0x4000;
}
}
theApp.Out (" -----\n");
}
}
// Open the Multiple Read & Write dialog box and process it
void CMainFrame::OnEvalboardMulrw()
{
DWORD comemID=0,rxFailCount = 0, txFailCount = 0;
CMulRWDlg dlg;
ULONG returnCode;
const DWORD MAX_LOOP_WAITS = 100;
// Initialize dialog data
dlg.m_EvalRWLoops = MulRWLoops;
dlg.m_EvalRLoops = MulRLoops;
dlg.m_EvalWLoops = MulWLoops;
// theApp.Out("Opening the Multiple Read/Write Dialog Box...\n");
if(dlg.DoModal() == IDOK)
{
// -----------
#if 1
// Create buffers in host mem for DMA operation
DWORD linPage;
DWORD physPage;
// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
//theApp.Out ("here1\n");
returnCode = comemAllocContigMemL(4, &linPage, &physPage, comemID);
// theApp.Out ("here2\n");
if (returnCode != NO_ERROR)
{
theApp.Out("Error Allocating Contiguous Memory\n");
return;
}
/* returnCode = comemAllocContigMemL(4, &linPage1, &physPage1, comemID);
theApp.Out ("here3\n");
if (returnCode != NO_ERROR)
{
theApp.Out("Error Allocating Contiguous Memory\n");
return;
}
*/
// -----------
int i;
div_t div_result;
MulRWLoops = dlg.m_EvalRWLoops;
MulRLoops = dlg.m_EvalRLoops;
MulWLoops = dlg.m_EvalWLoops;
//theApp.Out ("here4\n");
// 1. The READ & WRITE loops
if (dlg.m_EvalRWLoops > 0)
{
theApp.Out ("\n1. Starting %i block reads and writes...\nLoop:",dlg.m_EvalRWLoops);
for (i = dlg.m_EvalRWLoops; i > 0; --i)
{
returnCode = evalBoardTx2(comemID, linPage, physPage, i);
if (returnCode != 0)
{
++txFailCount;
theApp.Out("ERROR: evalBoardTx failed on block %i.\n", i);
comemDeAllocContigMemL(&linPage, &physPage, comemID);
return;
}
returnCode = evalBoardRx2(comemID, linPage, physPage, i);
if (returnCode != 0)
{
++rxFailCount;
theApp.Out("ERROR: evalBoardRx failed on block %i.\n", i);
comemDeAllocContigMemL(&linPage, &physPage, comemID);
return;
}
div_result = div( i, 100 );
if (div_result.rem == 0)
{
theApp.Out ("%6i\t",i);
}
}
theApp.Out("\nFail Counts: Tx:%i\tRx:%i\n", txFailCount, rxFailCount);
}
//2.The WRITE loops
if (dlg.m_EvalWLoops > 0)
{
theApp.Out ("\n2. Starting %i block writes ...\nLoop:",dlg.m_EvalWLoops);
for (i = dlg.m_EvalWLoops; i > 0; --i)
{
returnCode = evalBoardTx2(comemID, linPage, physPage, i);
if (returnCode != 0)
{
++txFailCount;
theApp.Out("ERROR: evalBoardTx failed on block %i.\n", i);
comemDeAllocContigMemL(&linPage, &physPage, comemID);
return;
}
div_result = div( i, 100 );
if (div_result.rem == 0)
{
theApp.Out ("%6i\t",i);
}
}
theApp.Out("\nFail Counts: Tx:%i\n",txFailCount);
}
if (dlg.m_EvalRLoops > 0)
{
//3.The READ loops
theApp.Out ("\n3. Starting %i block reads ...\nLoop:",dlg.m_EvalRLoops);
for (i = dlg.m_EvalRLoops; i > 0; --i)
{
returnCode = evalBoardRx2(comemID, linPage, physPage, i);
if (returnCode != 0)
{
++rxFailCount;
theApp.Out("ERROR: evalBoardRx failed on block %i.\n", i);
comemDeAllocContigMemL(&linPage, &physPage, comemID);
return;
}
div_result = div( i, 100 );
if (div_result.rem == 0)
{
theApp.Out ("%6i\t",i);
}
}
theApp.Out("\nFail Counts: Rx:%i\n", rxFailCount);
}
theApp.Out("\nEnd.\n");
// Deallocate buffer in host memory for transmit and receive blocks.
comemDeAllocContigMemL(&linPage, &physPage, comemID);
// comemDeAllocContigMemL(&linPage1, &physPage1, comemID);
#endif
// theApp.Out ("what\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -