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