📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Test3042.h"
#include "MainFrm.h"
#include "InitE2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND_EX(CG_ID_VIEW_TESTDIALOGBAR, OnBarCheck)
ON_UPDATE_COMMAND_UI(CG_ID_VIEW_TESTDIALOGBAR, OnUpdateControlBarMenu)
ON_COMMAND_EX(ID_VIEW_TEST_TBAR, OnBarCheck)
ON_UPDATE_COMMAND_UI(ID_VIEW_TEST_TBAR, OnUpdateControlBarMenu)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_TEST_ALL, OnTestAll)
ON_COMMAND(ID_TEST_CONFIGREGS, OnTestConfigregs)
ON_COMMAND(ID_TEST_EEPROM, OnTestEeprom)
ON_COMMAND(ID_TEST_MEM, OnTestMem)
ON_COMMAND(ID_TEST_OP_REGS, OnTestOpRegs)
ON_COMMAND(ID_TEST_DMA, OnTestDma)
ON_COMMAND(ID_UTIL_INIT_EEPROM, OnUtilInitEeprom)
ON_COMMAND(ID_UTIL_ERASE_EEPROM, OnUtilEraseEeprom)
ON_COMMAND(ID_UTIL_SHOW_EEPROM, OnUtilShowEeprom)
ON_COMMAND(ID_UTIL_CHECK_EEPROM, OnUtilCheckEeprom)
ON_COMMAND(ID_TEST_INT, OnTestInt)
ON_COMMAND(ID_TEST_RESET, OnTestReset)
ON_COMMAND(ID_UTIL_DMA_TO_TARG, OnUtilDmaToTarg)
ON_COMMAND(IDR_TEST_RUN, OnTestRun)
ON_COMMAND(ID_UTIL_GETDRIVERREVISION, OnUtilGetdriverrevision)
ON_COMMAND(ID_HELP_ANCHORCHIPSWEBSITE, OnHelpAnchorchipswebsite)
ON_COMMAND(ID_HELP_CONTACTANCHORCHIPS, OnHelpContactanchorchips)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// TPM: Add a test toolbar with visibility ID: ID_VIEW_
// TPM: Add toggle entry to IDR_MAINFRAME
// TPM: Add ON_COMMAND_EX, ON_UPDATE_COMMAND_UI
{
if (!m_wndTestBar.Create(this,
WS_CHILD | CBRS_TOP | WS_VISIBLE |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
ID_VIEW_TEST_TBAR) ||
!m_wndTestBar.LoadToolBar(IDR_TEST))
{
TRACE0("Failed to create Test bar\n");
return -1; // fail to create
}
m_wndTestBar.SetWindowText(_T("Test"));
// make dockable
m_wndTestBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndTestBar);
DockControlBarLeftOf(&m_wndTestBar,&m_wndToolBar);
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
RecalcLayout(); // get MFC to adj dimensions of all docked ToolBars
LeftOf->GetWindowRect(&rect);
rect.OffsetRect(1,0);
dw=LeftOf->GetBarStyle();
n = 0;
n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
DockControlBar(Bar,n,&rect); //simulate Toolbar dragged to location and docked
}
// prototypes
DWORD testConfigRegs (DWORD comemID);
DWORD testEEPROM (DWORD comemID);
DWORD testSharedMem (DWORD comemID);
DWORD testOpRegs (DWORD comemID);
DWORD testDMAtoHost(DWORD comemID);
DWORD testDMAtoTarg(DWORD comemID);
void initEEPROM (DWORD comemID, USHORT m_usCBoxLocBusCfg, UCHAR m_ucResHold,
USHORT m_usVenID, USHORT m_usDevID, USHORT m_usSubSysVenID, USHORT m_usSubSysDevID,
USHORT m_usRevisionID, USHORT m_usMaxLat, USHORT m_usMinGnt, UINT m_uiClassCode, USHORT m_usIntPin);
void zeroEEPROM (DWORD comemID);
void checkEEPROM (DWORD comemID);
DWORD readEepromFunc(DWORD comemID);
DWORD testInt(DWORD comemID);
DWORD testReset(DWORD comemID);
DWORD testRun(DWORD comemID);
DWORD getRev(DWORD comemID);
void reportErrorCode(DWORD status, char * whereAmI);
void CMainFrame::OnTestAll()
{
theApp.Out("OnTestAll()\n");
OnTestMem();
OnTestOpRegs();
OnTestConfigregs();
OnTestInt();
OnTestReset();
}
void CMainFrame::OnTestConfigregs()
{
ULONG returnCode;
DWORD comemID=0;
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testConfigRegs(comemID);
if (!returnCode)
theApp.Out("OK: testConfigRegs Passed.\n");
else
theApp.Out("ERROR: testConfigRegs failure.\n");
}
void CMainFrame::OnTestEeprom()
{
ULONG returnCode;
DWORD comemID=0;
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testEEPROM(comemID);
if (!returnCode)
theApp.Out("OK: testEEPROM Passed.\n");
else
theApp.Out("ERROR: testEEPROM failure.\n");
}
void CMainFrame::OnTestMem()
{
ULONG returnCode;
DWORD comemID=0;
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testSharedMem(comemID);
if (!returnCode)
theApp.Out("OK: test Memory Passed.\n");
else
theApp.Out("ERROR: test Memory failure.\n");
}
void CMainFrame::OnTestOpRegs()
{
ULONG returnCode;
DWORD comemID=0;
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testOpRegs(comemID);
if (!returnCode)
theApp.Out("OK: testOpRegs Passed.\n");
else
theApp.Out("ERROR: testOpRegs failure.\n");
}
void CMainFrame::OnTestDma()
{
ULONG returnCode;
DWORD comemID=0;
returnCode = 0;
/*
theApp.Out("OK: testDMA skipped.\n");
*/
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testDMAtoHost(comemID);
if (!returnCode)
theApp.Out("OK: testDMA to Host Passed.\n");
else
theApp.Out("ERROR: testDMA to Host failure.\n");
// OnUtilDmaToTarg();
}
void CMainFrame::OnUtilInitEeprom()
{
DWORD comemID=0;
InitE2 dlg;
if(dlg.DoModal() == IDOK)
{
theApp.Out("Initializing EEPROM contents...\n");
initEEPROM(comemID, dlg.m_usCBoxLocBusCfg, dlg.m_ucResHold,
dlg.m_usVenID, dlg.m_usDevID, dlg.m_usSubSysVenID, dlg.m_usSubSysDevID,
dlg.m_usRevisionID, dlg.m_usMaxLat, dlg.m_usMinGnt, dlg.m_uiClassCode, dlg.m_usIntPin);
theApp.Out("Initialize EEPROM contents complete\n");
}
}
void CMainFrame::OnUtilEraseEeprom()
{
DWORD comemID=0;
theApp.Out("Erasing EEPROM contents...\n");
zeroEEPROM(comemID);
theApp.Out("Erase EEPROM contents complete\n");
}
void CMainFrame::OnUtilShowEeprom()
{
DWORD comemID=0;
readEepromFunc(comemID);
}
void CMainFrame::OnUtilCheckEeprom()
{
DWORD comemID=0;
theApp.Out("Checking EEPROM contents...\n");
checkEEPROM(comemID);
theApp.Out("Check EEPROM contents complete\n");
}
void CMainFrame::OnTestInt()
{
ULONG returnCode;
DWORD comemID=0;
theApp.Out("Checking Interrupts...\n");
returnCode = testInt(comemID);
if (!returnCode)
theApp.Out("OK: Check Interrupts OK.\n");
else
theApp.Out("ERROR: Check Interrupts failure.\n");
theApp.Out("Check Interrupts complete\n");
}
void CMainFrame::OnTestReset()
{
ULONG returnCode;
DWORD comemID=0;
theApp.Out("Reset Target...\n");
returnCode = testReset(comemID);
if (!returnCode)
theApp.Out("OK: Reset Target OK.\n");
else
theApp.Out("ERROR: Reset Target failure.\n");
}
void CMainFrame::OnUtilDmaToTarg()
{
ULONG returnCode;
DWORD comemID=0;
if (returnCode = testReset(comemID))
theApp.Out("ERROR: Reset Target failure.\n");
returnCode = testDMAtoTarg(comemID);
if (!returnCode)
theApp.Out("OK: testDMA to Targ Passed.\n");
else
theApp.Out("ERROR: testDMA to Targ failure.\n");
}
void CMainFrame::OnTestRun()
{
ULONG returnCode;
DWORD comemID=0;
theApp.Out("Releasing Target Reset...\n");
returnCode = testRun(comemID);
}
void CMainFrame::OnUtilGetdriverrevision()
{
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.anchorchips.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:apps@anchorchips.com", NULL, NULL, SW_SHOWNORMAL);
if(!((UINT)h > 32))
{
AfxMessageBox("Sorry: cannot access email", MB_OK | MB_ICONEXCLAMATION);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -