Mercurial > public > hwos_code
annotate src/ghostwriter.asm @ 604:ca4556fb60b9
bump to 2.99beta, work on 3.00 stable
author | heinrichsweikamp |
---|---|
date | Thu, 22 Nov 2018 19:47:26 +0100 |
parents | 08a0162d3ca1 |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File ghostwriter.asm REFACTORED VERSION V2.99a |
0 | 4 ; |
5 ; Ghostwriter (Log profile recorder) | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-11-27 : [mH] Creation | |
11 | |
582 | 12 #include "hwos.inc" ; Mandatory header |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
14 #include "external_flash.inc" | |
15 #include "surfmode.inc" | |
16 #include "eeprom_rs232.inc" | |
17 #include "strings.inc" | |
18 #include "isr.inc" | |
19 #include "tft_outputs.inc" | |
20 #include "divemode.inc" | |
21 #include "rtc.inc" | |
22 | |
604 | 23 extern deco_pull_tissues_from_vault |
24 | |
582 | 25 |
26 ;---- Private local variables ------------------------------------------------- | |
27 | |
604 | 28 CBLOCK local3 ; max size is 16 Byte !!! |
582 | 29 divisor_temperature ; divisor used to time the sampling of dive data |
30 divisor_deco ; divisor used to time the sampling of dive data | |
31 divisor_gf ; divisor used to time the sampling of dive data | |
32 divisor_ppo2_sensors ; divisor used to time the sampling of dive data | |
33 divisor_decoplan ; divisor used to time the sampling of dive data | |
34 divisor_cns ; divisor used to time the sampling of dive data | |
35 divisor_tank ; divisor used to time the sampling of dive data | |
36 ProfileFlagByte ; used to store events | |
37 ENDC ; used: 8 byte, remaining: 8 byte | |
38 | |
39 | |
40 ghostwriter CODE | |
41 | |
42 ;============================================================================= | |
43 | |
0 | 44 |
604 | 45 global init_recording_params ; initialize profile recording parameters |
582 | 46 init_recording_params: |
47 movff samplingrate,samplesecs_value; to avoid EEPROM access in the ISR | |
48 movlw div_temperature | |
49 movwf divisor_temperature ; load divisors for profile storage | |
50 movlw div_deco | |
51 movwf divisor_deco | |
52 movlw div_gf | |
53 movwf divisor_gf | |
54 movlw div_ppo2_sensors | |
55 movwf divisor_ppo2_sensors | |
56 movlw div_decoplan | |
57 movwf divisor_decoplan | |
58 movlw div_cns | |
59 movwf divisor_cns | |
60 movlw div_tank | |
61 movwf divisor_tank | |
604 | 62 btfss FLAG_apnoe_mode ; in Apnoe mode? |
582 | 63 bra init_recording_params_1 ; NO |
64 movlw samplingrate_apnoe ; YES - overwrite some parameters in Apnoe mode | |
65 movwf samplesecs_value ; to avoid EEPROM access in the ISR | |
66 init_recording_params_1: | |
67 btfsc FLAG_ccr_mode ; in CCR mode? | |
68 bra init_recording_params_2 ; YES | |
69 btfsc FLAG_pscr_mode ; in pSCR mode? | |
70 bra init_recording_params_2 ; YES | |
604 | 71 ; in all modes but CCR and pSCR, disable ppO2 logging |
582 | 72 movlw .0 |
73 movwf divisor_ppo2_sensors | |
74 init_recording_params_2: | |
75 return | |
76 | |
0 | 77 |
78 global store_dive_data | |
560 | 79 store_dive_data: |
582 | 80 bcf store_sample ; clear flag |
0 | 81 |
582 | 82 ifndef __DEBUG |
604 | 83 btfsc simulatormode_active ; are we in simulator mode? |
84 return ; YES - discard everything | |
582 | 85 endif |
0 | 86 |
604 | 87 btfsc FLAG_apnoe_mode ; in Apnoe mode? |
88 return ; YES - discard everything | |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
89 |
582 | 90 SAFE_2BYTE_COPY rel_pressure, lo |
91 movf lo,W ; store depth with every sample | |
604 | 92 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 93 movf hi,W |
604 | 94 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 95 |
604 | 96 ; First, find out how many bytes will be appended to this sample set |
582 | 97 clrf ProfileFlagByte ; clear number of bytes to append |
0 | 98 |
582 | 99 ; Check Extended informations |
604 | 100 decfsz divisor_temperature,W ; check divisor |
582 | 101 bra check_extended1 |
0 | 102 movlw infolength_temperature |
582 | 103 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 104 check_extended1: |
604 | 105 decfsz divisor_deco,W ; check divisor |
582 | 106 bra check_extended2 |
0 | 107 movlw infolength_deco |
582 | 108 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 109 check_extended2: |
604 | 110 decfsz divisor_gf,W ; check divisor |
582 | 111 bra check_extended3 |
0 | 112 movlw infolength_gf |
582 | 113 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 114 check_extended3: |
604 | 115 decfsz divisor_ppo2_sensors,W ; check divisor |
582 | 116 bra check_extended4 |
0 | 117 movlw infolength_ppo2_sensors |
582 | 118 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 119 check_extended4: |
604 | 120 decfsz divisor_decoplan,W ; check divisor |
582 | 121 bra check_extended5 |
0 | 122 movlw infolength_decoplan |
582 | 123 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 124 check_extended5: |
604 | 125 decfsz divisor_cns,W ; check divisor |
582 | 126 bra check_extended6 |
0 | 127 movlw infolength_cns |
582 | 128 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 129 check_extended6: |
604 | 130 decfsz divisor_tank,W ; check divisor |
0 | 131 bra check_extended7 |
132 movlw infolength_tank | |
582 | 133 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 134 check_extended7: |
135 | |
136 ; Second, check global event flag | |
604 | 137 btfss event_occured ; check global event flag |
138 bra store_dive_data3 ; no event | |
99
87cc1adfe4da
show event "bailout" in the internal logbook
heinrichsweikamp
parents:
98
diff
changeset
|
139 |
604 | 140 incf ProfileFlagByte,F ; add one byte (the EventByte1) |
0 | 141 |
582 | 142 clrf EventByte1 ; reset EventByte1 |
143 clrf EventByte2 ; reset EventByte2 | |
0 | 144 |
604 | 145 movf AlarmType,W ; type of Alarm Bit 0-3 |
146 addwf EventByte1,F ; copy to EventByte1 Bit 0-3 | |
147 clrf AlarmType ; reset AlarmType | |
582 | 148 |
560 | 149 ; Third, check events and add additional bytes |
604 | 150 btfss gas6_changed ; check flag |
0 | 151 bra check_event2 |
604 | 152 movlw d'2' ; information length |
582 | 153 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
604 | 154 bsf EventByte1,4 ; also set Flag in EventByte1! |
0 | 155 check_event2: |
604 | 156 btfss stored_gas_changed ; check flag |
0 | 157 bra check_event3 |
604 | 158 movlw d'1' ; information length |
582 | 159 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
604 | 160 bsf EventByte1,5 ; also set Flag in EventByte1! |
0 | 161 check_event3: |
604 | 162 btfss setpoint_changed ; check flag |
0 | 163 bra check_event4 |
604 | 164 movlw d'1' ; information length |
582 | 165 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
604 | 166 bsf EventByte1,6 ; also set Flag in EventByte1! |
0 | 167 check_event4: |
582 | 168 btfss bailoutgas_event ; =1: bailout was selected or a gas change during bailout |
169 bra check_event5 | |
604 | 170 movlw d'2' ; information length |
582 | 171 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
172 bsf EventByte2,0 ; set flag in EventByte2! | |
604 | 173 bsf EventByte1,7 ; =1: another EventByte1 is available |
98 | 174 |
175 check_event5: | |
0 | 176 ; more events? |
177 | |
178 store_dive_data3: | |
582 | 179 btfsc EventByte1,7 ; =1: Another EventByte1 is available |
180 incf ProfileFlagByte,F ; add one byte (The EventByte2) | |
98 | 181 |
604 | 182 btfsc event_occured ; check global event flag |
183 bsf ProfileFlagByte,7 ; set EventByte1 flag in ProfileFlagByte | |
98 | 184 |
604 | 185 movf ProfileFlagByte,W ; finally, write ProfileFlagByte |
186 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
98 | 187 |
604 | 188 btfss event_occured ; check global event flag (again) |
189 bra store_dive_data4 ; no event | |
98 | 190 |
191 ; Store the EventByte(s) + additional bytes now | |
582 | 192 movf EventByte1,W |
604 | 193 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 194 |
604 | 195 movf EventByte2,W ; write second event byte... |
196 btfsc EventByte1,7 ; =1: another EventByte1 is available | |
197 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 198 |
604 | 199 btfss gas6_changed ; check flag |
0 | 200 bra store_dive_data3b |
582 | 201 movff char_I_O2_ratio,WREG ; store gas 6 o2 ratio |
604 | 202 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
582 | 203 movff char_I_He_ratio,WREG ; store gas 6 He ratio |
604 | 204 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
205 bcf gas6_changed ; clear this event | |
0 | 206 store_dive_data3b: |
604 | 207 btfss stored_gas_changed ; check flag |
0 | 208 bra store_dive_data3c |
604 | 209 movf active_dil,W ; store active diluent (default, may be overwritten soon) |
210 btfsc FLAG_oc_mode ; in OC mode? | |
211 movf active_gas,W ; YES - store active gas | |
212 btfsc FLAG_bailout_mode ; in bailout? | |
213 movf active_gas,W ; YES - store active OC = bailout gas | |
214 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
215 bcf stored_gas_changed ; clear this event | |
0 | 216 store_dive_data3c: |
604 | 217 btfss setpoint_changed ; check flag |
0 | 218 bra store_dive_data3d |
582 | 219 movff char_I_const_ppO2,WREG ; store setpoint |
604 | 220 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
221 bcf setpoint_changed ; clear this event | |
0 | 222 store_dive_data3d: |
604 | 223 btfss bailoutgas_event ; check flag |
582 | 224 bra store_dive_data4 |
225 movff char_I_O2_ratio,WREG ; store O2 ratio of bailout gas | |
604 | 226 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
582 | 227 movff char_I_He_ratio,WREG ; store He ratio of bailout gas |
604 | 228 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
229 bcf bailoutgas_event ; clear this event | |
0 | 230 |
231 store_dive_data4: | |
604 | 232 ; Store extended information |
233 decfsz divisor_temperature,F ; check divisor | |
0 | 234 bra store_extended1 |
235 rcall store_dive_temperature | |
236 store_extended1: | |
604 | 237 decfsz divisor_deco,F ; check divisor |
0 | 238 bra store_extended2 |
239 rcall store_dive_decodata | |
240 store_extended2: | |
604 | 241 decfsz divisor_gf,F ; check divisor |
582 | 242 bra store_extended3 |
0 | 243 rcall store_dive_gf |
244 store_extended3: | |
604 | 245 decfsz divisor_ppo2_sensors,F ; check divisor |
582 | 246 bra store_extended4 |
0 | 247 rcall store_dive_ppO2_sensors |
248 store_extended4: | |
604 | 249 decfsz divisor_decoplan,F ; check divisor |
582 | 250 bra store_extended5 |
0 | 251 rcall store_dive_decoplan |
252 store_extended5: | |
604 | 253 decfsz divisor_cns,F ; check divisor |
582 | 254 bra store_extended6 |
0 | 255 rcall store_dive_cns |
256 store_extended6: | |
604 | 257 decfsz divisor_tank,F ; check divisor |
0 | 258 bra store_extended7 |
259 rcall store_dive_tank | |
260 store_extended7: | |
261 | |
262 ; The next block is required to take care of "store never" | |
604 | 263 btfsc divisor_temperature,7 ; test highest bit (register must have been zero before the "decfsz" command!) |
264 clrf divisor_temperature ; and clear register again, so it will never reach zero... | |
0 | 265 btfsc divisor_deco,7 |
266 clrf divisor_deco | |
267 btfsc divisor_gf,7 | |
268 clrf divisor_gf | |
269 btfsc divisor_ppo2_sensors,7 | |
270 clrf divisor_ppo2_sensors | |
271 btfsc divisor_decoplan,7 | |
272 clrf divisor_decoplan | |
273 btfsc divisor_cns,7 | |
274 clrf divisor_cns | |
275 btfsc divisor_tank,7 | |
276 clrf divisor_tank | |
277 | |
278 store_dive_data5: | |
604 | 279 bcf event_occured ; clear the global event flag |
582 | 280 clrf EventByte1 ; reset EventByte1 |
281 clrf EventByte2 ; reset EventByte2 | |
604 | 282 return ; done (sample with all informations written to external flash) |
582 | 283 |
0 | 284 store_dive_cns: |
285 movff int_O_CNS_fraction+0,WREG | |
604 | 286 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 287 movff int_O_CNS_fraction+1,WREG |
604 | 288 bcf WREG,int_warning_flag ; clear warning flag |
289 bcf WREG,int_attention_flag ; clear attention flag | |
290 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 291 movlw div_cns |
604 | 292 movwf divisor_cns ; reload divisor from CF |
0 | 293 return |
294 | |
295 store_dive_tank: | |
604 | 296 ; OSTC TR tank pressure logging |
0 | 297 movlw div_tank |
604 | 298 movwf divisor_tank ; reload divisor from CF |
0 | 299 return |
300 | |
301 store_dive_decoplan: | |
582 | 302 ; Store the deco plan |
303 lfsr FSR1,char_O_deco_time_for_log+.0 | |
304 movlw .15 | |
305 movwf lo | |
0 | 306 store_dive_decoplan_loop: |
582 | 307 movf POSTINC1,W |
604 | 308 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
582 | 309 decfsz lo,F |
310 bra store_dive_decoplan_loop | |
0 | 311 movlw div_decoplan |
604 | 312 movwf divisor_decoplan ; reload divisor from CF |
0 | 313 return |
314 | |
315 store_dive_ppO2_sensors: | |
604 | 316 movf o2_ppo2_sensor1,W ; Sensor1 ppO2 (in 0.01 bar steps) |
317 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
318 SAFE_2BYTE_COPY o2_mv_sensor1,lo ; o2_mv_sensor may be modified via ISR during the two writes here... | |
319 movf lo,W ; in 0.1 mV steps | |
320 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
321 movf hi,W ; in 0.1 mV steps | |
322 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 323 |
604 | 324 movf o2_ppo2_sensor2,W ; Sensor2 ppO2 (in 0.01 bar steps) |
325 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
326 SAFE_2BYTE_COPY o2_mv_sensor2,lo ; o2_mv_sensor may be modified via ISR during the two writes here... | |
327 movf lo,W ; in 0.1 mV steps | |
328 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
329 movf hi,W ; in 0.1 mV steps | |
330 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 331 |
604 | 332 movf o2_ppo2_sensor3,W ; Sensor3 ppO2 (in 0.01 bar steps) |
333 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
334 SAFE_2BYTE_COPY o2_mv_sensor3,lo ; o2_mv_sensor may be modified via ISR during the two writes here... | |
335 movf lo,W ; in 0.1 mV steps | |
336 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
337 movf hi,W ; in 0.1 mV steps | |
338 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 339 |
340 movlw div_ppo2_sensors | |
604 | 341 movwf divisor_ppo2_sensors ; reload divisor |
0 | 342 return |
343 | |
344 store_dive_gf: | |
604 | 345 movff int_O_gradient_factor+0,WREG ; gradient factor absolute (range is limited to 255, only lower byte used for value) |
346 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 347 movlw div_gf |
604 | 348 movwf divisor_gf ; reload divisor |
0 | 349 return |
350 | |
351 store_dive_decodata: | |
582 | 352 ; Check if deco stops are necessary |
604 | 353 movff char_O_first_deco_depth,WREG ; get ceiling |
354 tstfsz WREG ; ceiling < 0 m (aka in deco) ? | |
355 bra store_dive_decodata_deco ; YES | |
582 | 356 ; NO - within NDL |
604 | 357 clrf WREG ; =0: no stop dive |
358 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
359 movff char_O_nullzeit,WREG ; remaining NDL time | |
360 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
582 | 361 bra store_dive_decodata_common |
362 store_dive_decodata_deco: | |
363 ; YES - in deco | |
604 | 364 movff char_O_first_deco_depth,WREG ; ceiling in m |
365 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
366 movff char_O_first_deco_time,WREG ; length of first stop in minutes | |
367 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
582 | 368 store_dive_decodata_common: |
0 | 369 movlw div_deco |
604 | 370 movwf divisor_deco ; Reload divisor |
0 | 371 return |
372 | |
373 store_dive_temperature: | |
582 | 374 SAFE_2BYTE_COPY temperature,lo |
604 | 375 movf lo,W ; append temperature to current sample! |
376 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 377 movf hi,W |
604 | 378 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 379 movlw div_temperature |
604 | 380 movwf divisor_temperature ; reload divisor |
0 | 381 return |
382 | |
383 ghostwrite_byte_header: | |
604 | 384 goto write_byte_ext_flash_plus_header ; (this call will also delete the 4kB TOC entry first) |
582 | 385 ; returns... |
0 | 386 |
387 ghostwrite_byte_profile: | |
604 | 388 goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000 |
582 | 389 ; returns... |
0 | 390 |
391 global ghostwriter_end_dive | |
392 ghostwriter_end_dive: | |
393 movff ext_flash_address+0,ext_flash_log_pointer+0 | |
394 movff ext_flash_address+1,ext_flash_log_pointer+1 | |
604 | 395 movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header |
0 | 396 |
604 | 397 movff menupos3,customview_divemode ; store last custom view |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
35
diff
changeset
|
398 |
604 | 399 btfss realdive ; dive longer then one minute |
400 goto ghostwriter_end_dive_common ; NO - discard everything | |
0 | 401 |
402 ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... | |
604 | 403 ifndef __DEBUG |
404 btfsc simulatormode_active ; are we in simulator mode? | |
405 goto ghostwriter_end_dive_common_sim ; YES - discard everything | |
406 endif | |
0 | 407 |
604 | 408 btfsc FLAG_apnoe_mode ; in Apnoe mode? |
409 goto ghostwriter_end_dive_common ; YES - discard everything | |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
410 |
604 | 411 ; Dive finished (and longer than one minute) |
0 | 412 |
604 | 413 btfsc FLAG_apnoe_mode ; calc max. depth (again) for very short apnoe dives |
0 | 414 call apnoe_calc_maxdepth |
415 | |
416 ; calculate desaturation time | |
604 | 417 movff last_surfpressure_30min+0,int_I_pres_surface+0 ; pass surface to desat routine ! |
0 | 418 movff last_surfpressure_30min+1,int_I_pres_surface+1 |
419 | |
582 | 420 call deco_calc_dive_interval_1min ; calculate deco in surface mode |
421 call deco_calc_desaturation_time ; calculate desaturation time | |
422 banksel common ; select ram bank 1 | |
423 | |
604 | 424 movlw 0xFD ; .... End-of-Profile bytes |
425 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 426 movlw 0xFD |
604 | 427 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 428 movff ext_flash_address+0,ext_flash_log_pointer+0 |
429 movff ext_flash_address+1,ext_flash_log_pointer+1 | |
604 | 430 movff ext_flash_address+2,ext_flash_log_pointer+2 ; save end-of-profile pointer to store in header |
0 | 431 |
582 | 432 ; Set to first address again to store dive length ext_flash_dive_counter:3 |
604 | 433 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 |
0 | 434 |
604 | 435 incf_ext_flash_address_0x20 d'6' ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header |
582 | 436 ; Store dive length |
437 movf ext_flash_dive_counter+0,W | |
604 | 438 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 |
582 | 439 movf ext_flash_dive_counter+1,W |
604 | 440 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 |
582 | 441 movf ext_flash_dive_counter+2,W |
604 | 442 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 |
0 | 443 |
604 | 444 ; profile recording done |
0 | 445 |
446 ; Load total number of dives | |
447 read_int_eeprom .2 | |
448 movff EEDATA,lo | |
449 read_int_eeprom .3 | |
450 movff EEDATA,hi | |
582 | 451 ; +1 ; increase total dive counter |
452 infsnz lo,F | |
147 | 453 incf hi,F |
0 | 454 ; Store new number in EEPROM |
455 movff lo,EEDATA | |
582 | 456 write_int_eeprom .2 |
0 | 457 movff hi,EEDATA |
582 | 458 write_int_eeprom .3 |
0 | 459 |
582 | 460 decf lo,F ; -1 |
461 | |
0 | 462 ; Set ext_flash_address:3 to TOC entry of this dive |
463 ; 1st: 200000h-200FFFh -> lo=0 | |
464 ; 2nd: 201000h-201FFFh -> lo=1 | |
465 ; 3rd: 202000h-202FFFh -> lo=2 | |
466 ; 255: 2FF000h-2FFFFFh -> lo=255 | |
467 | |
468 clrf ext_flash_address+0 | |
469 clrf ext_flash_address+1 | |
470 movlw 0x20 | |
471 movwf ext_flash_address+2 | |
472 movlw .16 | |
582 | 473 mulwf lo ; lo*16 = offset to 0x2000 (up:hi) |
0 | 474 movf PRODL,W |
475 addwf ext_flash_address+1,F | |
476 movf PRODH,W | |
477 addwfc ext_flash_address+2,F | |
582 | 478 |
0 | 479 ; Now, write header |
480 | |
604 | 481 movlw 0xFA ; header start |
482 rcall ghostwrite_byte_header ; (this call will also delete the 4kB TOC entry first) | |
0 | 483 movlw 0xFA |
604 | 484 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 485 |
582 | 486 ; store pointer to begin of dive profile |
487 read_int_eeprom .4 | |
0 | 488 movf EEDATA,W |
604 | 489 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 490 read_int_eeprom .5 |
0 | 491 movf EEDATA,W |
604 | 492 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 493 read_int_eeprom .6 |
0 | 494 movf EEDATA,W |
604 | 495 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 496 |
582 | 497 ; store pointer to end of dive profile |
0 | 498 movf ext_flash_log_pointer+0,W |
604 | 499 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 500 movf ext_flash_log_pointer+1,W |
604 | 501 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 502 movf ext_flash_log_pointer+2,W |
604 | 503 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 504 |
505 ; write rest of header | |
604 | 506 movlw logbook_profile_version ; defined in hwos.inc |
507 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 508 |
582 | 509 ; Store dive length |
510 movf ext_flash_dive_counter+0,W | |
604 | 511 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 512 movf ext_flash_dive_counter+1,W |
604 | 513 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 514 movf ext_flash_dive_counter+2,W |
604 | 515 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 516 |
604 | 517 lfsr FSR0,start_year ; load base address of start-of-dive data |
518 movf POSTINC0,W ; year | |
519 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
520 movf POSTINC0,W ; month | |
521 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
522 movf POSTINC0,W ; day | |
523 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
524 movf POSTINC0,W ; hour | |
525 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
526 movf POSTINC0,W ; minute | |
527 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 528 |
604 | 529 btfss FLAG_apnoe_mode ; store apnoe max or normal max (which is only max from the last descent) |
530 bra end_dive1 ; store normal depth | |
0 | 531 |
532 movff apnoe_max_pressure+0,lo | |
533 movff apnoe_max_pressure+1,hi | |
582 | 534 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] |
0 | 535 movff lo,apnoe_max_pressure+0 |
536 movff hi,apnoe_max_pressure+1 | |
604 | 537 |
538 movf lo,W ; max. depth, low byte | |
539 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
540 movf hi,W ; max. depth, high byte | |
541 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
582 | 542 bra end_dive2 ; skip normal max. depth |
543 | |
0 | 544 end_dive1: |
545 movff max_pressure+0,lo | |
546 movff max_pressure+1,hi | |
582 | 547 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] |
0 | 548 movff lo,max_pressure+0 |
549 movff hi,max_pressure+1 | |
582 | 550 |
604 | 551 movf lo,W ; max. depth, low byte |
552 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
553 movf hi,W ; max. depth, high byte | |
554 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 555 |
556 end_dive2: | |
582 | 557 movf divemins+0,W ; dive time minutes |
604 | 558 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 559 movf divemins+1,W |
604 | 560 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 561 movf divesecs,W ; dive time seconds |
604 | 562 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
560 | 563 movff minimum_temperature+0,WREG ; minimum temperature |
604 | 564 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 565 movff minimum_temperature+1,WREG |
604 | 566 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 567 movff last_surfpressure_30min+0,WREG ; air pressure before dive |
604 | 568 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 569 movff last_surfpressure_30min+1,WREG |
604 | 570 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
560 | 571 movff int_O_desaturation_time+0,WREG ; desaturation time in minutes |
604 | 572 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 573 movff int_O_desaturation_time+1,WREG |
604 | 574 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 575 |
604 | 576 btfsc FLAG_ccr_mode ; in CCR mode? |
577 bra end_dive_dil_gaslist ; YES - write diluent gas list | |
578 btfsc FLAG_pscr_mode ; in pSCR mode? | |
579 bra end_dive_dil_gaslist ; YES - write diluent gas list | |
0 | 580 |
604 | 581 end_dive_oc_gaslist: ; write OC gases |
582 lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement | |
583 bra end_dive_gaslist ; write all 5 OC gases | |
0 | 584 |
604 | 585 end_dive_dil_gaslist: ; write diluents |
586 lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement | |
587 ;bra end_dive_gaslist ; write all 5 diluents | |
0 | 588 |
604 | 589 end_dive_gaslist: ; helper function for writing gas list entries |
590 ; | |
591 ; Memory Map: | |
592 ; ------------------------- | |
593 ; opt_gas_O2_ratio res 5 | |
594 ; opt_dil_O2_ratio res 5 | |
595 ; opt_gas_He_ratio res 5 | |
596 ; opt_dil_He_ratio res 5 | |
597 ; opt_gas_type res 5 | |
598 ; opt_dil_type res 5 | |
599 ; opt_gas_change res 5 | |
600 ; opt_dil_change res 5 | |
601 ; | |
602 movlw .5 ; 5 gases to store | |
603 movwf lo ; use lo as counter | |
604 end_dive_gaslist_loop: | |
605 movf PREINC0,W ; increment base address and get O2 ratio into WREG | |
606 rcall ghostwrite_byte_header ; store data | |
607 movlw .10 ; offset for H2 ratios | |
608 movf PLUSW0,W ; get H2 ratio into WREG | |
609 rcall ghostwrite_byte_header ; store data | |
610 movlw .30 ; offset for change depths | |
611 movf PLUSW0,W ; get change depth into WREG | |
612 rcall ghostwrite_byte_header ; store data | |
613 movlw .20 ; offset for types | |
614 movf PLUSW0,W ; get type into WREG | |
615 rcall ghostwrite_byte_header ; store data | |
616 decfsz lo ; decrement counter, did it became 0 ? | |
617 bra end_dive_gaslist_loop ; NO - loop | |
618 ;bra end_dive_oc_cc_common ; YES - done | |
0 | 619 |
620 end_dive_oc_cc_common: | |
604 | 621 movlw softwareversion_x ; firmware version |
0 | 622 rcall ghostwrite_byte_header |
623 movlw softwareversion_y | |
624 rcall ghostwrite_byte_header | |
604 | 625 movf batt_voltage+0,W ; battery voltage |
0 | 626 rcall ghostwrite_byte_header |
627 movf batt_voltage+1,W | |
628 rcall ghostwrite_byte_header | |
629 | |
582 | 630 movf samplingrate,W ; Sampling rate |
631 btfsc FLAG_apnoe_mode ; Apnoe mode? | |
632 movlw samplingrate_apnoe ; Apnoe sampling rate | |
604 | 633 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 634 |
582 | 635 ; CNS at beginning of dive |
0 | 636 movff CNS_start+0,WREG |
604 | 637 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 638 movff CNS_start+1,WREG |
604 | 639 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 640 ; Gradient factor |
641 movff GF_start,WREG | |
604 | 642 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 643 movff int_O_gradient_factor+0,WREG ; value limited to 255, only lower byte in use |
604 | 644 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
5 | 645 |
582 | 646 ; Logbook offset |
647 call do_logoffset_common_read ; Read into lo:hi | |
648 movf lo,W | |
604 | 649 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 650 movf hi,W |
604 | 651 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
5 | 652 |
582 | 653 ; Battery info at Byte 59 |
654 movf batt_percent,W ; 0-100 | |
604 | 655 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
656 | |
657 ; Store the setpoints | |
658 lfsr FSR0,char_I_setpoint_cbar ; base address of ppO2 values | |
659 lfsr FSR1,char_I_setpoint_change ; base address of change depths | |
660 movlw .5 ; 5 setpoints to store | |
661 movwf lo ; use lo as counter | |
662 end_dive_sp_loop: | |
663 movf POSTINC0,W ; get ppO2 value | |
664 rcall ghostwrite_byte_header ; store ppO2 value | |
665 movf POSTINC1,W ; get change depth | |
666 rcall ghostwrite_byte_header ; store change depth | |
667 decfsz lo ; decrement counter, did it became 0 ? | |
668 bra end_dive_sp_loop ; NO - loop | |
0 | 669 |
604 | 670 ; Store further data |
671 movff opt_salinity,WREG ; salinity (0-4%) | |
672 rcall ghostwrite_byte_header ; store salinity | |
0 | 673 |
604 | 674 movff int_O_CNS_fraction+0,WREG ; CNS value, low byte |
675 rcall ghostwrite_byte_header ; store CNS% | |
676 movff int_O_CNS_fraction+1,WREG ; CNS value, high byte | |
677 bcf WREG,int_warning_flag ; clear warning flag | |
678 bcf WREG,int_attention_flag ; clear attention flag | |
679 rcall ghostwrite_byte_header ; store CNS% | |
0 | 680 |
604 | 681 movff avg_rel_pressure_total+0,WREG ; average depth |
682 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
683 movff avg_rel_pressure_total+1,WREG ; average depth | |
684 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
685 | |
686 movff total_divetime_seconds+0,WREG ; total dive time (regardless of start_dive_threshold) | |
687 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
688 movff total_divetime_seconds+1,WREG ; total dive time (regardless of start_dive_threshold) | |
689 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 690 |
691 movff char_I_GF_Low_percentage,WREG ; GF_lo | |
692 movff char_I_deco_model,lo | |
693 decfsz lo,F ; jump over next line if char_I_deco_model == 1 | |
604 | 694 movff char_I_saturation_multiplier,WREG ; saturation multiplier |
695 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 696 |
697 movff char_I_GF_High_percentage,WREG ; GF_hi | |
698 movff char_I_deco_model,lo | |
699 decfsz lo,F ; jump over next line if char_I_deco_model == 1 | |
604 | 700 movff char_I_desaturation_multiplier,WREG ; desaturation multiplier |
701 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 702 |
703 movff char_I_deco_model,WREG ; 0 = ZH-L16, 1 = ZH-L16-GF | |
582 | 704 rcall ghostwrite_byte_header ; writes byte and increases address (no banking) |
0 | 705 |
582 | 706 read_int_eeprom .2 |
0 | 707 movf EEDATA,W |
604 | 708 rcall ghostwrite_byte_header ; total dive counter, low |
582 | 709 read_int_eeprom .3 |
0 | 710 movf EEDATA,W |
604 | 711 rcall ghostwrite_byte_header ; total dive counter, high |
0 | 712 |
582 | 713 movff opt_dive_mode,WREG |
714 rcall ghostwrite_byte_header ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR | |
0 | 715 |
582 | 716 ; Store all tissue data available |
717 movlw .16 | |
718 movwf lo | |
719 lfsr FSR1,char_O_tissue_N2_saturation+0 | |
0 | 720 end_dive_store_tissues_N2: |
582 | 721 movf POSTINC1,W |
722 bcf WREG,7 ; clear flag bit for ongassing/offgassing | |
604 | 723 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 724 decfsz lo,F |
604 | 725 bra end_dive_store_tissues_N2 ; NO |
0 | 726 |
582 | 727 movlw .64 |
728 movwf lo | |
604 | 729 lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4 Byte Float = 64 Bytes |
0 | 730 end_dive_store_tissues_N2_2: |
582 | 731 movf POSTINC1,W |
604 | 732 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 733 decfsz lo,F |
604 | 734 bra end_dive_store_tissues_N2_2 ; NO |
0 | 735 |
582 | 736 movlw .16 |
737 movwf lo | |
738 lfsr FSR1,char_O_tissue_He_saturation+0 | |
0 | 739 end_dive_store_tissues_He: |
582 | 740 movf POSTINC1,W |
741 bcf WREG,7 ; clear flag bit for ongassing/offgassing | |
604 | 742 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 743 decfsz lo,F |
604 | 744 bra end_dive_store_tissues_He ; NO |
0 | 745 |
582 | 746 movlw .64 |
747 movwf lo | |
604 | 748 lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4 Byte Float = 64 Bytes |
0 | 749 end_dive_store_tissues_He_2: |
582 | 750 movf POSTINC1,W |
604 | 751 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 752 decfsz lo,F |
604 | 753 bra end_dive_store_tissues_He_2 ; NO |
0 | 754 |
582 | 755 ; Some deco stuff |
756 movff char_I_depth_last_deco,WREG ; last stop [m] | |
604 | 757 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 758 movff char_I_deco_distance,WREG ; assumed distance to shown stop |
604 | 759 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 760 |
582 | 761 ; Last HUD data |
604 | 762 movff hud_battery_mv+0,WREG ; last HUD battery value |
763 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
764 movff hud_battery_mv+1,WREG ; last HUD battery value | |
765 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
766 movff hud_status_byte,WREG ; last HUD status | |
767 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 768 |
582 | 769 ; Battery gauge registers [nAs] |
604 | 770 lfsr FSR0,battery_gauge ; load base address of battery gauge register |
771 movf POSTINC0,W ; get byte 0 | |
772 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
773 movf POSTINC0,W ; get byte 1 | |
774 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
775 movf POSTINC0,W ; get byte 2 | |
776 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
777 movf POSTINC0,W ; get byte 3 | |
778 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
779 movf POSTINC0,W ; get byte 4 | |
780 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
781 movf POSTINC0,W ; get byte 5 | |
782 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 783 |
582 | 784 ; Header stop |
0 | 785 movlw 0xFB |
604 | 786 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 787 movlw 0xFB |
604 | 788 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 789 |
604 | 790 call divemode_store_statistics ; store/update statistics for this unit |
0 | 791 |
792 clrf surface_interval+0 | |
604 | 793 clrf surface_interval+1 ; clear surface interval timer |
0 | 794 |
795 ghostwriter_end_dive_common: | |
796 ; Update ext_flash_log_pointer into EEPROM | |
797 clrf EEADRH | |
798 movff ext_flash_log_pointer+0,EEDATA | |
799 write_int_eeprom .4 | |
800 movff ext_flash_log_pointer+1,EEDATA | |
801 write_int_eeprom .5 | |
802 movff ext_flash_log_pointer+2,EEDATA | |
803 write_int_eeprom .6 | |
804 | |
582 | 805 bcf simulatormode_active ; if we were in simulator mode |
0 | 806 |
807 ; In DEBUG compile, keep all simulated dives in logbook, Desat time, nofly, etc... | |
604 | 808 ifndef __DEBUG |
809 btfsc restore_deco_data ; restore decodata? | |
810 call deco_pull_tissues_from_vault | |
811 banksel common ; bank 1 | |
812 endif | |
560 | 813 call update_battery_registers ; update battery registers into EEPROM |
582 | 814 goto surfloop ; and return to surface loop |
0 | 815 |
604 | 816 |
166
30ebaf72170d
BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents:
147
diff
changeset
|
817 ghostwriter_end_dive_common_sim: |
604 | 818 tstfsz surface_interval+0 ; was interval zero? |
819 bra ghostwriter_end_dive_common_sim2 ; NO | |
820 tstfsz surface_interval+1 ; was interval zero? | |
821 bra ghostwriter_end_dive_common_sim2 ; NO | |
822 bra ghostwriter_end_dive_common ; YES - done | |
174
932e91074bdb
CHANGE: Clarify Travel Gases with "---" as change depth
heinrichsweikamp
parents:
170
diff
changeset
|
823 ghostwriter_end_dive_common_sim2: |
582 | 824 movf divemins+0,W |
825 addwf surface_interval+0,F | |
826 movf divemins+1,W | |
604 | 827 addwfc surface_interval+1 ; add simulated dive time to surface interval |
582 | 828 bra ghostwriter_end_dive_common |
166
30ebaf72170d
BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents:
147
diff
changeset
|
829 |
604 | 830 |
831 ghostwriter_load_pointer: ; load ext_flash_address:3 from EEPROM .4-.6 | |
832 clrf EEADRH ; make sure to select EEPROM bank 0 | |
0 | 833 read_int_eeprom .4 |
834 movff EEDATA,ext_flash_address+0 | |
835 read_int_eeprom .5 | |
836 movff EEDATA,ext_flash_address+1 | |
837 read_int_eeprom .6 | |
838 movff EEDATA,ext_flash_address+2 | |
582 | 839 return |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
840 |
604 | 841 ghostwriter_short_header_init: ; proceed one page forward |
582 | 842 clrf EEDATA |
604 | 843 write_int_eeprom .4 ; ext_flash_address+0 = 0 |
582 | 844 movlw .16 |
845 addwf ext_flash_address+1,F | |
846 movlw .0 | |
847 addwfc ext_flash_address+2,F | |
848 movlw 0x20 | |
604 | 849 cpfseq ext_flash_address+2 ; at address 0x200000? |
850 bra ghostwriter_short_header_init2 ; NO | |
851 clrf ext_flash_address+2 ; YES - rollover to 0x000000 | |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
852 ghostwriter_short_header_init2: |
582 | 853 movlw 0xF0 |
604 | 854 andwf ext_flash_address+1,F ; keep higher nibble, set lower nibble to 0 |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
855 |
582 | 856 movff ext_flash_address+1,EEDATA |
604 | 857 write_int_eeprom .5 ; write new pointer |
582 | 858 movff ext_flash_address+2,EEDATA |
604 | 859 write_int_eeprom .6 ; write new pointer |
860 bra ghostwriter_short_header2 ; Done | |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
861 |
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
862 global ghostwriter_short_header |
604 | 863 ghostwriter_short_header: ; write short header with dive number into profile memory |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
864 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive) |
604 | 865 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
866 |
582 | 867 ; The following code is used to write a clean new dive after the previous hasn't been |
868 ; stored correctly. e.g. after a battery fail during the dive | |
604 | 869 call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw |
582 | 870 incfsz ext_flash_rw,F |
604 | 871 bra ghostwriter_short_header_init ; not 0xFF -> init page |
872 call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw | |
582 | 873 incfsz ext_flash_rw,F |
604 | 874 bra ghostwriter_short_header_init ; not 0xFF -> init page |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
875 |
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
876 ghostwriter_short_header2: |
582 | 877 ; All ok, reload the pointer and start |
604 | 878 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 |
0 | 879 |
582 | 880 ; Clear dive length counter |
881 clrf ext_flash_dive_counter+0 | |
882 clrf ext_flash_dive_counter+1 | |
883 clrf ext_flash_dive_counter+2 | |
0 | 884 |
582 | 885 ; Write short header with dive number into profile memory |
0 | 886 movlw 0xFA |
604 | 887 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 888 movlw 0xFA |
604 | 889 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 890 ; Load total number of dives (low byte only) |
891 read_int_eeprom .2 | |
604 | 892 incf EEDATA,W ; +1 |
893 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 894 read_int_eeprom .3 |
895 movf EEDATA,W | |
604 | 896 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 897 movlw 0xFA |
604 | 898 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 899 movlw 0xFA |
604 | 900 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
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
|
901 |
582 | 902 ; Keep room for dive length ext_flash_dive_counter:3 (Stored at the end of the dive) |
903 ; Writing 0xFF three times here is mandatory | |
904 ; - 0xFF can be overwritten after the dive | |
905 ; - ghostwrite_byte_profile takes care of 4kB Page switching | |
906 ; - fixes an issue when we are at exactly 0xXXX000 here... | |
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
|
907 |
582 | 908 movlw 0xFF |
604 | 909 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
582 | 910 movlw 0xFF |
604 | 911 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
582 | 912 movlw 0xFF |
604 | 913 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
0 | 914 |
604 | 915 movf samplingrate,W ; sampling rate |
916 btfsc FLAG_apnoe_mode ; apnoe mode? | |
917 movlw samplingrate_apnoe ; apnoe sampling rate | |
918 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 919 |
604 | 920 movlw .7 ; number of divisors |
921 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 922 |
604 | 923 movlw .0 ; type |
924 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 925 movlw infolength_temperature |
604 | 926 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
927 movlw div_temperature ; divisor temperature | |
928 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 929 |
582 | 930 movlw .1 ; Type |
604 | 931 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 932 movlw infolength_deco |
604 | 933 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
934 movlw div_deco ; divisor deco data | |
935 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 936 |
604 | 937 movlw .2 ; type |
938 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 939 movlw infolength_gf |
604 | 940 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
941 movlw div_gf ; divisor gf | |
942 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 943 |
604 | 944 movlw .3 ; type |
945 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 946 movlw infolength_ppo2_sensors |
604 | 947 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
948 movlw div_ppo2_sensors ; divisor ppO2 | |
582 | 949 btfss FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active |
604 | 950 movlw .0 ; no ppO2 data in OC mode |
951 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 952 |
604 | 953 movlw .4 ; type |
954 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 955 movlw infolength_decoplan |
604 | 956 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
957 movlw div_decoplan ; divisor debug | |
958 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 959 |
582 | 960 movlw .5 ; Type |
604 | 961 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 962 movlw infolength_cns |
604 | 963 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
964 movlw div_cns ; divisor CNS | |
965 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 966 |
582 | 967 movlw .6 ; Type |
604 | 968 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 969 movlw infolength_tank |
604 | 970 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
971 movlw div_tank ; divisor tank | |
972 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 973 |
974 return | |
582 | 975 |
604 | 976 divemode_store_statistics: ; store/update statistics for this unit |
582 | 977 call vault_decodata_into_eeprom ; update deco data |
604 | 978 call do_logoffset_common_read ; existing logbook offset into lo:hi |
582 | 979 |
980 tstfsz lo ; lo=0? | |
604 | 981 bra change_logbook_offset1 ; NO - adjust offset |
582 | 982 tstfsz hi ; hi=0? |
604 | 983 bra change_logbook_offset1 ; NO - adjust offset |
984 bra change_logbook_offset2 ; lo=0 and hi=0 -> skip offset routine | |
582 | 985 |
0 | 986 change_logbook_offset1: |
987 movlw d'1' | |
988 addwf lo | |
989 movlw d'0' | |
990 addwfc hi | |
582 | 991 call do_logoffset_common_write ; lo:hi -> EEPROM |
992 | |
0 | 993 change_logbook_offset2: |
453
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
994 ; Clear lastdive:4 |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
995 banksel lastdive_time+0 |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
996 clrf lastdive_time+0 |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
997 clrf lastdive_time+1 |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
998 clrf lastdive_time+2 |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
999 clrf lastdive_time+3 |
503
4542d03f748a
NEW: Last Dive customviews in surface mode with divetime, depth and interval
heinrichsweikamp
parents:
490
diff
changeset
|
1000 movff divemins+0,lastdive_duration+0 |
4542d03f748a
NEW: Last Dive customviews in surface mode with divetime, depth and interval
heinrichsweikamp
parents:
490
diff
changeset
|
1001 movff divemins+1,lastdive_duration+1 |
582 | 1002 movff divesecs, lastdive_duration+2 |
503
4542d03f748a
NEW: Last Dive customviews in surface mode with divetime, depth and interval
heinrichsweikamp
parents:
490
diff
changeset
|
1003 movff max_pressure+0,lastdive_maxdepth+0 |
4542d03f748a
NEW: Last Dive customviews in surface mode with divetime, depth and interval
heinrichsweikamp
parents:
490
diff
changeset
|
1004 movff max_pressure+1,lastdive_maxdepth+1 |
453
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
1005 banksel common |
b4f28ab23b87
NEW: Show Uptime (Time since last firmware boot) in information menu
heinrichsweikamp
parents:
437
diff
changeset
|
1006 |
0 | 1007 ; Add more here... |
1008 return | |
1009 | |
582 | 1010 END |