// PCIWDGDlg.cpp : implementation file // #include "stdafx.h" #include "WDGThrd.h" #include "PCIWDG.h" #include "PWDGDlg.h" #include "ACCES32.h" #include "WDG.h" #define MyKey "Software\\PCIFIND\\NTioPCI\\Parameters" TPCI_COMMON_CONFIG buf[64]; WDGThread *thread; bool Testing; bool found; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPCIWDGDlg dialog CPCIWDGDlg::CPCIWDGDlg(CWnd* pParent /*=NULL*/) : CDialog(CPCIWDGDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPCIWDGDlg) // m_BaseAddress = _T(""); m_Base = _T("300"); m_IRQ = _T("5"); m_IRQLabel = _T(""); m_HandleCOS = FALSE; m_HandleTimeout = FALSE; m_BusType = _T(""); m_BusNumber = 0; m_StatusByte = _T(" Status: 00"); m_StatusLabel = _T(""); m_IgnoreValue = 0; m_LoopLabel = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPCIWDGDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPCIWDGDlg) DDX_Control(pDX, IDC_BASEEDIT, m_IsaEditCtrl); DDX_Control(pDX, IDC_IRQEDIT, m_IrqEditCtrl); DDX_Control(pDX, IDC_IRQ, m_IrqCtrl); DDX_Control(pDX, IDOK, m_TestButton); DDX_Control(pDX, IDC_SHUTDOWN, m_ShutdownButton); DDX_Control(pDX, IDC_DISABLE, m_DisableButton); DDX_Control(pDX, IDC_IGNORE, m_IgnoreButton); DDX_Text(pDX, IDC_BASELABEL, m_BaseAddress); DDX_Text(pDX, IDC_BASEEDIT, m_Base); DDX_Text(pDX, IDC_IRQEDIT, m_IRQ); DDX_Text(pDX, IDC_IRQ, m_IRQLabel); DDX_Check(pDX, IDC_CHECK1, m_HandleCOS); DDX_Check(pDX, IDC_CHECK2, m_HandleTimeout); DDX_CBString(pDX, IDC_COMBO1, m_BusType); DDX_Text(pDX, IDC_EDIT1, m_BusNumber); DDX_Text(pDX, IDC_STATUSBYTE, m_StatusByte); DDX_Text(pDX, IDC_STATUSLABEL, m_StatusLabel); DDX_Radio(pDX, IDC_IGNORE, m_IgnoreValue); DDX_Text(pDX, IDC_LOOPLABEL, m_LoopLabel); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPCIWDGDlg, CDialog) //{{AFX_MSG_MAP(CPCIWDGDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_CHECK2, OnHandleTimeoutCheck) ON_WM_SHOWWINDOW() ON_WM_CLOSE() ON_BN_CLICKED(IDCANCEL, OnExitButton) ON_BN_CLICKED(IDOK, OnTestButton) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPCIWDGDlg message handlers BOOL CPCIWDGDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon if (InPortB(0x61) == 0xAA55) { MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", MB_OK); } // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CPCIWDGDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CPCIWDGDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CPCIWDGDlg::OnHandleTimeoutCheck() { UpdateData(true); m_IgnoreButton.EnableWindow(m_HandleTimeout); m_DisableButton.EnableWindow(m_HandleTimeout); m_ShutdownButton.EnableWindow(m_HandleTimeout); } void CPCIWDGDlg::OnShowWindow(BOOL bShow, UINT nStatus) { CDialog::OnShowWindow(bShow, nStatus); FindCards(); } void CPCIWDGDlg::FindCards(void) { HKEY Key; DWORD DataType, DataSize, num, i; found = false; RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, KEY_ALL_ACCESS, &Key); DataSize = sizeof(num); RegQueryValueEx(Key, "NumDevices", NULL, &DataType, (PUCHAR)&num, &DataSize); if (num > 0) { DataSize = num * sizeof(TPCI_COMMON_CONFIG); RegQueryValueEx(Key, "PCICommonConfig", NULL, &DataType, (PUCHAR)buf, &DataSize); } for (i=0; i>8) & 0xFF); } void CPCIWDGDlg::SetCounter() { InPortB(BaseAddr+7); // disable counter functions CtrMode(2,0); // set counter 2 to mode 0 OutPortB(BaseAddr+7,0); // enable counters InPortB(BaseAddr+7); // disable counter functions OutPortB(BaseAddr+6,0); // enable buzzer OutPortB(BaseAddr+0x0C,0); // select low clock rate InPortB(BaseAddr+0x0D); // disable opto reset InPortB(BaseAddr+0x0E); // disable opto reset InPortB(BaseAddr+0x0F); // disable program outputs // program the counters for the REQUIRED modes CtrMode(0,3); // set counter 0 to mode 3 LoadCtr(0,0xFFFF); // full load value CtrMode(1,2); // set counter 1 to mode 2 LoadCtr(1,0x10); // load counter 1 with 10 hex CtrMode(2,1); // set counter 2 to mode 1 // Note:Not loading counter 2 creates an infinite reset duration // Set the reset duration by loading a value in counter 2 // Change counter 2 to mode 2 to set duration } void CPCIWDGDlg::SetHandler() { unsigned short TimeoutOp; short BusType; UpdateData(true); TimeoutOp = IGNORE_TIMEOUT; if (m_HandleTimeout) { if (m_IgnoreValue + 1 == IGNORE_TIMEOUT) TimeoutOp = IGNORE_TIMEOUT; else if (m_IgnoreValue + 1 == DISABLE_TIMEOUT) TimeoutOp = DISABLE_TIMEOUT; else if (m_IgnoreValue + 1 == SHUTDOWN_TIMEOUT) TimeoutOp = SHUTDOWN_TIMEOUT; } if (m_BusType == "PCI") BusType = PCIBus; else if (m_BusType == "ISA") BusType = Isa; else BusType = InterfaceTypeUndefined; WDGSetHandler(BaseAddr, IRQ, BusType, m_BusNumber, m_HandleCOS, m_HandleTimeout, TimeoutOp); } void CPCIWDGDlg::OnTestButton() { if (!found){ UpdateData(true); sscanf(m_Base, "%x", &BaseAddr); sscanf(m_IRQ, "%x", &IRQ); } if (!Testing) { SetCounter(); SetHandler(); m_TestButton.SetWindowText("&Abort"); m_StatusLabel = " Watchdog Okay"; Testing = true; State = Loop = 0; SetTimer(0, 35, NULL); thread = (WDGThread*)AfxBeginThread(RUNTIME_CLASS(WDGThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL); thread->InitWnd(m_hWnd); thread->ResumeThread(); } else { InPortB(BaseAddr + 6); InPortB(BaseAddr + 7); KillTimer(0); m_TestButton.SetWindowText("&Test"); State = Loop = 0; Testing = false; // thread->Done = true; } UpdateData(false); } void CPCIWDGDlg::OnTimer(UINT nIDEvent) { unsigned short readback; switch(State) { case 0: InPortB(BaseAddr+4); // clear any pending interrupts OutPortB(BaseAddr+7,0); // start counters counting State++; break; case 1: CtrMode(1,2); LoadCtr(1,0x10); // keep reloading counter if (++Loop == 100) State++; char text[64]; sprintf(text, " Updating counter 1 ... loop number: %3.3d", Loop); m_LoopLabel = text; break; case 2: readback = InPortB(BaseAddr+4); if ((readback & 0x01) == 0) { m_StatusLabel = " Watchdog Timed Out"; m_TestButton.SetWindowText("&Test"); Testing = false; State++; Loop = 0; } else m_StatusLabel = " Waiting for Timeout"; break; case 3: Loop++; if (Loop == 5) { InPortB(BaseAddr + 6); KillTimer(0); State = Loop = 0; // thread->Done = true; } break; } UpdateData(false); CDialog::OnTimer(nIDEvent); }