diff src/start.asm @ 410:d3087a8ed7e1

BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
author heinrichsweikamp
date Tue, 08 Mar 2016 11:42:58 +0100
parents a9e35c1327aa
children 4389fe9673b2
line wrap: on
line diff
--- a/src/start.asm	Wed Feb 24 09:57:08 2016 +0100
+++ b/src/start.asm	Tue Mar 08 11:42:58 2016 +0100
@@ -213,6 +213,8 @@
 
     call    fix_180_dives           ; fix dives made with the 1.80
 
+    rcall   backup_flash_page       ; backup the first 128bytes from flash to EEPROM
+
 	movlw	d'1'					; store current version in EEPROM
 	movwf	EEADR                   ; =1
 	movwf	EEADRH                  ; =1
@@ -384,4 +386,28 @@
 	bsf		FLAG_apnoe_mode
     return							    ; start in Surfacemode
 
+backup_flash_page:       ; backup the first 128bytes from flash to EEPROM
+    	; Start address in internal flash
+    	movlw   0x00
+        movwf   TBLPTRL
+        movwf   TBLPTRH
+        movwf   TBLPTRU
+
+        movlw	.128
+        movwf	lo              ; Byte counter
+        clrf    EEADR
+        movlw   .3
+        movwf   EEADRH          ; Setup backup address
+
+        TBLRD*-					; Dummy read to be in 128 byte block
+backup_flash_loop:
+        tblrd+*					; Table Read with Pre-Increment
+        movff	TABLAT,EEDATA	; put 1 byte
+        call    write_eeprom    ; save it in EEPROM
+        incf    EEADR,F
+        decfsz 	lo,F            ; 128byte done?
+        bra 	backup_flash_loop ; No
+        clrf    EEADRH          ; Reset EEADRH
+        return                  ; Done.
+
 	END
\ No newline at end of file