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