source: ISPProgrammer/ISPprog/Globals.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: 7.1 KB
Line 
1unit Globals;
2
3{$MODE Delphi}
4
5interface
6
7{$INCLUDE Options.inc}
8
9uses Dialogs, Forms;
10
11type
12 TLPTpinout = packed record
13 strobe1:byte; // out
14 strobe2:byte; // out
15 reset:byte; // out
16 mosi:byte; // out
17 sck:byte; // out
18 miso:byte; // in
19 led:byte; // out
20 resetinv:boolean; // is RESET inverted
21 end;
22 PLPTpinout = ^TLPTpinout;
23
24const
25 DataPort = 0; // offset from BASE
26 StatusPort = 1; // offset from BASE
27 ControlPort = 2; // offset from BASE
28
29 // processor/memory types
30 PROC_TYPE_AVR = 0; // AT90, ATmega, ATtiny
31 PROC_TYPE_NEW51 = 1; // AT89[L]S51/52
32 PROC_TYPE_OLD51 = 2; // AT89S53/8252
33 PROC_TYPE_S8253 = 3; // AT89S8253
34 PROC_TYPE_S2051 = 4; // AT89S2051/4051
35 PROC_TYPE_DATAFLASH = 5; // AT25/26/45DB
36 PROC_TYPE_SERIALFLASH = 6; // AT25F
37 PROC_TYPE_I2C_BUS = 7; // I2C memories
38
39 // ISP operations
40 OP_READSIG = 1; // read signature
41 OP_ERASE = 2; // erase device
42 OP_BLANKCHECKFLASH = 4; // blank check Flash
43 OP_BLANKCHECKEEPROM = 8; // blank check EEPROM
44 OP_READFLASH = $10; // read Flash
45 OP_WRITEFLASH = $20; // write Flash
46 OP_VERIFYFLASH = $40; // verify Flash
47 OP_READEEPROM = $80; // read EEPROM
48 OP_WRITEEEPROM = $100; // write EEPROM
49 OP_VERIFYEEPROM = $200; // verify EEPROM
50 OP_READUSERSIG = $400; // read user signature
51 OP_WRITEUSERSIG = $800; // write user signature
52 OP_VERIFYUSERSIG = $1000;// verify user signature
53 OP_READFUSE = $2000; // read fuse bits
54 OP_WRITEFUSE = $4000; // write fuse bits
55 OP_VERIFYFUSE = $8000; // verify fuse bits
56 OP_READLOCK = $10000; // read lock bits
57 OP_WRITELOCK = $20000; // write lock bits
58 OP_VERIFYLOCK = $40000; // verify lock bits
59
60 // LPT outputs
61 LPT_OUT_STROBE = 0; // pin 1
62 LPT_OUT_D0 = 1; // pin 2
63 LPT_OUT_D1 = 2; // pin 3
64 LPT_OUT_D2 = 3; // pin 4
65 LPT_OUT_D3 = 4; // pin 5
66 LPT_OUT_D4 = 5; // pin 6
67 LPT_OUT_D5 = 6; // pin 7
68 LPT_OUT_D6 = 7; // pin 8
69 LPT_OUT_D7 = 8; // pin 9
70 LPT_OUT_AUTOLF = 9; // pin 14
71 LPT_OUT_INIT = 10; // pin 16
72 LPT_OUT_SELECTIN = 11; // pin 17
73 LPT_OUT_NOTUSED = 12;
74
75 // LPT inputs
76 LPT_IN_ACK = 0; // pin 10
77 LPT_IN_BUSY = 1; // pin 11
78 LPT_IN_PAPEREND = 2; // pin 12
79 LPT_IN_SELECT = 3; // pin 13
80 LPT_IN_ERROR = 4; // pin 15
81
82 // cable pinouts
83 LPT_PINOUT_ADD = 0;
84 LPT_PINOUT_AECISP = 1;
85 LPT_PINOUT_ALTERA = 2;
86 LPT_PINOUT_ATPROG = 3;
87 LPT_PINOUT_SIPROG = 4;
88 LPT_PINOUT_STK200 = 5;
89 LPT_PINOUT_UISP = 6;
90 LPT_PINOUT_CUSTOM = 7;
91
92 ISP_PINOUT_ADD:TLPTpinout = (
93 strobe1:LPT_OUT_STROBE;
94 strobe2:LPT_OUT_NOTUSED;
95 reset:LPT_OUT_AUTOLF;
96 mosi:LPT_OUT_INIT;
97 sck:LPT_OUT_SELECTIN;
98 miso:LPT_IN_ACK;
99 led:LPT_OUT_NOTUSED;
100 resetinv:false);
101
102 ISP_PINOUT_AECISP:TLPTpinout = (
103 strobe1:LPT_OUT_NOTUSED;
104 strobe2:LPT_OUT_NOTUSED;
105 reset:LPT_OUT_D4;
106 mosi:LPT_OUT_D5;
107 sck:LPT_OUT_D6;
108 miso:LPT_IN_ACK;
109 led:LPT_OUT_NOTUSED;
110 resetinv:false);
111
112 ISP_PINOUT_ALTERA:TLPTpinout = (
113 strobe1:LPT_OUT_AUTOLF;
114 strobe2:LPT_OUT_NOTUSED;
115 reset:LPT_OUT_D1;
116 mosi:LPT_OUT_D6;
117 sck:LPT_OUT_D0;
118 miso:LPT_IN_BUSY;
119 led:LPT_OUT_NOTUSED;
120 resetinv:false);
121
122 ISP_PINOUT_ATPROG:TLPTpinout = (
123 strobe1:LPT_OUT_NOTUSED;
124 strobe2:LPT_OUT_NOTUSED;
125 reset:LPT_OUT_D3;
126 mosi:LPT_OUT_D0;
127 sck:LPT_OUT_D1;
128 miso:LPT_IN_ACK;
129 led:LPT_OUT_NOTUSED;
130 resetinv:false);
131
132 ISP_PINOUT_SIPROG:TLPTpinout = (
133 strobe1:LPT_OUT_D3;
134 strobe2:LPT_OUT_D2;
135 reset:LPT_OUT_D7;
136 mosi:LPT_OUT_D5;
137 sck:LPT_OUT_D4;
138 miso:LPT_IN_ACK;
139 led:LPT_OUT_NOTUSED;
140 resetinv:false);
141
142 ISP_PINOUT_STK200:TLPTpinout = (
143 strobe1:LPT_OUT_D3;
144 strobe2:LPT_OUT_D2;
145 reset:LPT_OUT_D7;
146 mosi:LPT_OUT_D5;
147 sck:LPT_OUT_D4;
148 miso:LPT_IN_ACK;
149 led:LPT_OUT_D6;
150 resetinv:false);
151
152 ISP_PINOUT_UISP:TLPTpinout = (
153 strobe1:LPT_OUT_NOTUSED;
154 strobe2:LPT_OUT_NOTUSED;
155 reset:LPT_OUT_INIT;
156 mosi:LPT_OUT_D0;
157 sck:LPT_OUT_STROBE;
158 miso:LPT_IN_BUSY;
159 led:LPT_OUT_NOTUSED;
160 resetinv:false);
161
162 devicenr:byte = 0;
163
164var
165 proctype:byte; // processor type (AVR/51)
166 lptno:integer; // LPT port number
167 BASE:word; // LPT port base address
168 pinout:TLPTpinout; // LPT->ISP cable pinout
169 pinout_num:integer; // pinout type id
170 flashsize:integer; // Flash size in bytes
171 eepromsize:integer; // EEPROM size in bytes
172 usersigsize:integer; // User Signature size in bytes
173 MCUfreq:integer; // clock freq [Hz]
174 tCLK_AVR:integer; // clock period in ns
175 tCLK_8252:integer; // 40 clock periods in ns
176 forcedev:boolean; // force device with name forcename
177 forcename:string; // forced device name
178 autoop:longword; // auto operations mask
179
180{$IFDEF Windows}
181
182function MessageDlgCenter(const Msg: string; DlgType: TMsgDlgType;
183 Buttons: TMsgDlgButtons; HelpCtx: Longint; Form:TForm): Integer;
184
185function GetProgramVersionString:string;
186{$ENDIF}
187
188implementation
189
190{$IFDEF Windows}
191
192uses //Settings,
193 SysUtils, LCLIntf, Windows;
194
195function MessageDlgCenter(const Msg: string; DlgType: TMsgDlgType;
196 Buttons: TMsgDlgButtons; HelpCtx: Longint; Form:TForm): Integer;
197begin
198 with CreateMessageDialog(Msg, DlgType, Buttons) do
199 try
200 HelpContext := HelpCtx;
201 HelpFile := '';
202 Left:=Form.Left + (Form.Width - Width) div 2;
203 Top:=Form.Top + (Form.Height - Height) div 2;
204 Position:=poDesigned;
205 Result:=ShowModal;
206 finally
207 Free;
208 end;
209
210end;
211
212function GetProgramVersionString:string;
213var
214 filename:array[0..MAX_PATH-1] of char;
215 zero:DWORD;
216 infolen:DWORD;
217 infobuf:pointer;
218 verlen:UINT;
219 ptr:pointer;
220 verptr:PVSFixedFileInfo;
221begin
222 Result:='';
223 if GetModuleFileName(0, filename, MAX_PATH) > 0 then
224 if StrLen(filename) > 0 then
225 begin
226 zero:=0;
227 infolen:=GetFileVersionInfoSize(filename, zero);
228 if infolen > 0 then
229 begin
230 infobuf:=AllocMem(infolen);
231 if infobuf<>nil then
232 begin
233 ptr:=nil;
234 verlen:=0;
235 if GetFileVersionInfo(filename, 0, infolen, infobuf) then
236 if VerQueryValue(infobuf, '\', ptr, verlen) then
237 begin
238 verptr:=ptr;
239 Result:=
240 IntToStr(HiWord(verptr^.dwFileVersionMS)) + '.' +
241 IntToStr(LoWord(verptr^.dwFileVersionMS)) + '.' +
242 IntToStr(HiWord(verptr^.dwFileVersionLS)) + '.' +
243 IntToStr(LoWord(verptr^.dwFileVersionLS));
244 end;
245 FreeMem(infobuf);
246 end;
247 end;
248 end;
249end;
250
251{$ENDIF}
252
253initialization
254 //ReadSettingsFromRegistry(false, false, true);
255
256finalization
257 //WriteSettingsToRegistry(false, false, true);
258end.
259
Note: See TracBrowser for help on using the repository browser.