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