comparison src/ghostwriter.asm @ 219:4b2622e0fd50

init new 4kB Page in logbook memory when pointer is not valid.
author heinrichsweikamp
date Sun, 04 Jan 2015 21:24:01 +0100
parents f515712d8cd6
children d730302fae75
comparison
equal deleted inserted replaced
218:8fbd8c5ac51f 219:4b2622e0fd50
361 movff ext_flash_address+0,ext_flash_log_pointer+0 361 movff ext_flash_address+0,ext_flash_log_pointer+0
362 movff ext_flash_address+1,ext_flash_log_pointer+1 362 movff ext_flash_address+1,ext_flash_log_pointer+1
363 movff ext_flash_address+2,ext_flash_log_pointer+2 ; Save end-of-profile pointer to store in header 363 movff ext_flash_address+2,ext_flash_log_pointer+2 ; Save end-of-profile pointer to store in header
364 364
365 ; Set to first address again to store dive length ext_flash_dive_counter:3 365 ; Set to first address again to store dive length ext_flash_dive_counter:3
366 clrf EEADRH ; Make sure to select eeprom bank 0 366 rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6
367 read_int_eeprom .4
368 movff EEDATA,ext_flash_address+0
369 read_int_eeprom .5
370 movff EEDATA,ext_flash_address+1
371 read_int_eeprom .6
372 movff EEDATA,ext_flash_address+2
373 367
374 incf_ext_flash_address_0x20 d'6' ; Skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header 368 incf_ext_flash_address_0x20 d'6' ; Skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header
375 ; Store dive length 369 ; Store dive length
376 movf ext_flash_dive_counter+0,W 370 movf ext_flash_dive_counter+0,W
377 call write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase) 371 call write_byte_ext_flash_plus_nocnt ; WREG -> Profile in ext. flash (No ext_flash_dive_counter:3 increase)
817 addwf surface_interval+0,F 811 addwf surface_interval+0,F
818 movf divemins+1,W 812 movf divemins+1,W
819 addwfc surface_interval+1 ; Add simulated divetime to surface interval 813 addwfc surface_interval+1 ; Add simulated divetime to surface interval
820 bra ghostwriter_end_dive_common 814 bra ghostwriter_end_dive_common
821 815
822 global ghostwriter_short_header 816 ghostwriter_load_pointer: ; Load ext_flash_address:3 from EEPROM .4-.6
823 ghostwriter_short_header: ; Write short header with divenumber into profile memory
824
825 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive)
826 clrf EEADRH ; Make sure to select eeprom bank 0 817 clrf EEADRH ; Make sure to select eeprom bank 0
827 read_int_eeprom .4 818 read_int_eeprom .4
828 movff EEDATA,ext_flash_address+0 819 movff EEDATA,ext_flash_address+0
829 read_int_eeprom .5 820 read_int_eeprom .5
830 movff EEDATA,ext_flash_address+1 821 movff EEDATA,ext_flash_address+1
831 read_int_eeprom .6 822 read_int_eeprom .6
832 movff EEDATA,ext_flash_address+2 823 movff EEDATA,ext_flash_address+2
824 return
825
826 ghostwriter_short_header_init: ; Proceed one page forward
827 clrf EEDATA
828 write_int_eeprom .4 ; ext_flash_address+0 = 0
829 movlw .16
830 addwf ext_flash_address+1,F
831 movlw .0
832 addwfc ext_flash_address+2,F
833 movlw 0x20
834 cpfseq ext_flash_address+2 ; at address 0x200000?
835 bra ghostwriter_short_header_init2 ; No
836 clrf ext_flash_address+2 ; Yes, rollover to 0x000000
837 ghostwriter_short_header_init2:
838 movlw 0xF0
839 andwf ext_flash_address+1,F ; keep higher nibble, set lower nibble to 0
840
841 movff ext_flash_address+1,EEDATA
842 write_int_eeprom .5 ; Write new pointer
843 movff ext_flash_address+2,EEDATA
844 write_int_eeprom .6 ; Write new pointer
845 bra ghostwriter_short_header2 ; Done.
846
847 global ghostwriter_short_header
848 ghostwriter_short_header: ; Write short header with divenumber into profile memory
849 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive)
850 rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6
851
852 ; The following code is used to write a clean new dive after the previous hasn't been
853 ; stored correctly. e.g. after a battery fail during the dive
854 call ext_flash_byte_read_plus_0x20 ; Into temp1
855 incfsz temp1,F
856 bra ghostwriter_short_header_init ; Not 0xFF -> init page
857 call ext_flash_byte_read_plus_0x20 ; Into temp1
858 incfsz temp1,F
859 bra ghostwriter_short_header_init ; Not 0xFF -> init page
860
861 ghostwriter_short_header2:
862 ; All ok, reload the pointer and start
863 rcall ghostwriter_load_pointer ; Load ext_flash_address:3 from EEPROM .4-.6
833 864
834 ; Clear dive length counter 865 ; Clear dive length counter
835 clrf ext_flash_dive_counter+0 866 clrf ext_flash_dive_counter+0
836 clrf ext_flash_dive_counter+1 867 clrf ext_flash_dive_counter+1
837 clrf ext_flash_dive_counter+2 868 clrf ext_flash_dive_counter+2