diff src/ghostwriter.asm @ 278:dfac47ac2e1d

BUGFIX: There was a 1:4096 chance that a portion of a dive was not stored correctly resulting in download issues
author heinrichsweikamp
date Mon, 18 May 2015 21:25:56 +0200
parents 653a3ab08062
children 62c7af4795b0
line wrap: on
line diff
--- a/src/ghostwriter.asm	Mon May 18 14:24:50 2015 +0200
+++ b/src/ghostwriter.asm	Mon May 18 21:25:56 2015 +0200
@@ -368,11 +368,11 @@
     incf_ext_flash_address_0x20	d'6'        ; Skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header
     ; Store dive length
     movf   ext_flash_dive_counter+0,W
-	call    write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase)
+	call    write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page
     movf   ext_flash_dive_counter+1,W
-	call    write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase)
+	call    write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page
     movf   ext_flash_dive_counter+2,W
-	call    write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase)
+	call    write_byte_ext_flash_plus_nodel ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) and does NOT delete 4kB page
 
 ; profile recording done.
 
@@ -883,8 +883,19 @@
 	rcall	ghostwrite_byte_profile 	; WREG -> Profile in ext. flash
 	movlw	0xFA
 	rcall	ghostwrite_byte_profile 	; WREG -> Profile in ext. flash
+
     ; Keep room for dive length ext_flash_dive_counter:3 (Stored at the end of the dive)
-    incf_ext_flash_address_0x20	d'3'        ; Skip Bytes in external flash (faster)
+    ; Writing 0xFF three times here is mandatory
+    ; - 0xFF can be overwritten after the dive
+    ; - ghostwrite_byte_profile takes care of 4kB Page switching
+    ; - fixes an issue when we are at exactly 0xXXX000 here...
+
+    movlw   0xFF
+    rcall	ghostwrite_byte_profile 	; WREG -> Profile in ext. flash
+    movlw   0xFF
+    rcall	ghostwrite_byte_profile 	; WREG -> Profile in ext. flash
+    movlw   0xFF
+    rcall	ghostwrite_byte_profile 	; WREG -> Profile in ext. flash
 
 	movf	samplingrate,W  			; Sampling rate
 	btfsc	FLAG_apnoe_mode				; Apnoe mode?