source: ISPProgrammer/ISPprog/PortsIO.pas

Last change on this file was 363, checked in by chronos, 13 years ago
  • Added: Package ISPProgrammer for in-system programming of various chips. Supports Dallas ISP protocol, Presto, Rabbit RFU and some others Atmel devices.
File size: 2.6 KB
Line 
1unit PortsIO;
2
3{$MODE Delphi}
4
5interface
6
7{$INCLUDE Options.inc}
8
9function InPort(adr:word):byte;
10procedure OutPort(adr:word;y:byte);
11procedure Init;
12
13implementation
14
15uses
16 LCLIntf, SysUtils {$IFDEF WINDOWS},Windows{$ENDIF}
17{$IFDEF USE_INPOUT32}
18 , InpOut32
19{$ENDIF}
20 ;
21
22var
23 Initialized: Boolean;
24
25function InPort_direct(adr:word):byte; assembler;
26asm
27 mov dx,adr
28 in al,dx
29end;
30
31procedure OutPort_direct(adr:word;y:byte);
32begin
33 asm
34 mov dx,adr
35 mov al,y
36 out dx,al
37 end;
38end;
39
40function InPort(adr:word):byte;
41begin
42 {$IFDEF WINDOWS}
43{$IFDEF USE_INPOUT32}
44 if Win32Platform = VER_PLATFORM_WIN32_NT then
45 Result:=Inp32(adr) and $ff
46 else
47 Result:=InPort_direct(adr);
48{$ENDIF}
49
50{$IFDEF USE_GIVEIO}
51 Result:=InPort_direct(adr);
52{$ENDIF}
53{$ENDIF}
54end;
55
56procedure OutPort(adr:word;y:byte);
57begin
58 {$IFDEF WINDOWS}
59{$IFDEF USE_INPOUT32}
60 if Win32Platform = VER_PLATFORM_WIN32_NT then
61 Out32(adr,y)
62 else
63 OutPort_direct(adr,y);
64{$ENDIF}
65
66{$IFDEF USE_GIVEIO}
67 OutPort_direct(adr,y);
68{$ENDIF}
69{$ENDIF}
70end;
71
72{$IFDEF USE_GIVEIO}
73function InitializeGiveIo:boolean;
74var
75 hDriver:THandle;
76begin
77 hDriver := CreateFile('\\.\giveio', GENERIC_READ, 0, nil, OPEN_EXISTING,
78 FILE_ATTRIBUTE_NORMAL, 0);
79 if hDriver = INVALID_HANDLE_VALUE then
80 Result:=false
81 else
82 begin
83 if hDriver <> 0 then
84 CloseHandle(hDriver);
85 Result:=true;
86 end;
87end;
88{$ENDIF}
89
90procedure Init;
91begin
92 {$IFDEF WINDOWS}
93 if not Initialized then begin
94 if Win32Platform = VER_PLATFORM_WIN32_NT then
95 begin
96{$IFDEF USE_GIVEIO}
97 if not InitializeGiveIo then
98 begin
99 MessageBox(0,
100 'Can''t find giveio.sys driver.' + #13#10#13#10 +
101 'The giveio.sys driver must be installed' + #13#10 +
102 'before running ISP Programmer.' + #13#10#13#10 +
103 'Uninstall and install ISP Programmer again.',
104 'ISP Programmer', MB_OK or MB_ICONERROR);
105 ExitProcess(1);
106 end;
107{$ENDIF}
108
109{$IFDEF USE_INPOUT32}
110 if not IsInpOutDriverOpen then
111 begin
112 MessageBox(0,
113 'Can''t initialize InpOut32 driver.' + #13#10#13#10 +
114 'The InpOut32 driver must be installed' + #13#10 +
115 'before running ISP Programmer.' + #13#10#13#10 +
116 'Run ISP Programmer with administrator rights' + #13#10 +
117 'or uninstall and install ISP Programmer again.',
118 'ISP Programmer', MB_OK or MB_ICONERROR);
119 ExitProcess(1);
120 end;
121{$ENDIF}
122 end;
123 Initialized := True;
124 end;
125 {$ENDIF}
126end;
127
128initialization
129
130Initialized := False;
131
132end.
133
Note: See TracBrowser for help on using the repository browser.