source: ISPProgrammer/ISPprog/ISP_Fusebits.pas

Last change on this file was 363, checked in by chronos, 12 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: 4.5 KB
Line 
1unit ISP_Fusebits;
2
3{$MODE Delphi}
4
5interface
6
7function ISPReadFuseBits(var fblo,fbhi,fbext:byte):integer;
8procedure ISPWriteFuseLoBits(fuse:byte);
9procedure ISPWriteFuseHiBits(fuse:byte);
10procedure ISPWriteFuseExtBits(fuse:byte);
11function AnyFuseLo:boolean;
12function AnyFuseHi:boolean;
13function AnyFuseExt:boolean;
14function AnyFuse:boolean;
15
16implementation
17
18uses Delays, Globals, Processors, SPI;
19
20function ISPReadFuseBits(var fblo,fbhi,fbext:byte):integer;
21var data:array[0..2] of byte;
22begin
23 if not AnyFuse then
24 begin
25 Result:=-1;
26 Exit; // no fuse bits accessible by ISP
27 end;
28 Result:=0;
29 fblo:=0;
30 fbhi:=0;
31 fbext:=0;
32 case Signatures[devicenr].algo_lb of
33 ALGO_LB_89S8253, ALGO_LB_89S2051:
34 begin
35 data[0] := $21;
36 data[1] := $00;
37 data[2] := $00;
38 WriteBytes(@data, 3);
39 fblo:=ReadByte and $0f;
40 end;
41 ALGO_LB_2323:
42 begin
43 data[0] := $58;
44 data[1] := $00;
45 data[2] := $00;
46 WriteBytes(@data, 3);
47 fblo:=ReadByte and $01;
48 end;
49 ALGO_LB_2333:
50 begin
51 data[0] := $a0;
52 data[1] := $00;
53 data[2] := $00;
54 WriteBytes(@data, 3);
55 fblo:=ReadByte;
56 end;
57 ALGO_LB_MEGA, ALGO_LB_TINY:
58 begin
59 if AnyFuseLo then
60 begin
61 data[0] := $50;
62 data[1] := $00;
63 data[2] := $00;
64 WriteBytes(@data, 3);
65 fblo:=ReadByte;
66 end;
67 if AnyFuseHi then
68 begin
69 data[0] := $58;
70 data[1] := $08;
71 data[2] := $00;
72 WriteBytes(@data, 3);
73 fbhi:=ReadByte;
74 end;
75 if AnyFuseExt then
76 begin
77 data[0] := $50;
78 data[1] := $08;
79 data[2] := $00;
80 WriteBytes(@data, 3);
81 fbext:=ReadByte;
82 end;
83 end;
84 else
85 Result:=-1; // no ISP command to read fuse bits
86 end;
87end;
88
89procedure ISPWriteFuseLoBits(fuse:byte);
90var data:array[0..3] of byte;
91begin
92 if not AnyFuseLo then
93 Exit;
94 case Signatures[devicenr].algo_lb of
95 ALGO_LB_89S8253, ALGO_LB_89S2051:
96 begin
97 data[0] := $ac;
98 data[1] := $10 or (fuse and $0f);
99 data[2] := $00;
100 data[3] := $00;
101 WriteBytes(@data, 4);
102 Sync;
103 WaitMS(Signatures[devicenr].prog_time);
104 end;
105 ALGO_LB_MEGA, ALGO_LB_TINY:
106 begin
107 data[0] := $ac;
108 data[1] := $a0;
109 data[2] := $00;
110 data[3] := fuse;
111 WriteBytes(@data, 4);
112 Sync;
113 WaitMS(Signatures[devicenr].prog_time);
114 end;
115 ALGO_LB_2323:
116 begin
117 data[0] := $ac;
118 data[1] := $be or (fuse and $01);
119 data[2] := $00;
120 data[3] := $00;
121 WriteBytes(@data, 4);
122 Sync;
123 WaitMS(Signatures[devicenr].prog_time);
124 end;
125 ALGO_LB_2333:
126 begin
127 data[0] := $ac;
128 data[1] := $a0 or (fuse and $1f);
129 data[2] := $00;
130 data[3] := $00;
131 WriteBytes(@data, 4);
132 Sync;
133 WaitMS(Signatures[devicenr].prog_time);
134 end;
135 end;
136end;
137
138procedure ISPWriteFuseHiBits(fuse:byte);
139var data:array[0..3] of byte;
140begin
141 if not AnyFuseHi then
142 Exit;
143 if Signatures[devicenr].algo = ALGO_MEGA then
144 begin
145 data[0] := $ac;
146 data[1] := $a8;
147 data[2] := $00;
148 data[3] := fuse;
149 WriteBytes(@data, 4);
150 Sync;
151 WaitMS(Signatures[devicenr].prog_time);
152 end;
153end;
154
155procedure ISPWriteFuseExtBits(fuse:byte);
156var data:array[0..3] of byte;
157begin
158 if not AnyFuseExt then
159 Exit;
160 if Signatures[devicenr].algo = ALGO_MEGA then
161 begin
162 data[0] := $ac;
163 data[1] := $a4;
164 data[2] := $00;
165 data[3] := fuse;
166 WriteBytes(@data, 4);
167 Sync;
168 WaitMS(Signatures[devicenr].prog_time);
169 end;
170end;
171
172function AnyFuseLo:boolean;
173var i:integer;
174begin
175 Result:=true;
176 for i:=0 to 7 do
177 if Signatures[devicenr].fusebitslo[i] <> '' then
178 Exit;
179 Result:=false;
180end;
181
182function AnyFuseHi:boolean;
183var i:integer;
184begin
185 Result:=true;
186 for i:=0 to 7 do
187 if Signatures[devicenr].fusebitshi[i] <> '' then
188 Exit;
189 Result:=false;
190end;
191
192function AnyFuseExt:boolean;
193var i:integer;
194begin
195 Result:=true;
196 for i:=0 to 7 do
197 if Signatures[devicenr].fusebitsext[i] <> '' then
198 Exit;
199 Result:=false;
200end;
201
202function AnyFuse:boolean;
203var i:integer;
204begin
205 Result:=true;
206 for i:=0 to 7 do
207 if (Signatures[devicenr].fusebitslo[i] <> '') or
208 (Signatures[devicenr].fusebitshi[i] <> '') or
209 (Signatures[devicenr].fusebitsext[i] <> '') then
210 Exit;
211 Result:=false;
212end;
213
214end.
Note: See TracBrowser for help on using the repository browser.