unit sample3u; 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; procedure ExitBtnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure TestBtnClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; const myKey = 'Software\PCIFIND\NTioPCI\Parameters'; var Form1: TForm1; BaseAddr: WORD; Running: boolean; State : byte = 0; Loop : integer = 0; implementation uses ACCES32; 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; {$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+$0C,0); {select low clock rate} InPortB(BaseAddr+$0D); {disable opto reset} InPortB(BaseAddr+$0E); {disable opto reset} {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 + 7); end; procedure TForm1.ExitBtnClick(Sender: TObject); begin Close; end; (* Check for existence of card *) procedure TForm1.FormCreate(Sender: TObject); var num, i: Integer; found: Boolean; DriverRegistry:TRegistry; 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 [Windows]/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 if VendorID = $494F then if (DeviceID = $25C0) or (DeviceID = $2FC0) or (DeviceID = $2FC1) then begin BaseAddr := BaseAddresses[2] AND $FFF8; BaseLbl.Caption := IntToHex(BaseAddr, 4); found := true; Break; end ; end; if not found then begin StatusLbl.Caption:='P104-WDG-CSM Not Found'; BaseLbl.Caption:='NOT FOUND!'; end; DriverRegistry.Free; end; procedure TForm1.TestBtnClick(Sender: TObject); begin if (TestBtn.Caption = '&Test') then begin UpdateLbl.Visible := True; LoopLbl.Visible := True; TestBtn.Caption := '&Abort'; StatusLbl.Caption := 'Watchdog Okay'; SetCounter; Timer1.Enabled := True; end else begin InportB(BaseAddr + 7); Timer1.Enabled := False; TestBtn.Caption := '&Test'; State := 0; Loop := 0; 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 Timer1.Enabled := False; State := 0; Loop := 0; end; end; end; end; end.