Mercurial > public > hwos_code
annotate src/external_flash.asm @ 420:789230298511
fix handling for new flash memory chip
author | heinrichsweikamp |
---|---|
date | Fri, 29 Apr 2016 15:38:57 +0200 |
parents | 4389fe9673b2 |
children | 3895adc3477f |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File external_flash.asm | |
4 ; | |
5 ; External flash | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-12 : [mH] creation | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "wait.inc" |
14 | |
15 basic CODE | |
16 ;============================================================================= | |
17 | |
18 global incf_ext_flash_address_p1 | |
19 incf_ext_flash_address_p1: ; Increase by one | |
20 movlw .1 | |
21 | |
22 global incf_ext_flash_address0 | |
23 incf_ext_flash_address0: | |
24 addwf ext_flash_address+0,F ; increase address | |
25 movlw d'0' | |
26 addwfc ext_flash_address+1,F | |
27 addwfc ext_flash_address+2,F | |
28 | |
29 movlw 0x40 | |
30 cpfseq ext_flash_address+2 ; at address 40FFFF? | |
31 return ; No, return | |
167 | 32 ; clrf ext_flash_address+0 |
33 ; clrf ext_flash_address+1 | |
34 clrf ext_flash_address+2 ; Yes, rollover to 0x000000 | |
0 | 35 return |
36 | |
37 global incf_ext_flash_address0_p1_0x20 | |
38 incf_ext_flash_address0_p1_0x20: ; Increase by one | |
39 movlw .1 | |
40 | |
41 global incf_ext_flash_address0_0x20 | |
42 incf_ext_flash_address0_0x20: ; with roll-over at 0x200000 to 0x000000 | |
43 addwf ext_flash_address+0,F ; increase address | |
44 movlw d'0' | |
45 addwfc ext_flash_address+1,F | |
46 addwfc ext_flash_address+2,F | |
47 | |
48 movlw 0x20 | |
49 cpfseq ext_flash_address+2 ; at address 0x200000? | |
50 return ; No, return | |
167 | 51 ; clrf ext_flash_address+0 |
52 ; clrf ext_flash_address+1 | |
53 clrf ext_flash_address+2 ; Yes, rollover to 0x000000 | |
0 | 54 return |
55 | |
56 global decf_ext_flash_address0 | |
57 decf_ext_flash_address0: | |
58 subwf ext_flash_address+0,F ; decrease address: do a 16-8bits substract. | |
59 movlw d'0' | |
60 subwfb ext_flash_address+1,F | |
61 movlw d'0' | |
62 subwfb ext_flash_address+2,F | |
63 | |
64 btfss ext_flash_address+2,7 ; Rollover to 0xFFFFFF? | |
65 return ; No, return | |
66 clrf ext_flash_address+2 ; Set to 0x00FFFFF | |
67 setf ext_flash_address+1 | |
68 setf ext_flash_address+0 | |
69 return | |
70 | |
71 global ext_flash_byte_read_plus ; Return data read in WREG and SSP2BUF and | |
72 ext_flash_byte_read_plus: ; increase address after read | |
73 rcall ext_flash_byte_read | |
74 movwf temp1 ; store received data | |
75 bra incf_ext_flash_address_p1 ; +1 and return | |
76 | |
77 global ext_flash_byte_read_plus_0x20; Return data read in WREG and SSP2BUF and | |
78 ext_flash_byte_read_plus_0x20: ; increase address after read with banking at 0x200000 | |
79 rcall ext_flash_byte_read | |
80 movwf temp1 ; store received data | |
81 bra incf_ext_flash_address0_p1_0x20 ;+1 and return | |
82 | |
83 | |
84 global ext_flash_byte_read ; Return data read in WREG | |
85 ext_flash_byte_read: | |
86 movlw 0x03 ; Read command | |
87 rcall write_spi | |
88 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | |
89 rcall write_spi ; Dummy write to read data into WREG | |
90 bsf flash_ncs ; CS=1 | |
91 movwf temp1 | |
92 return ; Return data read in WREG and temp1 | |
93 | |
94 ext_flash_write_address: ; Write 24bit address ext_flash_address:3 via SPI | |
95 movf ext_flash_address+2,W ; 24Bit Address | |
96 rcall write_spi | |
97 movf ext_flash_address+1,W | |
98 rcall write_spi | |
99 movf ext_flash_address+0,W | |
100 bra write_spi ; And return.... | |
101 | |
102 global ext_flash_read_block_start ; Return data read in WREG | |
103 ext_flash_read_block_start: | |
104 movlw 0x03 ; Read command | |
105 rcall write_spi | |
106 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | |
107 rcall write_spi ; Dummy write to read data into WREG | |
108 return ; Return data read in WREG | |
109 | |
110 global ext_flash_read_block ; Return data read in WREG | |
111 ext_flash_read_block: | |
112 rcall incf_ext_flash_address_p1 ; Increase address +1 | |
113 bra write_spi1 ; Dummy write to read data into WREG and return | |
114 | |
115 global ext_flash_read_block_stop ; Return data read in WREG | |
116 ext_flash_read_block_stop: | |
117 bsf flash_ncs ; CS=1 | |
118 return ; NO data in WREG | |
119 | |
120 global write_byte_ext_flash_plus_header | |
121 write_byte_ext_flash_plus_header: ; Write from WREG and increase address after write | |
122 movwf temp1 ; store data | |
123 ; test if write is done at first byte of 4kB block | |
124 ; if yes -> delete 4kB block first | |
125 tstfsz ext_flash_address+0 ; at 0x00? | |
126 bra write_byte_ext_flash_plus_h1 ; No, normal Write | |
127 | |
128 movf ext_flash_address+1,W | |
129 andlw 0x0F ; Mask lower nibble | |
130 tstfsz WREG ; at 0x.0? | |
131 bra write_byte_ext_flash_plus_h1; No, normal Write | |
132 | |
133 ; At beginning of 4kB block -> rease first! | |
134 rcall ext_flash_erase4kB ; Erases 4kB sector @ext_flash_address:3 | |
135 write_byte_ext_flash_plus_h1: | |
136 movf temp1,W | |
137 rcall ext_flash_byte_write ; Write the byte | |
138 bra incf_ext_flash_address_p1 ; +1 and return | |
139 | |
279 | 140 global write_byte_ext_flash_plus_nocnt ; No increase of ext_flash_dive_counter:3 |
141 write_byte_ext_flash_plus_nocnt: | |
142 movwf temp1 ; store data | |
143 bra write_byte_ext_flash_plus2 | |
144 | |
278
dfac47ac2e1d
BUGFIX: There was a 1:4096 chance that a portion of a dive was not stored correctly resulting in download issues
heinrichsweikamp
parents:
275
diff
changeset
|
145 global write_byte_ext_flash_plus_nodel ; Does NOT delete 4kB Page when required |
279 | 146 write_byte_ext_flash_plus_nodel: ; Write from WREG and increase address after write with banking at 0x200000 |
147 movwf temp1 ; store data | |
278
dfac47ac2e1d
BUGFIX: There was a 1:4096 chance that a portion of a dive was not stored correctly resulting in download issues
heinrichsweikamp
parents:
275
diff
changeset
|
148 bra write_byte_ext_flash_plus1 ; Ignore possible begin of 4kB page, there have been written 0xFF already |
6 | 149 |
0 | 150 global write_byte_ext_flash_plus ; Write from WREG and increase address after write with banking at 0x200000 |
151 write_byte_ext_flash_plus: | |
152 movwf temp1 ; store data | |
153 | |
154 ; First, increase dive length counter | |
155 incf ext_flash_dive_counter+0,F | |
156 movlw .0 | |
157 addwfc ext_flash_dive_counter+1,F | |
158 addwfc ext_flash_dive_counter+2,F ; 24bit++ | |
159 | |
6 | 160 write_byte_ext_flash_plus2: |
0 | 161 ; Now test if write is done at first byte of 4kB block |
162 ; if yes -> delete 4kB block first | |
163 tstfsz ext_flash_address+0 ; at 0x00? | |
164 bra write_byte_ext_flash_plus1 ; No, normal Write | |
165 | |
166 movf ext_flash_address+1,W | |
167 andlw 0x0F ; Mask lower nibble | |
168 tstfsz WREG ; at 0x.0? | |
169 bra write_byte_ext_flash_plus1 ; No, normal Write | |
170 | |
171 ; At beginning of 4kB block -> erase first! | |
172 rcall ext_flash_erase4kB ; Erases 4kB sector @ext_flash_address:3 | |
173 write_byte_ext_flash_plus1: | |
174 movf temp1,W | |
175 rcall ext_flash_byte_write ; Write the byte | |
176 bra incf_ext_flash_address0_p1_0x20 ; +1 and roll over at 0x200000 to 0x000000 and return | |
177 | |
178 global ext_flash_byte_write ; Write from WREG | |
179 ext_flash_byte_write: | |
180 movwf temp1 ; store data byte | |
181 bsf flash_ncs ; CS=1 | |
182 movlw 0x06 ; WREN command | |
183 rcall write_spi | |
184 bsf flash_ncs ; CS=1 | |
185 movlw 0x02 ; Write command | |
186 rcall write_spi | |
420 | 187 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI |
0 | 188 movf temp1,W ; load data byte |
189 rcall write_spi ; write one byte of data! | |
190 bsf flash_ncs ; CS=1 | |
191 return | |
192 | |
193 global ext_flash_disable_protection ; Disable write protection | |
194 ext_flash_disable_protection: | |
414 | 195 ; unlock old memory |
0 | 196 bsf flash_ncs ; CS=1 |
197 movlw 0x50 ; EWSR command | |
198 rcall write_spi | |
199 bsf flash_ncs ; CS=1 | |
200 | |
201 movlw 0x01 ; WRSR command | |
202 rcall write_spi | |
203 movlw b'00000000' ; New status | |
204 rcall write_spi | |
205 bsf flash_ncs ; CS=1 | |
414 | 206 |
207 ; unlock new memory | |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
414
diff
changeset
|
208 ; bsf flash_ncs ; CS=1 |
420 | 209 ; movlw 0x06 ; WREN command |
210 ; rcall write_spi | |
211 ; bsf flash_ncs ; CS=1 | |
212 ; movlw 0x98 ; ULBPR command | |
213 ; rcall write_spi | |
214 ; bsf flash_ncs ; CS=1 | |
215 | |
216 ;bsf flash_ncs ; CS=1 | |
414 | 217 movlw 0x06 ; WREN command |
218 rcall write_spi | |
219 bsf flash_ncs ; CS=1 | |
420 | 220 movlw 0x42 ; WBPR command |
414 | 221 rcall write_spi |
420 | 222 movlw .18 |
223 movwf temp1 | |
224 ext_flash_disable_protection2: | |
225 movlw 0x00 | |
226 rcall write_spi | |
227 decfsz temp1,F ; 18 bytes with 0x00 | |
228 bra ext_flash_disable_protection2 | |
229 bsf flash_ncs ; CS=1 | |
0 | 230 return |
231 | |
232 global ext_flash_enable_protection | |
233 ext_flash_enable_protection: | |
414 | 234 ; lock old memory |
0 | 235 bsf flash_ncs ; CS=1 |
236 movlw 0x50 ; EWSR command | |
237 rcall write_spi | |
238 bsf flash_ncs ; CS=1 | |
239 | |
240 movlw 0x01 ; WRSR command | |
241 rcall write_spi | |
242 movlw b'00011100' ; New status (Write protect on) | |
243 rcall write_spi | |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
414
diff
changeset
|
244 ; bsf flash_ncs ; CS=1 |
414 | 245 |
246 ; lock new memory | |
247 bsf flash_ncs ; CS=1 | |
248 movlw 0x06 ; WREN command | |
249 rcall write_spi | |
250 bsf flash_ncs ; CS=1 | |
251 movlw 0x42 ; WBPR command | |
252 rcall write_spi | |
253 movlw .18 | |
254 movwf temp1 | |
255 ext_flash_enable_protection2: | |
256 movlw 0xFF | |
257 rcall write_spi | |
258 decfsz temp1,F ; 18 bytes with 0xFF | |
259 bra ext_flash_enable_protection2 | |
260 bsf flash_ncs ; CS=1 | |
0 | 261 return |
262 | |
263 | |
264 global ext_flash_erase4kB ; Erases 4kB sector | |
265 ext_flash_erase4kB: | |
266 bsf flash_ncs ; CS=1 | |
267 movlw 0x06 ; WREN command | |
268 rcall write_spi | |
269 bsf flash_ncs ; CS=1 | |
270 movlw 0x20 ; Sector erase command | |
271 rcall write_spi | |
272 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI | |
273 bsf flash_ncs ; CS=1 | |
274 ; bra ext_flash_wait_write ; Wait for write... and return | |
275 ext_flash_wait_write: | |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
414
diff
changeset
|
276 WAITMS d'5' ; TBE/TSE=25ms... |
0 | 277 movlw 0x05 ; RDSR command |
278 rcall write_spi ; Read status | |
279 rcall write_spi ; Read status into WREG | |
280 bsf flash_ncs ; CS=1 | |
281 btfsc SSP2BUF,0 ; Write operation in process? | |
282 bra ext_flash_wait_write ; Yes, wait more.. | |
283 return | |
284 | |
414 | 285 global ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte -> 3145728 Bytes) |
0 | 286 ext_flash_erase_logbook: |
287 bsf flash_ncs ; CS=1 | |
288 clrf ext_flash_address+0 | |
289 clrf ext_flash_address+1 | |
290 clrf ext_flash_address+2 | |
291 | |
414 | 292 setf temp1 ; 256*12kB=3145728 Bytes |
0 | 293 ext_flash_erase_logbook_loop: |
414 | 294 rcall ext_flash_erase4kB ; 4kB |
295 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB | |
296 rcall ext_flash_erase4kB ; 4kB | |
297 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB | |
298 rcall ext_flash_erase4kB ; 4kB | |
299 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB | |
0 | 300 decfsz temp1,F |
301 bra ext_flash_erase_logbook_loop | |
302 return | |
303 | |
414 | 304 ext_flash_add_4kB: |
305 movlw 0x10 | |
306 addwf ext_flash_address+1,F | |
307 movlw d'0' | |
308 addwfc ext_flash_address+2,F | |
309 return | |
310 | |
0 | 311 |
312 write_spi: ; With data in WREG... | |
313 bcf flash_ncs ; CS | |
314 global write_spi1 | |
315 write_spi1: ; With data in WREG... | |
316 bcf SSP2STAT,WCOL ; Clear flag | |
317 movwf SSP2BUF ; Write to buffer | |
318 btfsc SSP2STAT,WCOL ; Was buffer full? | |
319 bra write_spi1 ; Yes, try again | |
320 | |
321 write_spi2: ; Wait for write command | |
322 btfss SSP2STAT, BF ; Buffer full? | |
323 bra write_spi2 ; No, wait. | |
324 movf SSP2BUF,W | |
325 return ; Returns RX data in WREG and SSP2BUF | |
326 | |
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
327 global fix_180_dives |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
328 fix_180_dives: ; fix dives made with the 1.80 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
329 clrf divesecs ; Here: # of dive (0-255) in TOC |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
330 fix_180_dives2: |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
331 rcall fix_load_dive_into_buffer ; Load header #divesecs into buffer:256 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
332 rcall fix_check_buffer ; Check the buffered dive |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
333 tstfsz WREG ; Dive needs fix? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
334 rcall fix_buffered_dive ; Yes, fix and save it |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
335 decfsz divesecs,F ; All done? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
336 bra fix_180_dives2 ; No, continue |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
337 return ; All done. |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
338 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
339 fix_buffered_dive: ; Yes, fix and save it |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
340 rcall ext_flash_disable_protection ; Disable write protection for external flash |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
341 banksel buffer |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
342 ; Set to 1.81 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
343 movlw .81 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
344 movwf buffer+.49 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
345 ; Fix wrong profile length |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
346 movlw .3 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
347 subwf buffer+.9,F |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
348 movlw d'0' |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
349 subwfb buffer+.10,F |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
350 subwfb buffer+.11,F |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
351 banksel common |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
352 ; save result into external flash again |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
353 rcall fix_set_to_toc_start |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
354 clrf lo |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
355 lfsr FSR0,buffer+0 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
356 fix_buffered_dive2: |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
357 movf POSTINC0,W |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
358 rcall write_byte_ext_flash_plus_header; Write from WREG and increase address after write |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
359 decfsz lo,F ; All done? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
360 bra fix_buffered_dive2 ; No, continue |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
361 return |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
362 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
363 fix_check_buffer: ; Check the buffered dive |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
364 movff buffer+.48,temp1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
365 movlw .1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
366 cpfseq temp1 ; buffer+.48 = .1 ? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
367 retlw .0 ; No, abort |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
368 movff buffer+.49,temp1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
369 movlw .80 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
370 cpfseq temp1 ; buffer+.49 = .80 ? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
371 retlw .0 ; No, abort |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
372 retlw .1 ; Yes, fix this dive |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
373 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
374 fix_load_dive_into_buffer: ; Load header #divesecs into buffer:256 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
375 rcall fix_set_to_toc_start |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
376 clrf lo |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
377 lfsr FSR0,buffer+0 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
378 fix_load_dive_into_buffer2: |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
379 rcall ext_flash_byte_read_plus ; increase address after read |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
380 movff temp1,POSTINC0 ; copy into buffer |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
381 decfsz lo,F ; All done? |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
382 bra fix_load_dive_into_buffer2 ; No, continue |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
383 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
384 fix_set_to_toc_start: |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
385 clrf ext_flash_address+0 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
386 clrf ext_flash_address+1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
387 movlw 0x20 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
388 movwf ext_flash_address+2 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
389 movlw .16 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
390 mulwf divesecs; divesecs*16 = offset to 0x2000 (up:hi) |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
391 movf PRODL,W |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
392 addwf ext_flash_address+1,F |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
393 movf PRODH,W |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
394 addwfc ext_flash_address+2,F |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
395 ; pointer at the first 0xFA of header |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
396 return |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
397 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
279
diff
changeset
|
398 |
0 | 399 END |