Mercurial > public > hwos_code
annotate src/ghostwriter.asm @ 629:237931377539
3.07 stable release
author | heinrichsweikamp |
---|---|
date | Fri, 29 Nov 2019 18:48:11 +0100 |
parents | cd58f7fc86db |
children | 185ba2f91f59 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
629 | 3 ; File ghostwriter.asm combined next generation V3.06.2 |
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 "tft_outputs.inc" | |
19 #include "divemode.inc" | |
20 #include "rtc.inc" | |
21 | |
623 | 22 |
604 | 23 extern deco_pull_tissues_from_vault |
24 | |
582 | 25 |
623 | 26 ; private local Variables |
582 | 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 | |
623 | 31 divisor_supersat ; divisor used to time the sampling of dive data |
582 | 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 | |
623 | 40 ghostwriter CODE |
582 | 41 |
42 ;============================================================================= | |
43 | |
0 | 44 |
604 | 45 global init_recording_params ; initialize profile recording parameters |
582 | 46 init_recording_params: |
623 | 47 movlw div_temperature ; get divisor for temperature storage |
48 movwf divisor_temperature ; initialize divisor | |
49 | |
50 movlw div_deco ; ... | |
51 movwf divisor_deco ; ... | |
52 | |
582 | 53 movlw div_gf |
623 | 54 movwf divisor_supersat |
55 | |
56 movlw div_decoplan | |
57 movwf divisor_decoplan | |
58 | |
59 movlw div_cns | |
60 movwf divisor_cns | |
61 | |
628 | 62 IFDEF _rx_functions |
63 clrf WREG ; default to no tank data logging | |
64 btfsc tr_functions_activated ; TR functions activated? | |
65 movlw div_tank ; YES - get divisor for tank data | |
66 movwf divisor_tank ; initialize divisor | |
67 ENDIF | |
623 | 68 |
69 IFDEF _external_sensor | |
582 | 70 movlw div_ppo2_sensors |
71 movwf divisor_ppo2_sensors | |
623 | 72 |
582 | 73 btfsc FLAG_ccr_mode ; in CCR mode? |
74 bra init_recording_params_2 ; YES | |
75 btfsc FLAG_pscr_mode ; in pSCR mode? | |
76 bra init_recording_params_2 ; YES | |
604 | 77 ; in all modes but CCR and pSCR, disable ppO2 logging |
582 | 78 movlw .0 |
79 movwf divisor_ppo2_sensors | |
623 | 80 ENDIF |
81 | |
582 | 82 init_recording_params_2: |
83 return | |
84 | |
0 | 85 |
86 global store_dive_data | |
560 | 87 store_dive_data: |
623 | 88 bcf trigger_sample_divedata ; clear flag |
0 | 89 |
623 | 90 ifndef _DEBUG |
91 btfsc sensor_override_active ; in simulator mode? | |
92 return ; YES - no dive data stored in simulator mode | |
93 endif | |
0 | 94 |
623 | 95 btfss FLAG_apnoe_mode ; in apnoe mode? |
96 bra store_dive_data_1 ; NO - proceed | |
97 TSTOSS opt_store_apnoe_dive ; YES - logging in apnoe mode enabled? | |
98 return ; NO - done | |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
99 |
623 | 100 store_dive_data_1: |
101 ; Store depth with every sample | |
102 movf pressure_rel_cur_cached+0,W ; get depth (relative pressure), low byte | |
103 rcall ghostwrite_byte_profile ; store to profile in ext. flash | |
104 movf pressure_rel_cur_cached+1,W ; get depth (relative pressure), high byte | |
105 rcall ghostwrite_byte_profile ; store to profile in ext. flash | |
0 | 106 |
604 | 107 ; First, find out how many bytes will be appended to this sample set |
582 | 108 clrf ProfileFlagByte ; clear number of bytes to append |
0 | 109 |
623 | 110 ; Check Extended Information |
111 decfsz divisor_temperature,W ; check divisor if it will become 0, dump decremented value to WREG | |
112 bra check_extended1 ; NO - skip | |
113 movlw infolength_temperature ; YES - get length of extra data | |
114 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 115 check_extended1: |
623 | 116 decfsz divisor_deco,W ; check divisor if it will become 0, dump decremented value to WREG |
117 bra check_extended2 ; NO - skip | |
118 movlw infolength_deco ; YES - get length of extra data | |
119 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 120 check_extended2: |
623 | 121 decfsz divisor_supersat,W ; check divisor if it will become 0, dump decremented value to WREG |
122 bra check_extended3 ; NO - skip | |
123 movlw infolength_gf ; YES - get length of extra data | |
582 | 124 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
0 | 125 check_extended3: |
623 | 126 IFDEF _external_sensor |
127 decfsz divisor_ppo2_sensors,W ; check divisor if it will become 0, dump decremented value to WREG | |
128 bra check_extended4 ; NO - skip | |
129 movlw infolength_ppo2_sensors ; YES - get length of extra data | |
130 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
131 ENDIF | |
0 | 132 check_extended4: |
623 | 133 decfsz divisor_decoplan,W ; check divisor if it will become 0, dump decremented value to WREG |
134 bra check_extended5 ; NO - skip | |
135 movlw infolength_decoplan ; YES - get length of extra data | |
136 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 137 check_extended5: |
623 | 138 decfsz divisor_cns,W ; check divisor if it will become 0, dump decremented value to WREG |
139 bra check_extended6 ; NO - skip | |
140 movlw infolength_cns ; YES - get length of extra data | |
141 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 142 check_extended6: |
628 | 143 IFDEF _rx_functions |
623 | 144 decfsz divisor_tank,W ; check divisor if it will become 0, dump decremented value to WREG |
145 bra check_extended7 ; NO - skip | |
146 movlw infolength_tank ; YES - get length of extra data | |
147 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
628 | 148 ENDIF |
0 | 149 check_extended7: |
150 | |
151 ; Second, check global event flag | |
604 | 152 btfss event_occured ; check global event flag |
153 bra store_dive_data3 ; no event | |
99
87cc1adfe4da
show event "bailout" in the internal logbook
heinrichsweikamp
parents:
98
diff
changeset
|
154 |
623 | 155 incf ProfileFlagByte,F ; add one byte (the event byte 1) |
0 | 156 |
623 | 157 clrf event_byte1 ; reset event byte 1 |
158 clrf event_byte2 ; reset event byte 2 | |
0 | 159 |
623 | 160 movf alarm_type,W ; type of alarm Bit 0-3 |
161 addwf event_byte1,F ; copy to event byte 1, bit 0-3 | |
162 clrf alarm_type ; reset alarm type | |
582 | 163 |
560 | 164 ; Third, check events and add additional bytes |
623 | 165 btfss event_gas_change_gas6 ; did a change to gas 6 occur? |
166 bra check_event2 ; NO | |
167 movlw d'2' ; YES - set information length | |
168 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
169 bsf event_byte1,4 ; - set flag in event byte 1 | |
0 | 170 check_event2: |
623 | 171 btfss event_gas_change ; did a gas change occur? |
172 bra check_event3 ; NO | |
173 movlw d'1' ; YES - set information length | |
174 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
175 bsf event_byte1,5 ; - set flag in event byte 1 | |
0 | 176 check_event3: |
623 | 177 IFDEF _ccr_pscr |
178 btfss event_SP_change ; did a setpoint change occur? | |
179 bra check_event4 ; NO | |
180 movlw d'1' ; YES - set information length | |
181 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
182 bsf event_byte1,6 ; - set flag in event byte 1 | |
183 ENDIF | |
0 | 184 check_event4: |
623 | 185 IFDEF _ccr_pscr |
186 btfss event_bailout ; did a gas change due to bailout occur? | |
582 | 187 bra check_event5 |
604 | 188 movlw d'2' ; information length |
582 | 189 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
623 | 190 bsf event_byte2,0 ; set flag in event byte 2 |
191 bsf event_byte1,7 ; =1: another event byte is available | |
192 ENDIF | |
98 | 193 |
194 check_event5: | |
0 | 195 ; more events? |
196 | |
197 store_dive_data3: | |
623 | 198 btfsc event_byte1,7 ; =1: another event byte is available |
199 incf ProfileFlagByte,F ; add one byte (the event byte 2) | |
98 | 200 |
604 | 201 btfsc event_occured ; check global event flag |
623 | 202 bsf ProfileFlagByte,7 ; set event byte 1 flag in ProfileFlagByte |
98 | 203 |
604 | 204 movf ProfileFlagByte,W ; finally, write ProfileFlagByte |
205 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
98 | 206 |
604 | 207 btfss event_occured ; check global event flag (again) |
208 bra store_dive_data4 ; no event | |
98 | 209 |
628 | 210 ; Store the EventByte(s) + additional bytes now |
623 | 211 movf event_byte1,W |
604 | 212 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
623 | 213 movf event_byte2,W ; write second event byte... |
214 btfsc event_byte1,7 ; =1: another event byte is available | |
215 rcall ghostwrite_byte_profile ; store that information | |
0 | 216 |
623 | 217 btfss event_gas_change_gas6 ; did a change to gas 6 occur? |
218 bra store_dive_data3b ; NO | |
219 movff char_I_O2_ratio,WREG ; YES - get gas 6 O2 ratio | |
220 rcall ghostwrite_byte_profile ; - store it | |
221 IFDEF _helium | |
222 movff char_I_He_ratio,WREG ; - get gas 6 He ratio | |
223 ELSE | |
224 clrf WREG ; - He ratio is zero | |
225 ENDIF | |
226 rcall ghostwrite_byte_profile ; - store it | |
227 bcf event_gas_change_gas6 ; - clear event flag | |
628 | 228 |
0 | 229 store_dive_data3b: |
623 | 230 btfss event_gas_change ; did a gas change occur? |
231 bra store_dive_data3c ; NO | |
232 IFDEF _ccr_pscr | |
628 | 233 movf active_dil,W ; YES - get active diluent by default |
623 | 234 btfsc FLAG_oc_mode ; - in OC mode? |
628 | 235 movf active_gas,W ; YES - replace by active gas |
623 | 236 btfsc bailout_mode ; - in bailout? |
237 ENDIF | |
628 | 238 movf active_gas,W ; YES - get active OC (bailout) gas |
623 | 239 rcall ghostwrite_byte_profile ; - store it |
240 bcf event_gas_change ; - clear event flag | |
628 | 241 |
0 | 242 store_dive_data3c: |
623 | 243 IFDEF _ccr_pscr |
244 btfss event_SP_change ; did a setpoint change occur? | |
245 bra store_dive_data3d ; NO | |
246 movff char_I_const_ppO2,WREG ; YES - get setpoint | |
247 rcall ghostwrite_byte_profile ; - store it | |
248 bcf event_SP_change ; - clear event flag | |
249 ENDIF | |
628 | 250 |
0 | 251 store_dive_data3d: |
623 | 252 IFDEF _ccr_pscr |
253 btfss event_bailout ; did a gas change due to bailout occur? | |
254 bra store_dive_data4 ; NO | |
255 movff char_I_O2_ratio,WREG ; YES - get O2 ratio of bailout gas | |
256 rcall ghostwrite_byte_profile ; - store it | |
257 IFDEF _helium | |
258 movff char_I_He_ratio,WREG ; - get He ratio of bailout gas | |
259 ELSE | |
260 clrf WREG ; - He ratio is zero | |
628 | 261 ENDIF ; helium |
623 | 262 rcall ghostwrite_byte_profile ; - store it |
263 bcf event_bailout ; - clear event flag | |
264 ENDIF ; _ccr_pscr | |
628 | 265 |
0 | 266 store_dive_data4: |
628 | 267 ; Store extended information |
268 | |
623 | 269 decfsz divisor_temperature,F ; time to store a temperature sample ? |
628 | 270 bra store_dive_data4a ; NO - skip |
623 | 271 rcall store_dive_temperature ; YES - store data |
628 | 272 store_dive_data4a: |
273 btfsc divisor_temperature,7 ; did the timer under-run? | |
274 clrf divisor_temperature ; YES - reset timer | |
275 | |
623 | 276 decfsz divisor_deco,F ; time to store the current deco data? |
628 | 277 bra store_dive_data4b ; NO - skip |
623 | 278 rcall store_dive_decodata ; YES - store data |
628 | 279 store_dive_data4b: |
280 btfsc divisor_deco,7 ; did the timer under-run? | |
281 clrf divisor_deco ; YES - reset timer | |
282 | |
623 | 283 decfsz divisor_supersat,F ; time to store the current supersaturation ? |
628 | 284 bra store_dive_data4c ; NO - skip |
623 | 285 rcall store_dive_supersat ; YES - store data |
628 | 286 store_dive_data4c: |
287 btfsc divisor_supersat,7 ; did the timer under-run? | |
288 clrf divisor_supersat ; YES - reset timer | |
289 | |
623 | 290 IFDEF _external_sensor |
291 decfsz divisor_ppo2_sensors,F ; decrement divisor, did it became 0 ? | |
628 | 292 bra store_dive_data4d ; NO - skip |
623 | 293 rcall store_dive_ppO2_sensors ; YES - store data |
628 | 294 store_dive_data4d: |
295 btfsc divisor_ppo2_sensors,7 ; did the timer under-run? | |
296 clrf divisor_ppo2_sensors ; YES - reset timer | |
623 | 297 ENDIF |
298 | |
628 | 299 decfsz divisor_decoplan,F ; decrement divisor, did it became 0 ? |
300 bra store_dive_data4e ; NO - skip | |
301 rcall store_dive_decoplan ; YES - store data | |
302 store_dive_data4e: | |
303 btfsc divisor_decoplan,7 ; did the timer under-run? | |
304 clrf divisor_decoplan ; YES - reset timer | |
623 | 305 |
628 | 306 decfsz divisor_cns,F ; decrement divisor, did it became 0 ? |
307 bra store_dive_data4f ; NO - skip | |
308 rcall store_dive_cns ; YES - store data | |
309 store_dive_data4f: | |
310 btfsc divisor_cns,7 ; did the timer under-run? | |
311 clrf divisor_cns ; YES - reset timer | |
623 | 312 |
628 | 313 IFDEF _rx_functions |
314 decfsz divisor_tank,F ; decrement divisor, did it became 0 ? | |
315 bra store_dive_data4g ; NO - skip | |
316 rcall store_dive_tank ; YES - store data | |
317 store_dive_data4g: | |
318 btfsc divisor_tank,7 ; did the timer under-run? | |
319 clrf divisor_tank ; YES - reset timer | |
320 ENDIF | |
0 | 321 |
322 store_dive_data5: | |
604 | 323 bcf event_occured ; clear the global event flag |
623 | 324 clrf event_byte1 ; reset event byte 1 |
325 clrf event_byte2 ; reset event byte 2 | |
628 | 326 return ; done (sample with all information written to external flash) |
327 | |
328 | |
329 IFDEF _rx_functions | |
330 store_dive_tank: | |
331 movff int_O_tank_pressure+0,WREG ; get tank pressure, low byte | |
332 rcall ghostwrite_byte_profile ; store it | |
333 movff int_O_tank_pressure+1,WREG ; get tank pressure, high byte | |
334 rcall ghostwrite_byte_profile ; store it | |
335 movlw div_tank ; get sampling rate | |
336 movwf divisor_tank ; reload timer | |
337 return | |
338 ENDIF | |
582 | 339 |
0 | 340 store_dive_cns: |
623 | 341 movff int_O_CNS_current+0,WREG ; get current CNS, low byte |
342 rcall ghostwrite_byte_profile ; store it | |
343 movff int_O_CNS_current+1,WREG ; get current CNS, high byte | |
604 | 344 bcf WREG,int_warning_flag ; clear warning flag |
345 bcf WREG,int_attention_flag ; clear attention flag | |
623 | 346 rcall ghostwrite_byte_profile ; store it |
628 | 347 movlw div_cns ; get sampling rate |
348 movwf divisor_cns ; reload timer | |
0 | 349 return |
350 | |
351 store_dive_decoplan: | |
582 | 352 ; Store the deco plan |
623 | 353 lfsr FSR1,char_O_deco_time_for_log ; load base address of deco stop times table |
354 movlw NUM_STOPS_LOG ; load size of deco stop times table | |
355 movwf lo ; copy size to loop counter | |
0 | 356 store_dive_decoplan_loop: |
623 | 357 movf POSTINC1,W ; get a stop time |
358 rcall ghostwrite_byte_profile ; store it | |
359 decfsz lo,F ; decrement loop counter, became zero? | |
360 bra store_dive_decoplan_loop ; NO - loop | |
628 | 361 movlw div_decoplan ; YES - get sampling rate |
623 | 362 movwf divisor_decoplan ; - reload timer |
363 return ; - done | |
364 | |
365 | |
366 IFDEF _external_sensor | |
0 | 367 store_dive_ppO2_sensors: |
623 | 368 movff sensor1_ppO2,WREG ; get sensor 1 ppO2 (in 0.01 bar steps) |
369 rcall ghostwrite_byte_profile ; store it | |
370 SMOVII sensor1_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo | |
371 movf lo,W ; in 0.1 mV steps, low byte | |
372 rcall ghostwrite_byte_profile ; store it | |
373 movf hi,W ; in 0.1 mV steps, high byte | |
374 rcall ghostwrite_byte_profile ; store it | |
0 | 375 |
623 | 376 movff sensor2_ppO2,WREG ; get sensor 2 ppO2 (in 0.01 bar steps) |
377 rcall ghostwrite_byte_profile ; store it | |
378 SMOVII sensor2_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo | |
379 movf lo,W ; in 0.1 mV steps, low byte | |
380 rcall ghostwrite_byte_profile ; store it | |
381 movf hi,W ; in 0.1 mV steps, high byte | |
382 rcall ghostwrite_byte_profile ; store it | |
0 | 383 |
623 | 384 movff sensor3_ppO2,WREG ; get sensor 3 ppO2 (in 0.01 bar steps) |
385 rcall ghostwrite_byte_profile ; store it | |
386 SMOVII sensor3_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor to hi:lo | |
387 movf lo,W ; in 0.1 mV steps, low byte | |
388 rcall ghostwrite_byte_profile ; store it | |
389 movf hi,W ; in 0.1 mV steps, high byte | |
390 rcall ghostwrite_byte_profile ; store it | |
0 | 391 |
628 | 392 movlw div_ppo2_sensors ; get sampling rate |
623 | 393 movwf divisor_ppo2_sensors ; reload timer |
0 | 394 return |
623 | 395 ENDIF |
396 | |
397 | |
398 store_dive_supersat: | |
399 movff int_O_lead_supersat+0,WREG ; get leading tissue's supersaturation (value is limited to 255, only lower byte is used for the value) | |
400 rcall ghostwrite_byte_profile ; store it | |
628 | 401 movlw div_gf ; get sampling rate |
623 | 402 movwf divisor_supersat ; reload timer |
0 | 403 return |
404 | |
405 store_dive_decodata: | |
582 | 406 ; Check if deco stops are necessary |
623 | 407 movff char_O_deco_depth,WREG ; get depth of the first stop |
408 tstfsz WREG ; depth of first stop > 0 m (aka in deco) ? | |
604 | 409 bra store_dive_decodata_deco ; YES |
582 | 410 ; NO - within NDL |
604 | 411 clrf WREG ; =0: no stop dive |
623 | 412 rcall ghostwrite_byte_profile ; store it |
413 movff char_O_NDL_norm,WREG ; get NDL time in normal plan | |
414 rcall ghostwrite_byte_profile ; store it | |
582 | 415 bra store_dive_decodata_common |
416 store_dive_decodata_deco: | |
417 ; YES - in deco | |
623 | 418 movff char_O_deco_depth,WREG ; get depth of the first stop in meters |
419 rcall ghostwrite_byte_profile ; store it | |
420 movff char_O_deco_time,WREG ; get time of the first stop in minutes | |
421 rcall ghostwrite_byte_profile ; store it | |
582 | 422 store_dive_decodata_common: |
628 | 423 movlw div_deco ; get sampling rate |
623 | 424 movwf divisor_deco ; reload timer |
0 | 425 return |
426 | |
427 store_dive_temperature: | |
623 | 428 SMOVII temperature_cur,mpr ; ISR-safe 2 byte copy of current temperature to hi:lo |
429 movf lo,W ; get low byte | |
430 rcall ghostwrite_byte_profile ; store it | |
431 movf hi,W ; get high byte | |
432 rcall ghostwrite_byte_profile ; store it | |
628 | 433 movlw div_temperature ; get sampling rate |
623 | 434 movwf divisor_temperature ; reload timer |
0 | 435 return |
436 | |
437 ghostwrite_byte_header: | |
604 | 438 goto write_byte_ext_flash_plus_header ; (this call will also delete the 4kB TOC entry first) |
582 | 439 ; returns... |
0 | 440 |
441 ghostwrite_byte_profile: | |
604 | 442 goto write_byte_ext_flash_plus ; writes byte and increases address with banking at 0x200000 |
582 | 443 ; returns... |
0 | 444 |
623 | 445 |
0 | 446 global ghostwriter_end_dive |
447 ghostwriter_end_dive: | |
623 | 448 ; save end-of-profile pointer to store in header |
0 | 449 movff ext_flash_address+0,ext_flash_log_pointer+0 |
450 movff ext_flash_address+1,ext_flash_log_pointer+1 | |
623 | 451 movff ext_flash_address+2,ext_flash_log_pointer+2 |
0 | 452 |
623 | 453 ; remember last custom view shown in dive mode |
454 movff active_customview,customview_divemode | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
35
diff
changeset
|
455 |
623 | 456 btfss divetime_longer_1min ; dive longer then one minute |
604 | 457 goto ghostwriter_end_dive_common ; NO - discard everything |
0 | 458 |
623 | 459 ; In DEBUG compile, write simulated dives to logbook |
460 ifndef _DEBUG | |
461 btfsc sensor_override_active ; are we in simulator mode? | |
462 goto ghostwriter_end_dive_common ; YES - discard everything | |
463 endif | |
0 | 464 |
623 | 465 btfss FLAG_apnoe_mode ; are we in apnoe mode? |
466 bra ghostwriter_end_dive_1 ; NO - proceed | |
467 TSTOSS opt_store_apnoe_dive ; YES - logging in apnoe mode enabled? | |
468 goto ghostwriter_end_dive_common ; NO - discard everything | |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
469 |
623 | 470 ghostwriter_end_dive_1: |
604 | 471 ; Dive finished (and longer than one minute) |
0 | 472 |
623 | 473 btfsc FLAG_apnoe_mode ; are we in apnoe mode? |
474 call apnoe_calc_maxdepth ; YES - calculate max. depth (again) for very short apnoe dives | |
0 | 475 |
623 | 476 movlw 0xFD ; coding for End-of-Profile, byte 1 |
477 rcall ghostwrite_byte_profile ; store it | |
478 movlw 0xFD ; coding for End-of-Profile, byte 2 | |
479 rcall ghostwrite_byte_profile ; store it | |
582 | 480 |
623 | 481 ; Save end-of-profile pointer to store in header |
0 | 482 movff ext_flash_address+0,ext_flash_log_pointer+0 |
483 movff ext_flash_address+1,ext_flash_log_pointer+1 | |
623 | 484 movff ext_flash_address+2,ext_flash_log_pointer+2 |
0 | 485 |
582 | 486 ; Set to first address again to store dive length ext_flash_dive_counter:3 |
604 | 487 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 |
0 | 488 |
604 | 489 incf_ext_flash_address_0x20 d'6' ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" Header |
582 | 490 ; Store dive length |
491 movf ext_flash_dive_counter+0,W | |
604 | 492 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 | 493 movf ext_flash_dive_counter+1,W |
604 | 494 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 | 495 movf ext_flash_dive_counter+2,W |
604 | 496 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 | 497 |
604 | 498 ; profile recording done |
0 | 499 |
500 ; Load total number of dives | |
501 read_int_eeprom .2 | |
502 movff EEDATA,lo | |
503 read_int_eeprom .3 | |
504 movff EEDATA,hi | |
623 | 505 |
506 INCI mpr ; increase total dive counter | |
507 | |
0 | 508 ; Store new number in EEPROM |
509 movff lo,EEDATA | |
582 | 510 write_int_eeprom .2 |
0 | 511 movff hi,EEDATA |
582 | 512 write_int_eeprom .3 |
0 | 513 |
582 | 514 decf lo,F ; -1 |
515 | |
0 | 516 ; Set ext_flash_address:3 to TOC entry of this dive |
517 ; 1st: 200000h-200FFFh -> lo=0 | |
518 ; 2nd: 201000h-201FFFh -> lo=1 | |
519 ; 3rd: 202000h-202FFFh -> lo=2 | |
520 ; 255: 2FF000h-2FFFFFh -> lo=255 | |
521 | |
522 clrf ext_flash_address+0 | |
523 clrf ext_flash_address+1 | |
524 movlw 0x20 | |
525 movwf ext_flash_address+2 | |
526 movlw .16 | |
582 | 527 mulwf lo ; lo*16 = offset to 0x2000 (up:hi) |
0 | 528 movf PRODL,W |
529 addwf ext_flash_address+1,F | |
530 movf PRODH,W | |
531 addwfc ext_flash_address+2,F | |
582 | 532 |
623 | 533 ; write header start code |
604 | 534 movlw 0xFA ; header start |
535 rcall ghostwrite_byte_header ; (this call will also delete the 4kB TOC entry first) | |
0 | 536 movlw 0xFA |
604 | 537 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 538 |
582 | 539 ; store pointer to begin of dive profile |
540 read_int_eeprom .4 | |
0 | 541 movf EEDATA,W |
604 | 542 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 543 read_int_eeprom .5 |
0 | 544 movf EEDATA,W |
604 | 545 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 546 read_int_eeprom .6 |
0 | 547 movf EEDATA,W |
604 | 548 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 549 |
582 | 550 ; store pointer to end of dive profile |
0 | 551 movf ext_flash_log_pointer+0,W |
604 | 552 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 553 movf ext_flash_log_pointer+1,W |
604 | 554 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 555 movf ext_flash_log_pointer+2,W |
604 | 556 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 557 |
623 | 558 ; write the remainder of the header |
604 | 559 movlw logbook_profile_version ; defined in hwos.inc |
560 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 561 |
623 | 562 ; store dive length |
582 | 563 movf ext_flash_dive_counter+0,W |
604 | 564 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 565 movf ext_flash_dive_counter+1,W |
604 | 566 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
582 | 567 movf ext_flash_dive_counter+2,W |
604 | 568 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 569 |
623 | 570 ; store start of time time & date |
604 | 571 lfsr FSR0,start_year ; load base address of start-of-dive data |
572 movf POSTINC0,W ; year | |
573 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
574 movf POSTINC0,W ; month | |
575 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
576 movf POSTINC0,W ; day | |
577 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
578 movf POSTINC0,W ; hour | |
579 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
580 movf POSTINC0,W ; minute | |
581 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 582 |
604 | 583 btfss FLAG_apnoe_mode ; store apnoe max or normal max (which is only max from the last descent) |
584 bra end_dive1 ; store normal depth | |
0 | 585 |
623 | 586 ; apnoe max depth |
587 MOVII apnoe_max_pressure,mpr | |
588 call adjust_depth_with_salinity ; compute salinity setting into hi:lo [mbar] | |
589 MOVII mpr,apnoe_max_pressure | |
590 bra end_dive2 ; store max depth | |
582 | 591 |
0 | 592 end_dive1: |
623 | 593 ; normal max depth |
594 MOVII pressure_rel_max_cached,mpr | |
595 call adjust_depth_with_salinity ; compute salinity setting into hi:lo [mbar] | |
596 MOVII mpr,pressure_rel_max_cached | |
582 | 597 |
623 | 598 end_dive2: |
599 ; store max depth (common part) | |
604 | 600 movf lo,W ; max. depth, low byte |
601 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
602 movf hi,W ; max. depth, high byte | |
603 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
0 | 604 |
623 | 605 ; store dive time |
606 SMOVTT counted_divetime_mins,mpr ; ISR-safe 3 byte copy of minutes:2 and seconds | |
607 movf mpr+0,W ; dive time minutes, low byte | |
604 | 608 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
623 | 609 movf mpr+1,W ; dive time minutes, high byte |
604 | 610 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
623 | 611 movf mpr+2,W ; dive time seconds |
604 | 612 rcall ghostwrite_byte_header ; WREG -> header in ext. flash |
0 | 613 |
623 | 614 ; store minimum temperature |
615 movff temperature_min+0,WREG ; minimum temperature, low byte | |
616 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
617 movff temperature_min+1,WREG ; minimum temperature, high byte | |
618 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
619 | |
620 ; store surface pressure (as used by deco engine) | |
621 movff int_I_pres_surface+0,WREG ; surface pressure, low byte | |
622 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
623 movff int_I_pres_surface+1,WREG ; surface pressure, high byte | |
624 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
625 | |
626 ; store desaturation time | |
627 movff int_O_desaturation_time+0,WREG ; desaturation time in minutes, low byte | |
628 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
629 movff int_O_desaturation_time+1,WREG ; desaturation time in minutes, high byte | |
630 rcall ghostwrite_byte_header ; WREG -> header in ext. flash | |
631 | |
632 IFDEF _ccr_pscr | |
604 | 633 btfsc FLAG_ccr_mode ; in CCR mode? |
634 bra end_dive_dil_gaslist ; YES - write diluent gas list | |
635 btfsc FLAG_pscr_mode ; in pSCR mode? | |
636 bra end_dive_dil_gaslist ; YES - write diluent gas list | |
623 | 637 ENDIF |
0 | 638 |
604 | 639 end_dive_oc_gaslist: ; write OC gases |
640 lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement | |
641 bra end_dive_gaslist ; write all 5 OC gases | |
0 | 642 |
623 | 643 IFDEF _ccr_pscr |
604 | 644 end_dive_dil_gaslist: ; write diluents |
645 lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement | |
646 ;bra end_dive_gaslist ; write all 5 diluents | |
623 | 647 ENDIF |
0 | 648 |
604 | 649 end_dive_gaslist: ; helper function for writing gas list entries |
650 ; | |
651 ; Memory Map: | |
652 ; ------------------------- | |
653 ; opt_gas_O2_ratio res 5 | |
654 ; opt_dil_O2_ratio res 5 | |
655 ; opt_gas_He_ratio res 5 | |
656 ; opt_dil_He_ratio res 5 | |
657 ; opt_gas_type res 5 | |
658 ; opt_dil_type res 5 | |
659 ; opt_gas_change res 5 | |
660 ; opt_dil_change res 5 | |
661 ; | |
662 movlw .5 ; 5 gases to store | |
663 movwf lo ; use lo as counter | |
664 end_dive_gaslist_loop: | |
665 movf PREINC0,W ; increment base address and get O2 ratio into WREG | |
666 rcall ghostwrite_byte_header ; store data | |
667 movlw .10 ; offset for H2 ratios | |
668 movf PLUSW0,W ; get H2 ratio into WREG | |
669 rcall ghostwrite_byte_header ; store data | |
670 movlw .30 ; offset for change depths | |
671 movf PLUSW0,W ; get change depth into WREG | |
672 rcall ghostwrite_byte_header ; store data | |
673 movlw .20 ; offset for types | |
674 movf PLUSW0,W ; get type into WREG | |
675 rcall ghostwrite_byte_header ; store data | |
676 decfsz lo ; decrement counter, did it became 0 ? | |
677 bra end_dive_gaslist_loop ; NO - loop | |
678 ;bra end_dive_oc_cc_common ; YES - done | |
0 | 679 |
680 end_dive_oc_cc_common: | |
623 | 681 movlw softwareversion_x ; get firmware version X (major) |
682 rcall ghostwrite_byte_header ; store data | |
683 movlw softwareversion_y ; get firmware version Y (minor) | |
684 rcall ghostwrite_byte_header ; store data | |
0 | 685 |
623 | 686 ; store battery voltage |
687 movf batt_voltage+0,W ; get battery voltage, low byte | |
688 rcall ghostwrite_byte_header ; store data | |
689 movf batt_voltage+1,W ; get battery voltage, high byte | |
690 rcall ghostwrite_byte_header ; store data | |
691 | |
692 ; store sampling rate | |
693 movf sampling_rate,W ; get sampling rate | |
694 rcall ghostwrite_byte_header ; store data | |
695 | |
696 ; store CNS at beginning of dive | |
697 movf CNS_start+0,W ; get CNS at start of dive, low byte | |
698 rcall ghostwrite_byte_header ; store data | |
699 movf CNS_start+1,W ; get CNS at start of dive, high byte | |
700 rcall ghostwrite_byte_header ; store data | |
0 | 701 |
623 | 702 ; store gradient factors |
703 movff supersat_start,WREG ; get supersaturation at start of dive | |
704 rcall ghostwrite_byte_header ; store data | |
705 movff int_O_lead_supersat+0,WREG ; get supersaturation at end of dive | |
706 rcall ghostwrite_byte_header ; store data | |
5 | 707 |
623 | 708 ; store logbook offset |
709 call do_logoffset_common_read ; read into mpr:2 | |
710 movf mpr+0,W | |
711 rcall ghostwrite_byte_header ; store data | |
712 movf mpr+1,W | |
713 rcall ghostwrite_byte_header ; store data | |
5 | 714 |
623 | 715 ; store battery info at Byte 59 |
716 movf batt_percent,W ; 0-100% | |
717 rcall ghostwrite_byte_header ; store data | |
604 | 718 |
623 | 719 ; store setpoints |
720 IFDEF _ccr_pscr | |
721 lfsr FSR0,opt_setpoint_cbar ; base address of ppO2 values | |
722 lfsr FSR1,opt_setpoint_change ; base address of change depths | |
723 ENDIF | |
724 movlw .5 ; 5 setpoints to be stored | |
604 | 725 movwf lo ; use lo as counter |
726 end_dive_sp_loop: | |
623 | 727 IFDEF _ccr_pscr |
728 movf POSTINC0,W ; get ppO2 value | |
729 ELSE | |
730 clrf WREG | |
731 ENDIF | |
732 rcall ghostwrite_byte_header ; store data | |
733 IFDEF _ccr_pscr | |
734 movf POSTINC1,W ; get change depth | |
735 ELSE | |
736 clrf WREG | |
737 ENDIF | |
738 rcall ghostwrite_byte_header ; store data | |
604 | 739 decfsz lo ; decrement counter, did it became 0 ? |
740 bra end_dive_sp_loop ; NO - loop | |
0 | 741 |
623 | 742 ; store salinity |
743 movff opt_salinity,WREG ; get salinity (0-4%) | |
744 rcall ghostwrite_byte_header ; store data | |
0 | 745 |
623 | 746 ; store CNS at end of dive |
747 movff int_O_CNS_current+0,WREG ; get current CNS, low byte | |
748 rcall ghostwrite_byte_header ; store data | |
749 movff int_O_CNS_current+1,WREG ; get current CNS, high byte | |
604 | 750 bcf WREG,int_warning_flag ; clear warning flag |
751 bcf WREG,int_attention_flag ; clear attention flag | |
623 | 752 rcall ghostwrite_byte_header ; store data |
0 | 753 |
623 | 754 ; store average depth |
755 movff pressure_rel_avg_total+0,WREG ; get total dive average depth, low byte | |
756 rcall ghostwrite_byte_header ; store data | |
757 movff pressure_rel_avg_total+1,WREG ; get total dive average depth, high byte | |
758 rcall ghostwrite_byte_header ; store data | |
604 | 759 |
623 | 760 ; store total dive time |
761 SMOVII total_divetime_secs,mpr ; ISR-safe 2 byte copy of the total dive time | |
762 movff mpr+0,WREG ; total dive time, low byte | |
763 rcall ghostwrite_byte_header ; store data | |
764 movff mpr+1,WREG ; total dive time, high byte | |
765 rcall ghostwrite_byte_header ; store data | |
0 | 766 |
623 | 767 ; store GF low or saturation multiplier |
768 movff char_I_GF_Low_percentage,WREG ; get GF_lo | |
769 movff char_I_deco_model,lo | |
770 decfsz lo,F ; skip next line if char_I_deco_model == 1 | |
771 movff char_I_saturation_multiplier,WREG ; get saturation multiplier | |
772 rcall ghostwrite_byte_header ; store data | |
773 | |
774 ; store GF high or desaturation multiplier | |
775 movff char_I_GF_High_percentage,WREG ; get GF_hi | |
0 | 776 movff char_I_deco_model,lo |
777 decfsz lo,F ; jump over next line if char_I_deco_model == 1 | |
623 | 778 movff char_I_desaturation_multiplier,WREG ; get desaturation multiplier |
779 rcall ghostwrite_byte_header ; store data | |
0 | 780 |
623 | 781 ; store deco model |
782 movff char_I_deco_model,WREG ; get deco model (0 = ZH-L16, 1 = ZH-L16-GF) | |
783 rcall ghostwrite_byte_header ; store data | |
0 | 784 |
623 | 785 ; store total dive number |
786 read_int_eeprom .2 ; get total dive counter, low | |
787 movf EEDATA,W ; ... | |
788 rcall ghostwrite_byte_header ; store data | |
789 read_int_eeprom .3 ; get total dive counter, high | |
790 movf EEDATA,W ; ... | |
791 rcall ghostwrite_byte_header ; store data | |
0 | 792 |
623 | 793 ; store deco mode |
794 movff opt_dive_mode,WREG ; get deco mode (0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR) | |
795 rcall ghostwrite_byte_header ; store data | |
0 | 796 |
623 | 797 ; store tissue data - N2 chars |
582 | 798 movlw .16 |
799 movwf lo | |
623 | 800 lfsr FSR1,char_O_tissue_pres_N2 |
0 | 801 end_dive_store_tissues_N2: |
582 | 802 movf POSTINC1,W |
623 | 803 bcf WREG,7 ; clear flag bit for on-gassing/off-gassing |
804 rcall ghostwrite_byte_header ; store data | |
582 | 805 decfsz lo,F |
604 | 806 bra end_dive_store_tissues_N2 ; NO |
0 | 807 |
623 | 808 ; store tissue data - N2 floats |
582 | 809 movlw .64 |
810 movwf lo | |
604 | 811 lfsr FSR1,0x700 ; pres_tissue_N2+0 ; 16*4 Byte Float = 64 Bytes |
0 | 812 end_dive_store_tissues_N2_2: |
582 | 813 movf POSTINC1,W |
623 | 814 rcall ghostwrite_byte_header ; store data |
582 | 815 decfsz lo,F |
604 | 816 bra end_dive_store_tissues_N2_2 ; NO |
0 | 817 |
623 | 818 ; store tissue data - He chars |
582 | 819 movlw .16 |
820 movwf lo | |
623 | 821 lfsr FSR1,char_O_tissue_pres_He |
0 | 822 end_dive_store_tissues_He: |
582 | 823 movf POSTINC1,W |
623 | 824 bcf WREG,7 ; clear flag bit for on-gassing/off-gassing |
825 rcall ghostwrite_byte_header ; store data | |
582 | 826 decfsz lo,F |
604 | 827 bra end_dive_store_tissues_He ; NO |
0 | 828 |
623 | 829 ; store tissue data - He floats |
582 | 830 movlw .64 |
831 movwf lo | |
604 | 832 lfsr FSR1,0x740 ; pres_tissue_He+0 ; 16*4 Byte Float = 64 Bytes |
0 | 833 end_dive_store_tissues_He_2: |
582 | 834 movf POSTINC1,W |
623 | 835 rcall ghostwrite_byte_header ; store data |
582 | 836 decfsz lo,F |
604 | 837 bra end_dive_store_tissues_He_2 ; NO |
0 | 838 |
623 | 839 ; store last stop depth |
840 movff char_I_depth_last_deco,WREG ; get last stop depth [m] | |
841 rcall ghostwrite_byte_header ; store data | |
0 | 842 |
623 | 843 ; store deco distance |
628 | 844 clrf WREG ; assumed deco distance - disposed, hard-coded to zero |
623 | 845 rcall ghostwrite_byte_header ; store data |
0 | 846 |
623 | 847 IFDEF _external_sensor |
848 ; store last HUD data | |
849 SMOVTT hud_status_byte,mpr ; ISR-safe 3 byte copy of last HUD status (1 byte) and battery voltage (2 byte) | |
850 movff mpr+1,WREG ; HUD battery value, low byte | |
851 rcall ghostwrite_byte_header ; store data | |
852 movff mpr+2,WREG ; HUD battery value, high byte | |
853 rcall ghostwrite_byte_header ; store data | |
854 movff mpr+0,WREG ; HUD status | |
855 rcall ghostwrite_byte_header ; store data | |
856 ELSE | |
857 ; store dummy data to keep format | |
858 clrf WREG | |
859 rcall ghostwrite_byte_header ; store null byte | |
860 clrf WREG | |
861 rcall ghostwrite_byte_header ; store null byte | |
862 clrf WREG | |
863 rcall ghostwrite_byte_header ; store null byte | |
864 ENDIF | |
0 | 865 |
623 | 866 ; store battery gauge registers [nAs] |
867 SMOVSS battery_gauge,mpr ; ISR-safe 6 byte copy of battery gauge value | |
868 movf mpr+0,W ; get byte 0 | |
869 rcall ghostwrite_byte_header ; store data | |
870 movf mpr+1,W ; get byte 1 | |
871 rcall ghostwrite_byte_header ; store data | |
872 movf mpr+2,W ; get byte 2 | |
873 rcall ghostwrite_byte_header ; store data | |
874 movf mpr+3,W ; get byte 3 | |
875 rcall ghostwrite_byte_header ; store data | |
876 movf mpr+4,W ; get byte 4 | |
877 rcall ghostwrite_byte_header ; store data | |
878 movf mpr+5,W ; get byte 5 | |
879 rcall ghostwrite_byte_header ; store data | |
880 | |
881 ; write header stop code | |
0 | 882 movlw 0xFB |
623 | 883 rcall ghostwrite_byte_header ; store data |
0 | 884 movlw 0xFB |
623 | 885 rcall ghostwrite_byte_header ; store data |
582 | 886 |
604 | 887 call divemode_store_statistics ; store/update statistics for this unit |
623 | 888 bsf reset_surface_interval ; request ISR to reset the surface interval timer |
0 | 889 |
890 ghostwriter_end_dive_common: | |
891 ; Update ext_flash_log_pointer into EEPROM | |
892 clrf EEADRH | |
893 movff ext_flash_log_pointer+0,EEDATA | |
894 write_int_eeprom .4 | |
895 movff ext_flash_log_pointer+1,EEDATA | |
896 write_int_eeprom .5 | |
897 movff ext_flash_log_pointer+2,EEDATA | |
898 write_int_eeprom .6 | |
899 | |
623 | 900 ; In DEBUG compile, write simulated dives to logbook and keep tissue pressures from simulation |
901 btfss simulatormode ; in simulator mode, i.e. need to restore tissue pressures? | |
902 bra ghostwriter_end_dive_common_1 ; NO | |
903 bcf simulatormode ; YES - clear mode flag | |
904 ifndef _DEBUG | |
905 call deco_pull_tissues_from_vault ; - restore tissue pressures (C-code) | |
906 banksel common ; - back to bank common | |
907 endif | |
604 | 908 |
623 | 909 ghostwriter_end_dive_common_1: |
910 bsf reset_timebase ; request ISR to reset the timebase | |
911 ; btfsc reset_timebase ; has the ISR confirmed reset of timebase? | |
912 ; bra $-2 ; NO - not yet, loop waiting for the ISR | |
913 bcf sensor_override_request ; request ISR to terminate the simulator mode | |
914 btfsc sensor_override_active ; has the ISR confirmed termination of simulator mode? | |
915 bra $-2 ; NO - not yet, loop waiting for the ISR | |
916 call update_battery_registers ; update battery registers into EEPROM | |
917 movff simulator_time,char_I_dive_interval ; get the simulator runtime, reads 0 if exiting from a real dive | |
918 call deco_calc_dive_interval ; catch up with tissue desaturation when exiting from simulator, | |
919 ; else calculates for 2 seconds only when exiting from a real dive, | |
920 ; needed to update CNS, GF and tissue graphics for surface display (C-code) | |
921 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up (C-code) | |
922 banksel common ; back to bank common | |
923 | |
924 ; the last surface pressure sample may have been taken while being submerged a bit already, | |
925 ; therefore it will be replaced by the sample taken one more before, which is the one that | |
926 ; became the surface pressure reference used while this dive. | |
927 MOVII pressure_abs_ref,pressure_abs_sampled | |
928 | |
929 goto surfloop ; done with post-dive operations, return to surface loop | |
166
30ebaf72170d
BUGFIX: Flip compass with flipped screen, too
heinrichsweikamp
parents:
147
diff
changeset
|
930 |
604 | 931 |
932 ghostwriter_load_pointer: ; load ext_flash_address:3 from EEPROM .4-.6 | |
933 clrf EEADRH ; make sure to select EEPROM bank 0 | |
0 | 934 read_int_eeprom .4 |
935 movff EEDATA,ext_flash_address+0 | |
936 read_int_eeprom .5 | |
937 movff EEDATA,ext_flash_address+1 | |
938 read_int_eeprom .6 | |
939 movff EEDATA,ext_flash_address+2 | |
582 | 940 return |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
941 |
604 | 942 ghostwriter_short_header_init: ; proceed one page forward |
582 | 943 clrf EEDATA |
604 | 944 write_int_eeprom .4 ; ext_flash_address+0 = 0 |
582 | 945 movlw .16 |
946 addwf ext_flash_address+1,F | |
947 movlw .0 | |
948 addwfc ext_flash_address+2,F | |
949 movlw 0x20 | |
604 | 950 cpfseq ext_flash_address+2 ; at address 0x200000? |
951 bra ghostwriter_short_header_init2 ; NO | |
952 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
|
953 ghostwriter_short_header_init2: |
582 | 954 movlw 0xF0 |
604 | 955 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
|
956 |
582 | 957 movff ext_flash_address+1,EEDATA |
604 | 958 write_int_eeprom .5 ; write new pointer |
582 | 959 movff ext_flash_address+2,EEDATA |
604 | 960 write_int_eeprom .6 ; write new pointer |
961 bra ghostwriter_short_header2 ; Done | |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
962 |
623 | 963 |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
964 global ghostwriter_short_header |
604 | 965 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
|
966 ; load pointer for profile storing into RAM (Updated in EEPROM after the dive) |
604 | 967 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
|
968 |
582 | 969 ; The following code is used to write a clean new dive after the previous hasn't been |
970 ; stored correctly. e.g. after a battery fail during the dive | |
604 | 971 call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw |
582 | 972 incfsz ext_flash_rw,F |
604 | 973 bra ghostwriter_short_header_init ; not 0xFF -> init page |
974 call ext_flash_byte_read_plus_0x20 ; into ext_flash_rw | |
582 | 975 incfsz ext_flash_rw,F |
604 | 976 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
|
977 |
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
978 ghostwriter_short_header2: |
582 | 979 ; All ok, reload the pointer and start |
604 | 980 rcall ghostwriter_load_pointer ; load ext_flash_address:3 from EEPROM .4-.6 |
0 | 981 |
582 | 982 ; Clear dive length counter |
983 clrf ext_flash_dive_counter+0 | |
984 clrf ext_flash_dive_counter+1 | |
985 clrf ext_flash_dive_counter+2 | |
0 | 986 |
582 | 987 ; Write short header with dive number into profile memory |
0 | 988 movlw 0xFA |
604 | 989 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 990 movlw 0xFA |
604 | 991 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 992 ; Load total number of dives (low byte only) |
993 read_int_eeprom .2 | |
604 | 994 incf EEDATA,W ; +1 |
995 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
0 | 996 read_int_eeprom .3 |
997 movf EEDATA,W | |
604 | 998 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 999 movlw 0xFA |
604 | 1000 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1001 movlw 0xFA |
604 | 1002 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
|
1003 |
628 | 1004 ; Keep room for dive length ext_flash_dive_counter:3 (stored at the end of the dive) |
582 | 1005 ; Writing 0xFF three times here is mandatory |
1006 ; - 0xFF can be overwritten after the dive | |
628 | 1007 ; - ghostwrite_byte_profile takes care of 4kB page switching |
582 | 1008 ; - 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
|
1009 |
582 | 1010 movlw 0xFF |
604 | 1011 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
582 | 1012 movlw 0xFF |
604 | 1013 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
582 | 1014 movlw 0xFF |
604 | 1015 call write_byte_ext_flash_plus_nocnt ; WREG -> profile in ext. flash (No ext_flash_dive_counter:3 increase) |
0 | 1016 |
628 | 1017 ; store sizes and sampling rates of recording datasets |
0 | 1018 |
628 | 1019 movf sampling_rate,W ; get general sampling rate |
604 | 1020 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1021 |
628 | 1022 movlw .7 ; get number of additional datasets |
604 | 1023 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1024 |
628 | 1025 movlw .0 ; type: temperature |
604 | 1026 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1027 movlw infolength_temperature ; get size of recording data |
604 | 1028 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1029 movlw div_temperature ; get sampling rate |
604 | 1030 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1031 |
628 | 1032 movlw .1 ; type: +++ |
1033 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
1034 movlw infolength_deco ; get size of recording data | |
1035 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
1036 movlw div_deco ; get sampling rate | |
604 | 1037 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1038 |
1039 movlw .2 ; type: saturation | |
604 | 1040 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1041 movlw infolength_gf ; get size of recording data |
1042 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
1043 movlw div_gf ; get sampling rate | |
604 | 1044 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1045 |
628 | 1046 movlw .3 ; type: ppO2 sensor data |
604 | 1047 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1048 movlw infolength_ppo2_sensors ; get size of recording data |
604 | 1049 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1050 movlw .0 ; default to no ppO2 data |
1051 btfsc FLAG_ccr_mode ; in CCR mode? | |
1052 movlw div_ppo2_sensors ; YES - get sampling rate | |
1053 btfsc FLAG_pscr_mode ; in pSCR mode? | |
1054 movlw div_ppo2_sensors ; YES - get sampling rate | |
604 | 1055 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1056 |
628 | 1057 movlw .4 ; type: deco plan (stop times) |
604 | 1058 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1059 movlw infolength_decoplan ; get size of recording data |
604 | 1060 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1061 movlw div_decoplan ; get sampling rate |
604 | 1062 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1063 |
628 | 1064 movlw .5 ; type: CNS |
604 | 1065 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1066 movlw infolength_cns ; get size of recording data |
604 | 1067 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1068 movlw div_cns ; get sampling rate |
604 | 1069 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1070 |
628 | 1071 movlw .6 ; type: tank pressure |
1072 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash | |
1073 movlw infolength_tank ; get size of recording data | |
604 | 1074 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
628 | 1075 movlw .0 ; default to no tank pressure data |
1076 btfsc tr_functions_activated ; TR functions activated? | |
1077 movlw div_tank ; YES - get sampling rate | |
604 | 1078 rcall ghostwrite_byte_profile ; WREG -> profile in ext. flash |
0 | 1079 |
1080 return | |
582 | 1081 |
628 | 1082 |
604 | 1083 divemode_store_statistics: ; store/update statistics for this unit |
582 | 1084 call vault_decodata_into_eeprom ; update deco data |
623 | 1085 call do_logoffset_common_read ; read current logbook offset into mpr |
582 | 1086 |
623 | 1087 tstfsz lo ; offset, low byte = 0 ? |
604 | 1088 bra change_logbook_offset1 ; NO - adjust offset |
623 | 1089 tstfsz hi ; offset, high byte = 0 ? |
604 | 1090 bra change_logbook_offset1 ; NO - adjust offset |
623 | 1091 bra change_logbook_offset2 ; YES to both - skip offset routine |
582 | 1092 |
0 | 1093 change_logbook_offset1: |
623 | 1094 INCI mpr ; increment offset |
1095 call do_logoffset_common_write ; write incremented offset as the new offset | |
582 | 1096 |
0 | 1097 change_logbook_offset2: |
623 | 1098 ; ISR-safe 3 byte copy of minutes:2 and seconds to last dive duration |
1099 SMOVTT counted_divetime_mins,lastdive_duration | |
1100 | |
1101 ; 2 byte copies of max and avg relative pressures to last dive data | |
1102 MOVII pressure_rel_max_cached,lastdive_maxdepth | |
1103 MOVII pressure_rel_avg_total, lastdive_avgdepth | |
1104 | |
0 | 1105 return |
1106 | |
582 | 1107 END |