unit Sample1u; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Registry, ExtCtrls ; type TForm1 = class(TForm) Label5: TLabel; ExitBtn: TButton; TestBtn: TButton; Label1: TLabel; BaseLbl: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label6: TLabel; UpdateLbl: TLabel; LoopLbl: TLabel; StatusLbl: TLabel; Bevel1: TBevel; Timer1: TTimer; CheckBox1: TCheckBox; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; CheckBox2: TCheckBox; Panel1: TPanel; WDGLabel: TLabel; Label7: TLabel; GroupBox1: TGroupBox; Label8: TLabel; Label9: TLabel; BusNumberEdit: TEdit; BusTypeCombo: TComboBox; Bevel2: TBevel; ISAEdit: TEdit; Label10: TLabel; IRQEdit: TEdit; Label11: TLabel; procedure ExitBtnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure TestBtnClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private DriverRegistry:TRegistry; { Private declarations } public procedure SetHandler; end; const myKey = 'Software\PCIFIND\NTioPCI\Parameters'; var Form1: TForm1; BaseAddr: WORD; IRQ: WORD; Running: boolean; State : byte = 0; Loop : integer = 0; found: Boolean; implementation uses ACCES32, WDGThrd1, WDG; type TPCI_COMMON_CONFIG = record VendorID : word; DeviceID : word; Command : word; Status : word; RevisionID : byte; ProgIf : byte; SubClass : byte; BaseClass : byte; CacheLineSize : byte; LatencyTimer : byte; HeaderType : byte; BIST : byte; BaseAddresses : Array[0..5] of longint; Reserved1 : Array[0..1] of longint; RomBaseAddress : longint; Reserved2 : Array[0..1] of longint; InterruptLine : byte; InterruptPin : byte; MinimumGrant : byte; MaximumLatency : byte; end; var buf: array [0..63] of TPCI_COMMON_CONFIG; Thread : WDGThread; {$R *.DFM} procedure CtrMode(cntr,mode:byte); var ctrl:byte; begin ctrl := (cntr shl 6) or $30 or (mode shl 1); OutPortB(BaseAddr+3, ctrl); end; procedure LoadCtr(c,val:integer); begin OutPortB(BaseAddr+c, lo(val)); OutPortB(BaseAddr+c, hi(val)); end; procedure SetCounter; begin 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+$0C,0); {select low clock rate} InPortB(BaseAddr+$0D); {disable opto reset} InPortB(BaseAddr+$0E); {disable opto reset} InPortB(BaseAddr+$0F); {disable program outputs} {program the counters for the REQUIRED modes} CtrMode(0,3); {set counter 0 to mode 3} LoadCtr(0,$FFFF); {full load value} CtrMode(1,2); {set counter 1 to mode 2} LoadCtr(1,$10);{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 end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin InportB(BaseAddr + 6); InportB(BaseAddr + 7); end; procedure TForm1.ExitBtnClick(Sender: TObject); begin Close; end; (* Check for existence of card *) procedure TForm1.FormCreate(Sender: TObject); var num, i: Integer; begin found := false; DriverRegistry:=TRegistry.Create; DriverRegistry.RootKey:=HKEY_LOCAL_MACHINE; DriverRegistry.OpenKey(MyKey, True); if (InPortB($61) = $AA55) then begin Application.MessageBox('ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.', 'Warning', IDOK); end; try num := DriverRegistry.ReadInteger('NumDevices'); except on ERegistryException do num := 0; end; if (num > 0) then DriverRegistry.ReadBinaryData('PCICommonConfig', buf, num*sizeof(TPCI_COMMON_CONFIG)); for i := 0 to num - 1 do begin with buf[i] do begin if (DeviceID = $22C0) and (VendorID=$494F) then begin BaseAddr := BaseAddresses[2] AND $FFF8; IRQ := InterruptLine; BaseLbl.Caption:=IntToHex(BaseAddr,4); found := true; Break; end; end; end; if not found then begin // StatusLbl.Caption:='PCI-WDG-CSM Not Found'; ISAEdit.visible:=true; IRQEdit.visible:=true; Label10.visible:=true; Label5.caption:='Windows 95/NT WDG-CSM Sample 1'; //BaseLbl.Caption:='NOT FOUND!'; end; DriverRegistry.Free; end; procedure TForm1.SetHandler; var HandleCOS, HandleTimeout: BOOLEAN; TimeoutOp: WORD; BusType: Smallint; BusNumber: Byte; begin HandleCOS := CheckBox2.Checked; HandleTimeout := CheckBox1.Checked; TimeoutOp := IGNORE_TIMEOUT; if HandleTimeout then begin if RadioButton1.Checked then TimeoutOp := IGNORE_TIMEOUT else if RadioButton2.Checked then TimeoutOp := DISABLE_TIMEOUT else if RadioButton3.Checked then TimeoutOp := SHUTDOWN_TIMEOUT; end; try BusNumber := StrToInt(BusNumberEdit.Text); except BusNumber := 0; end; if (BusTypeCombo.Text = 'PCI') then BusType := PCIBus else if (BusTypeCombo.Text = 'ISA') then BusType := Isa else BusType := InterfaceTypeUndefined; WDGSetHandler(BaseAddr, IRQ, BusType, BusNumber, HandleCOS, HandleTimeout, TimeoutOp); end; procedure TForm1.TestBtnClick(Sender: TObject); begin if not found then begin BaseAddr:=StrToInt('$'+ISAEdit.text); IRQ:=StrToInt('$'+IRQEdit.text); end; if (TestBtn.Caption = '&Test') then begin SetHandler; Thread := WDGThread.Create(false); UpdateLbl.Visible := True; LoopLbl.Visible := True; TestBtn.Caption := '&Abort'; StatusLbl.Caption := 'Watchdog Okay'; SetCounter; Timer1.Enabled := True; end else begin InportB(BaseAddr + 6); InportB(BaseAddr + 7); Timer1.Enabled := False; TestBtn.Caption := '&Test'; State := 0; Loop := 0; Thread.Terminate; end; end; procedure TForm1.Timer1Timer(Sender: TObject); var readback : word; begin case State of 0: begin InportB(BaseAddr+4);// clear any pending interrupts OutPortB(BaseAddr+7,0);//start counters counting Inc(State); end; 1: begin CtrMode(1,2); LoadCtr(1,$10); Inc(Loop); if(Loop = 100) then Inc(State); LoopLbl.Caption := IntToStr(Loop); end; 2: begin readback := InPortB(BaseAddr+4); if((readback AND 1) = 0) then begin StatusLbl.Caption := 'Watchdog Timed Out'; TestBtn.Caption := '&Test'; Inc(State); Loop := 0; end else StatusLbl.Caption := 'Waiting for Timeout';//IntToStr(test); end; 3: begin Inc(Loop); if (Loop = 5) then begin InportB(BaseAddr + 6); Timer1.Enabled := False; State := 0; Loop := 0; Thread.Terminate; end; end; end; end; procedure TForm1.CheckBox1Click(Sender: TObject); begin RadioButton1.Enabled := CheckBox1.Checked; RadioButton2.Enabled := CheckBox1.Checked; RadioButton3.Enabled := CheckBox1.Checked; end; end.