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