//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Sample3u.h" #include "acces32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; const char *myKey = "Software\\PCIFIND\\NTioPCI\\Parameters"; unsigned int BaseAddr; unsigned int IRQ; unsigned int Running; unsigned char State = 0; int Loop = 0; TPCI_COMMON_CONFIG buf[64]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void CtrMode(unsigned char cntr, unsigned char mode) { unsigned char ctrl; ctrl = (cntr << 6) | 0x30 | (mode << 1); OutPortB(BaseAddr+3, ctrl); } void LoadCtr(int c,int val) { OutPortB(BaseAddr+c, (0x00FF & val)); OutPortB(BaseAddr+c, (0xFF00 & val)>>8); } void 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 __fastcall TForm1::Timer1Timer(TObject *Sender) { unsigned int 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); Loop++; if(Loop == 100) State++; LoopLabel->Caption = IntToStr(Loop); break; case 2: readback = InPortB(BaseAddr+4); if ((readback & 1) == 0) { StatusLabel->Caption = "Watchdog Timed Out"; TestButton->Caption = "&Test"; State++; Loop = 0; } else StatusLabel->Caption = "Waiting for Timeout"; break; case 3: Loop++; if (Loop == 5) { InPortB(BaseAddr + 6); Timer1->Enabled = false; State = 0; Loop = 0; } break; } } //--------------------------------------------------------------------------- void __fastcall TForm1::TestButtonClick(TObject *Sender) { if (TestButton->Caption == "&Test") { UpdateLabel->Visible = true; LoopLabel->Visible = true; TestButton->Caption = "&Abort"; StatusLabel->Caption = "Watchdog Okay"; SetCounter(); Timer1->Enabled = true; }else { InPortB(BaseAddr + 6); InPortB(BaseAddr + 7); Timer1->Enabled = false; TestButton->Caption = "&Test"; State = 0; Loop = 0; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { InPortB(BaseAddr + 6); InPortB(BaseAddr + 7); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int num, i; unsigned int found; if (InPortB(0x61) == 0xAA55) { Application->MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", IDOK); } TRegistry *DriverRegistry = new TRegistry; found = false; DriverRegistry->RootKey = HKEY_LOCAL_MACHINE; DriverRegistry->OpenKey(myKey, true); num = DriverRegistry->ReadInteger("NumDevices"); if (num > 0) DriverRegistry->ReadBinaryData("PCICommonConfig", buf, (sizeof(TPCI_COMMON_CONFIG)*num)); for (i = 0; i<= num-1; i++) { if ((buf[i].DeviceID == 0x22C0) && (buf[i].VendorID == 0x494F)) { BaseAddr = buf[i].BaseAddresses[2] & 0xFFF8; IRQ = buf[i].InterruptLine; BaseLabel->Caption = IntToHex(int(BaseAddr),4); found = true; break; } } if (!found) { StatusLabel->Caption = "PCI-WDG-CSM Not Found"; BaseLabel->Caption = "NOT FOUND!"; } DriverRegistry->Free(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ExitButtonClick(TObject *Sender) { Close(); } //---------------------------------------------------------------------------