comparison src/external_flash.asm @ 281:eb758a5b44eb

BUGFIX: Fix download issue for dives made with 1.80 firmware
author heinrichsweikamp
date Tue, 26 May 2015 17:40:13 +0200
parents 62c7af4795b0
children 35bdfd89323c
comparison
equal deleted inserted replaced
280:c39aff8576f4 281:eb758a5b44eb
285 btfss SSP2STAT, BF ; Buffer full? 285 btfss SSP2STAT, BF ; Buffer full?
286 bra write_spi2 ; No, wait. 286 bra write_spi2 ; No, wait.
287 movf SSP2BUF,W 287 movf SSP2BUF,W
288 return ; Returns RX data in WREG and SSP2BUF 288 return ; Returns RX data in WREG and SSP2BUF
289 289
290 global fix_180_dives
291 fix_180_dives: ; fix dives made with the 1.80
292 clrf divesecs ; Here: # of dive (0-255) in TOC
293 fix_180_dives2:
294 rcall fix_load_dive_into_buffer ; Load header #divesecs into buffer:256
295 rcall fix_check_buffer ; Check the buffered dive
296 tstfsz WREG ; Dive needs fix?
297 rcall fix_buffered_dive ; Yes, fix and save it
298 decfsz divesecs,F ; All done?
299 bra fix_180_dives2 ; No, continue
300 return ; All done.
301
302 fix_buffered_dive: ; Yes, fix and save it
303 rcall ext_flash_disable_protection ; Disable write protection for external flash
304 banksel buffer
305 ; Set to 1.81
306 movlw .81
307 movwf buffer+.49
308 ; Fix wrong profile length
309 movlw .3
310 subwf buffer+.9,F
311 movlw d'0'
312 subwfb buffer+.10,F
313 subwfb buffer+.11,F
314 banksel common
315 ; save result into external flash again
316 rcall fix_set_to_toc_start
317 clrf lo
318 lfsr FSR0,buffer+0
319 fix_buffered_dive2:
320 movf POSTINC0,W
321 rcall write_byte_ext_flash_plus_header; Write from WREG and increase address after write
322 decfsz lo,F ; All done?
323 bra fix_buffered_dive2 ; No, continue
324 return
325
326 fix_check_buffer: ; Check the buffered dive
327 movff buffer+.48,temp1
328 movlw .1
329 cpfseq temp1 ; buffer+.48 = .1 ?
330 retlw .0 ; No, abort
331 movff buffer+.49,temp1
332 movlw .80
333 cpfseq temp1 ; buffer+.49 = .80 ?
334 retlw .0 ; No, abort
335 retlw .1 ; Yes, fix this dive
336
337 fix_load_dive_into_buffer: ; Load header #divesecs into buffer:256
338 rcall fix_set_to_toc_start
339 clrf lo
340 lfsr FSR0,buffer+0
341 fix_load_dive_into_buffer2:
342 rcall ext_flash_byte_read_plus ; increase address after read
343 movff temp1,POSTINC0 ; copy into buffer
344 decfsz lo,F ; All done?
345 bra fix_load_dive_into_buffer2 ; No, continue
346
347 fix_set_to_toc_start:
348 clrf ext_flash_address+0
349 clrf ext_flash_address+1
350 movlw 0x20
351 movwf ext_flash_address+2
352 movlw .16
353 mulwf divesecs; divesecs*16 = offset to 0x2000 (up:hi)
354 movf PRODL,W
355 addwf ext_flash_address+1,F
356 movf PRODH,W
357 addwfc ext_flash_address+2,F
358 ; pointer at the first 0xFA of header
359 return
360
361
290 END 362 END