Mercurial > public > hwos_code
annotate src/ghostwriter.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 75e90cd0c2c3 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File ghostwriter.asm * combined next generation V3.09.4k |
0 | 4 ; |
5 ; Ghostwriter (Log profile recorder) | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-11-27 : [mH] Creation | |
11 | |
582 | 12 #include "hwos.inc" ; Mandatory header |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
14 #include "external_flash.inc" | |
15 #include "surfmode.inc" | |
16 #include "eeprom_rs232.inc" | |
17 #include "strings.inc" | |
18 #include "tft_outputs.inc" | |
19 #include "divemode.inc" | |
20 #include "rtc.inc" | |
631 | 21 #include "logbook.inc" |
634 | 22 #include "convert.inc" |
582 | 23 |
623 | 24 |
604 | 25 extern deco_pull_tissues_from_vault |
26 | |
582 | 27 |
634 | 28 ;----------------------------------------------------------------------------- |
29 ; Macros - write PROFILE Data to FLASH (all macros are bank-safe) | |
631 | 30 |
31 FLASH_LIT_PROFILE macro literal ; write 1 byte LITERAL to FLASH profile data | |
32 movlw literal | |
33 rcall ghostwrite_WREG_profile_exec | |
34 endm | |
35 | |
36 FLASH_WREG_PROFILE macro ; write 1 byte from WREG to FLASH profile data | |
37 rcall ghostwrite_WREG_profile_exec | |
38 endm | |
39 | |
40 FLASH_CC_PROFILE macro memory_address ; write 1 byte from memory to FLASH profile data | |
41 MOVCC memory_address,WREG | |
42 rcall ghostwrite_WREG_profile_exec | |
43 endm | |
44 | |
45 FLASH_II_PROFILE macro memory_address ; write 2 byte from memory to FLASH profile data | |
46 lfsr FSR0,memory_address | |
47 rcall ghostwrite_II_profile_exec | |
48 endm | |
49 | |
50 | |
634 | 51 ;----------------------------------------------------------------------------- |
631 | 52 ; private local Variables |
582 | 53 |
604 | 54 CBLOCK local3 ; max size is 16 Byte !!! |
582 | 55 divisor_temperature ; divisor used to time the sampling of dive data |
56 divisor_deco ; divisor used to time the sampling of dive data | |
623 | 57 divisor_supersat ; divisor used to time the sampling of dive data |
582 | 58 divisor_ppo2_sensors ; divisor used to time the sampling of dive data |
59 divisor_decoplan ; divisor used to time the sampling of dive data | |
60 divisor_cns ; divisor used to time the sampling of dive data | |
61 divisor_tank ; divisor used to time the sampling of dive data | |
62 ProfileFlagByte ; used to store events | |
63 ENDC ; used: 8 byte, remaining: 8 byte | |
64 | |
65 | |
634 | 66 ;============================================================================= |
67 ghostwrite1 CODE | |
582 | 68 ;============================================================================= |
69 | |
634 | 70 ;----------------------------------------------------------------------------- |
71 ; prepare Data Recording | |
72 ; | |
604 | 73 global init_recording_params ; initialize profile recording parameters |
582 | 74 init_recording_params: |
623 | 75 movlw div_temperature ; get divisor for temperature storage |
76 movwf divisor_temperature ; initialize divisor | |
77 | |
631 | 78 movlw div_deco ; get divisor for deco status |
79 movwf divisor_deco ; initialize divisor | |
623 | 80 |
631 | 81 movlw div_gf ; get divisor for saturation |
82 movwf divisor_supersat ; initialize divisor | |
623 | 83 |
631 | 84 movlw div_decoplan ; get divisor for deco plan |
85 movwf divisor_decoplan ; initialize divisor | |
623 | 86 |
631 | 87 movlw div_cns ; get divisor for CNS |
88 movwf divisor_cns ; initialize divisor | |
623 | 89 |
628 | 90 IFDEF _rx_functions |
91 clrf WREG ; default to no tank data logging | |
92 btfsc tr_functions_activated ; TR functions activated? | |
93 movlw div_tank ; YES - get divisor for tank data | |
94 movwf divisor_tank ; initialize divisor | |
95 ENDIF | |
623 | 96 |
97 IFDEF _external_sensor | |
631 | 98 movlw div_ppo2_sensors ; get divisor for ppO2 sensor |
99 movwf divisor_ppo2_sensors ; initialize divisor by default | |
582 | 100 btfsc FLAG_ccr_mode ; in CCR mode? |
631 | 101 bra init_recording_params_2 ; YES - keep divisor |
102 btfsc FLAG_pscr_mode ; NO - in pSCR mode? | |
103 bra init_recording_params_2 ; YES - keep divisor | |
104 clrf divisor_ppo2_sensors ; NO - clear divisor again | |
623 | 105 ENDIF |
106 | |
582 | 107 init_recording_params_2: |
108 return | |
109 | |
0 | 110 |
634 | 111 ;============================================================================= |
112 ghostwrite2 CODE | |
113 ;============================================================================= | |
114 | |
115 ;----------------------------------------------------------------------------- | |
116 ; sample and store a Set of Dive Data | |
117 ; | |
0 | 118 global store_dive_data |
560 | 119 store_dive_data: |
623 | 120 bcf trigger_sample_divedata ; clear flag |
0 | 121 |
623 | 122 ifndef _DEBUG |
631 | 123 ; In DEBUG compile, write simulated dives to logbook |
623 | 124 btfsc sensor_override_active ; in simulator mode? |
125 return ; YES - no dive data stored in simulator mode | |
126 endif | |
0 | 127 |
623 | 128 btfss FLAG_apnoe_mode ; in apnoe mode? |
129 bra store_dive_data_1 ; NO - proceed | |
631 | 130 TSTOSS opt_store_apnoe ; YES - logging in apnoe mode enabled? |
623 | 131 return ; NO - done |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
132 |
623 | 133 store_dive_data_1: |
631 | 134 ; store depth with every sample |
135 MOVII pressure_rel_cur_cached,mpr ; copy current relative pressure to MPR | |
136 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
137 FLASH_II_PROFILE mpr ; store depth | |
0 | 138 |
631 | 139 ; first, find out how many bytes will be appended to this sample set |
140 clrf ProfileFlagByte ; start with no bytes to append | |
0 | 141 |
631 | 142 ; check extended information |
623 | 143 decfsz divisor_temperature,W ; check divisor if it will become 0, dump decremented value to WREG |
144 bra check_extended1 ; NO - skip | |
145 movlw infolength_temperature ; YES - get length of extra data | |
146 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 147 check_extended1: |
623 | 148 decfsz divisor_deco,W ; check divisor if it will become 0, dump decremented value to WREG |
149 bra check_extended2 ; NO - skip | |
150 movlw infolength_deco ; YES - get length of extra data | |
151 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 152 check_extended2: |
623 | 153 decfsz divisor_supersat,W ; check divisor if it will become 0, dump decremented value to WREG |
154 bra check_extended3 ; NO - skip | |
155 movlw infolength_gf ; YES - get length of extra data | |
634 | 156 addwf ProfileFlagByte,F ; - add to ProfileFlagByte |
0 | 157 check_extended3: |
623 | 158 IFDEF _external_sensor |
159 decfsz divisor_ppo2_sensors,W ; check divisor if it will become 0, dump decremented value to WREG | |
160 bra check_extended4 ; NO - skip | |
161 movlw infolength_ppo2_sensors ; YES - get length of extra data | |
162 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
163 ENDIF | |
0 | 164 check_extended4: |
623 | 165 decfsz divisor_decoplan,W ; check divisor if it will become 0, dump decremented value to WREG |
166 bra check_extended5 ; NO - skip | |
167 movlw infolength_decoplan ; YES - get length of extra data | |
168 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 169 check_extended5: |
623 | 170 decfsz divisor_cns,W ; check divisor if it will become 0, dump decremented value to WREG |
171 bra check_extended6 ; NO - skip | |
172 movlw infolength_cns ; YES - get length of extra data | |
173 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
0 | 174 check_extended6: |
628 | 175 IFDEF _rx_functions |
623 | 176 decfsz divisor_tank,W ; check divisor if it will become 0, dump decremented value to WREG |
177 bra check_extended7 ; NO - skip | |
178 movlw infolength_tank ; YES - get length of extra data | |
179 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
628 | 180 ENDIF |
631 | 181 |
0 | 182 check_extended7: |
631 | 183 ; second, check global event flag |
604 | 184 btfss event_occured ; check global event flag |
185 bra store_dive_data3 ; no event | |
99
87cc1adfe4da
show event "bailout" in the internal logbook
heinrichsweikamp
parents:
98
diff
changeset
|
186 |
623 | 187 incf ProfileFlagByte,F ; add one byte (the event byte 1) |
0 | 188 |
623 | 189 clrf event_byte1 ; reset event byte 1 |
190 clrf event_byte2 ; reset event byte 2 | |
0 | 191 |
623 | 192 movf alarm_type,W ; type of alarm Bit 0-3 |
193 addwf event_byte1,F ; copy to event byte 1, bit 0-3 | |
194 clrf alarm_type ; reset alarm type | |
582 | 195 |
631 | 196 ; third, check events and add additional bytes |
623 | 197 btfss event_gas_change_gas6 ; did a change to gas 6 occur? |
198 bra check_event2 ; NO | |
199 movlw d'2' ; YES - set information length | |
200 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
201 bsf event_byte1,4 ; - set flag in event byte 1 | |
0 | 202 check_event2: |
623 | 203 btfss event_gas_change ; did a gas change occur? |
204 bra check_event3 ; NO | |
205 movlw d'1' ; YES - set information length | |
206 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
207 bsf event_byte1,5 ; - set flag in event byte 1 | |
0 | 208 check_event3: |
623 | 209 IFDEF _ccr_pscr |
210 btfss event_SP_change ; did a setpoint change occur? | |
211 bra check_event4 ; NO | |
212 movlw d'1' ; YES - set information length | |
213 addwf ProfileFlagByte,F ; - add to ProfileFlagByte | |
214 bsf event_byte1,6 ; - set flag in event byte 1 | |
215 ENDIF | |
0 | 216 check_event4: |
623 | 217 IFDEF _ccr_pscr |
218 btfss event_bailout ; did a gas change due to bailout occur? | |
582 | 219 bra check_event5 |
604 | 220 movlw d'2' ; information length |
582 | 221 addwf ProfileFlagByte,F ; add to ProfileFlagByte |
623 | 222 bsf event_byte2,0 ; set flag in event byte 2 |
223 bsf event_byte1,7 ; =1: another event byte is available | |
224 ENDIF | |
98 | 225 |
226 check_event5: | |
631 | 227 ; more events in future time... |
0 | 228 |
229 store_dive_data3: | |
631 | 230 btfsc event_byte1,7 ; is another event byte available? |
231 incf ProfileFlagByte,F ; YES - add one byte (the event byte 2) | |
98 | 232 |
631 | 233 btfsc event_occured ; global event flag set? |
234 bsf ProfileFlagByte,7 ; YES - set event byte 1 flag in ProfileFlagByte | |
98 | 235 |
631 | 236 FLASH_CC_PROFILE ProfileFlagByte ; store ProfileFlagByte |
98 | 237 |
631 | 238 btfss event_occured ; global event flag set? |
634 | 239 bra store_dive_data4 ; NO - no events to store |
631 | 240 |
241 ; store the EventByte(s) + additional bytes now | |
242 FLASH_CC_PROFILE event_byte1 ; store 1st event byte | |
98 | 243 |
631 | 244 btfss event_byte1,7 ; another event byte available? |
245 bra store_dive_data3a ; NO - skip | |
246 FLASH_CC_PROFILE event_byte2 ; YES - store 2nd event byte | |
0 | 247 |
631 | 248 store_dive_data3a: |
623 | 249 btfss event_gas_change_gas6 ; did a change to gas 6 occur? |
631 | 250 bra store_dive_data3b ; NO - skip |
251 FLASH_CC_PROFILE char_I_O2_ratio ; YES - store gas 6 O2 ratio | |
623 | 252 IFDEF _helium |
631 | 253 FLASH_CC_PROFILE char_I_He_ratio ; - store gas 6 He ratio |
623 | 254 ELSE |
631 | 255 FLASH_LIT_PROFILE .0 ; - store He ratio as zero |
623 | 256 ENDIF |
257 bcf event_gas_change_gas6 ; - clear event flag | |
628 | 258 |
0 | 259 store_dive_data3b: |
623 | 260 btfss event_gas_change ; did a gas change occur? |
631 | 261 bra store_dive_data3c ; NO - skip |
623 | 262 IFDEF _ccr_pscr |
628 | 263 movf active_dil,W ; YES - get active diluent by default |
623 | 264 btfsc FLAG_oc_mode ; - in OC mode? |
628 | 265 movf active_gas,W ; YES - replace by active gas |
623 | 266 btfsc bailout_mode ; - in bailout? |
267 ENDIF | |
631 | 268 movf active_gas,W ; (YES) - get (replace with) active OC (bailout) gas |
269 FLASH_WREG_PROFILE ; - store active gas/diluent | |
623 | 270 bcf event_gas_change ; - clear event flag |
628 | 271 |
0 | 272 store_dive_data3c: |
623 | 273 IFDEF _ccr_pscr |
274 btfss event_SP_change ; did a setpoint change occur? | |
631 | 275 bra store_dive_data3d ; NO - skip |
276 FLASH_CC_PROFILE char_I_const_ppO2 ; YES - store setpoint | |
623 | 277 bcf event_SP_change ; - clear event flag |
278 ENDIF | |
628 | 279 |
0 | 280 store_dive_data3d: |
623 | 281 IFDEF _ccr_pscr |
282 btfss event_bailout ; did a gas change due to bailout occur? | |
631 | 283 bra store_dive_data4 ; NO - skip |
284 FLASH_CC_PROFILE char_I_O2_ratio ; YES - store O2 ratio of bailout gas | |
623 | 285 IFDEF _helium |
631 | 286 FLASH_CC_PROFILE char_I_He_ratio ; - store He ratio of bailout gas |
623 | 287 ELSE |
631 | 288 FLASH_LIT_PROFILE .0 ; - store He ratio as zero |
628 | 289 ENDIF ; helium |
623 | 290 bcf event_bailout ; - clear event flag |
291 ENDIF ; _ccr_pscr | |
628 | 292 |
0 | 293 store_dive_data4: |
628 | 294 ; Store extended information |
631 | 295 decfsz divisor_temperature,F ; decrement timer, did it became 0 ? |
628 | 296 bra store_dive_data4a ; NO - skip |
631 | 297 rcall store_dive_temperature ; YES - store temperature |
628 | 298 store_dive_data4a: |
631 | 299 btfsc divisor_temperature,7 ; did the divisor under-run? |
628 | 300 clrf divisor_temperature ; YES - reset timer |
301 | |
631 | 302 decfsz divisor_deco,F ; decrement timer, did it became 0 ? |
628 | 303 bra store_dive_data4b ; NO - skip |
631 | 304 rcall store_dive_decodata ; YES - store deco data |
628 | 305 store_dive_data4b: |
306 btfsc divisor_deco,7 ; did the timer under-run? | |
307 clrf divisor_deco ; YES - reset timer | |
308 | |
631 | 309 decfsz divisor_supersat,F ; decrement timer, did it became 0 ? |
628 | 310 bra store_dive_data4c ; NO - skip |
631 | 311 rcall store_dive_supersat ; YES - store supersaturation |
628 | 312 store_dive_data4c: |
313 btfsc divisor_supersat,7 ; did the timer under-run? | |
314 clrf divisor_supersat ; YES - reset timer | |
315 | |
623 | 316 IFDEF _external_sensor |
631 | 317 decfsz divisor_ppo2_sensors,F ; decrement timer, did it became 0 ? |
628 | 318 bra store_dive_data4d ; NO - skip |
631 | 319 rcall store_dive_ppO2_sensors ; YES - store sensor data |
628 | 320 store_dive_data4d: |
321 btfsc divisor_ppo2_sensors,7 ; did the timer under-run? | |
322 clrf divisor_ppo2_sensors ; YES - reset timer | |
623 | 323 ENDIF |
324 | |
631 | 325 decfsz divisor_decoplan,F ; decrement timer, did it became 0 ? |
628 | 326 bra store_dive_data4e ; NO - skip |
631 | 327 rcall store_dive_decoplan ; YES - store deco plan |
628 | 328 store_dive_data4e: |
329 btfsc divisor_decoplan,7 ; did the timer under-run? | |
330 clrf divisor_decoplan ; YES - reset timer | |
623 | 331 |
631 | 332 decfsz divisor_cns,F ; decrement timer, did it became 0 ? |
628 | 333 bra store_dive_data4f ; NO - skip |
631 | 334 rcall store_dive_cns ; YES - store CNS |
628 | 335 store_dive_data4f: |
336 btfsc divisor_cns,7 ; did the timer under-run? | |
337 clrf divisor_cns ; YES - reset timer | |
623 | 338 |
628 | 339 IFDEF _rx_functions |
631 | 340 decfsz divisor_tank,F ; decrement timer, did it became 0 ? |
628 | 341 bra store_dive_data4g ; NO - skip |
631 | 342 rcall store_dive_tank ; YES - store tank pressure |
628 | 343 store_dive_data4g: |
344 btfsc divisor_tank,7 ; did the timer under-run? | |
345 clrf divisor_tank ; YES - reset timer | |
346 ENDIF | |
0 | 347 |
348 store_dive_data5: | |
604 | 349 bcf event_occured ; clear the global event flag |
623 | 350 clrf event_byte1 ; reset event byte 1 |
351 clrf event_byte2 ; reset event byte 2 | |
631 | 352 return ; done |
628 | 353 |
354 | |
355 IFDEF _rx_functions | |
356 store_dive_tank: | |
631 | 357 FLASH_II_PROFILE int_O_tank_pressure ; store tank pressure |
358 movlw div_tank ; get sampling rate | |
359 movwf divisor_tank ; reload timer | |
628 | 360 return |
361 ENDIF | |
582 | 362 |
0 | 363 store_dive_cns: |
631 | 364 MOVII int_O_CNS_current,mpr ; get current CNS |
365 bcf mpr+1,int_warning_flag ; clear warning flag | |
366 bcf mpr+1,int_attention_flag ; clear attention flag | |
367 FLASH_II_PROFILE mpr ; store CNS | |
368 movlw div_cns ; get sampling rate | |
369 movwf divisor_cns ; reload timer | |
0 | 370 return |
371 | |
372 store_dive_decoplan: | |
631 | 373 ; store the deco plan |
623 | 374 lfsr FSR1,char_O_deco_time_for_log ; load base address of deco stop times table |
375 movlw NUM_STOPS_LOG ; load size of deco stop times table | |
376 movwf lo ; copy size to loop counter | |
0 | 377 store_dive_decoplan_loop: |
623 | 378 movf POSTINC1,W ; get a stop time |
631 | 379 FLASH_WREG_PROFILE ; store it |
623 | 380 decfsz lo,F ; decrement loop counter, became zero? |
381 bra store_dive_decoplan_loop ; NO - loop | |
628 | 382 movlw div_decoplan ; YES - get sampling rate |
623 | 383 movwf divisor_decoplan ; - reload timer |
384 return ; - done | |
385 | |
386 | |
387 IFDEF _external_sensor | |
0 | 388 store_dive_ppO2_sensors: |
631 | 389 FLASH_CC_PROFILE sensor1_ppO2 ; store sensor 1 ppO2 (in 0.01 bar steps) |
390 SMOVII sensor1_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor | |
391 FLASH_II_PROFILE mpr ; store sensor 1 mV | |
0 | 392 |
631 | 393 FLASH_CC_PROFILE sensor2_ppO2 ; store sensor 2 ppO2 (in 0.01 bar steps) |
394 SMOVII sensor2_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor | |
395 FLASH_II_PROFILE mpr ; store sensor 2 mV | |
0 | 396 |
631 | 397 FLASH_CC_PROFILE sensor3_ppO2 ; store sensor 3 ppO2 (in 0.01 bar steps) |
398 SMOVII sensor3_mv,mpr ; ISR-safe 2 byte copy of o2_mv_sensor | |
399 FLASH_II_PROFILE mpr ; store sensor 3 mV | |
0 | 400 |
628 | 401 movlw div_ppo2_sensors ; get sampling rate |
623 | 402 movwf divisor_ppo2_sensors ; reload timer |
631 | 403 return ; done |
623 | 404 ENDIF |
405 | |
406 store_dive_supersat: | |
631 | 407 FLASH_CC_PROFILE int_O_lead_supersat+0 ; store leading tissue's supersaturation (value is limited to 255, only lower byte is used for the value) |
628 | 408 movlw div_gf ; get sampling rate |
623 | 409 movwf divisor_supersat ; reload timer |
631 | 410 return ; done |
0 | 411 |
412 store_dive_decodata: | |
582 | 413 ; Check if deco stops are necessary |
623 | 414 movff char_O_deco_depth,WREG ; get depth of the first stop |
415 tstfsz WREG ; depth of first stop > 0 m (aka in deco) ? | |
604 | 416 bra store_dive_decodata_deco ; YES |
631 | 417 ;bra store_dive_decodata_ndl ; NO |
418 | |
419 store_dive_decodata_ndl: | |
420 FLASH_LIT_PROFILE .0 ; store depth of first stop as zero (encodes NDL dive) | |
421 FLASH_CC_PROFILE int_O_NDL_norm+0 ; store NDL time from normal plan | |
582 | 422 bra store_dive_decodata_common |
631 | 423 |
582 | 424 store_dive_decodata_deco: |
631 | 425 FLASH_CC_PROFILE char_O_deco_depth ; store depth of the first stop in meters |
426 FLASH_CC_PROFILE char_O_deco_time ; store duration of the first stop in minutes | |
427 ;bra store_dive_decodata_common | |
428 | |
582 | 429 store_dive_decodata_common: |
628 | 430 movlw div_deco ; get sampling rate |
623 | 431 movwf divisor_deco ; reload timer |
631 | 432 return ; done |
0 | 433 |
434 store_dive_temperature: | |
631 | 435 SMOVII temperature_cur,mpr ; ISR-safe 2 byte copy of current temperature |
436 FLASH_II_PROFILE mpr ; store temperature | |
628 | 437 movlw div_temperature ; get sampling rate |
623 | 438 movwf divisor_temperature ; reload timer |
631 | 439 return ; done |
440 | |
0 | 441 |
631 | 442 ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
443 ; flash writing through the macros | |
444 ; | |
445 ghostwrite_II_profile_exec: | |
634 | 446 movf POSTINC0,W ; get byte into WREG |
447 call ext_flash_write_byte_0x20_incdc ; write to external flash and increment ext_flash_dive_counter | |
448 movf POSTINC0,W ; get next byte into WREG | |
631 | 449 ghostwrite_WREG_profile_exec: |
634 | 450 goto ext_flash_write_byte_0x20_incdc ; write to external flash and increment ext_flash_dive_counter (and return) |
631 | 451 ; |
452 ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
0 | 453 |
623 | 454 |
634 | 455 ;----------------------------------------------------------------------------- |
456 ; finish Dive Data Recording and write Header | |
457 ; | |
0 | 458 global ghostwriter_end_dive |
459 ghostwriter_end_dive: | |
631 | 460 ; save end-of-profile pointer for later storage in EEPROM |
461 MOVTT ext_flash_address,ext_flash_log_pointer | |
0 | 462 |
623 | 463 ; remember last custom view shown in dive mode |
464 movff active_customview,customview_divemode | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
35
diff
changeset
|
465 |
631 | 466 ; reset gas/diluent lost & staged flags |
467 lfsr FSR1,opt_gas_type ; load FSR1 with base address of opt_gas_type | |
468 IFDEF _ccr_pscr | |
469 movlw 2*NUM_GAS ; load loop counter with number of gases + diluents = 2*5 | |
470 ELSE | |
471 movlw NUM_GAS ; load loop counter with number of gases = 5 | |
472 ENDIF | |
473 ghostwriter_end_dive_0: | |
474 bcf INDF1,gas_lost ; clear lost flag and keep index at present gas/dil | |
475 bcf POSTINC1,gas_staged ; clear staged flag and advance index to next gas/dil | |
476 decfsz WREG ; decrement loop counter and check if it became zero | |
477 bra ghostwriter_end_dive_0 ; NO - not yet, loop | |
478 | |
479 ; clear bailout state (if applicable) | |
480 bcf bailout_mode | |
481 | |
482 ; check if dive is worth storage at all | |
483 btfss divetime_longer_1min ; dive longer than one minute? | |
634 | 484 goto ghostwriter_end_dive_common ; NO - discard everything |
0 | 485 |
623 | 486 ifndef _DEBUG |
631 | 487 ; in DEBUG compile, write simulated dives to logbook |
488 btfsc sensor_override_active ; in simulator mode? | |
623 | 489 goto ghostwriter_end_dive_common ; YES - discard everything |
490 endif | |
0 | 491 |
631 | 492 ; calculate desaturation time |
493 call deco_calc_desaturation_time ; call the C-code | |
494 banksel common ; back to bank common | |
495 | |
496 ; condition apnoe mode | |
497 btfss FLAG_apnoe_mode ; are we in apnoe mode? | |
498 bra ghostwriter_end_dive_00 ; NO - proceed | |
499 MOVII apnoe_max_pressure,pressure_rel_max_cached ; YES - get max pressure of all yoyo dives | |
500 | |
501 ghostwriter_end_dive_00: | |
502 ; compute max depth for storage and last dive statistics | |
503 MOVII pressure_rel_max_cached,mpr ; get max pressure | |
504 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
505 MOVII mpr,lastdive_maxdepth ; store for last dive statistics | |
506 | |
507 ; compute avg depth for storage and last dive statistics | |
508 MOVII pressure_rel_avg_total,mpr ; get average pressure | |
509 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
510 MOVII mpr,lastdive_avgdepth ; store in last dive statistics | |
511 | |
512 ; get dive duration for last dive statistics | |
513 SMOVTT counted_divetime_mins,lastdive_duration ; ISR-safe 3 byte copy of minutes:2 and seconds | |
514 | |
515 ; check logging of apnoe mode | |
623 | 516 btfss FLAG_apnoe_mode ; are we in apnoe mode? |
517 bra ghostwriter_end_dive_1 ; NO - proceed | |
631 | 518 TSTOSS opt_store_apnoe ; YES - logging in apnoe mode enabled? |
519 goto ghostwriter_end_dive_cleanup ; NO - skip logging but do the after-dive cleanup | |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
520 |
623 | 521 ghostwriter_end_dive_1: |
634 | 522 |
523 ;---- dive finished (and longer than one minute) ------------------------- | |
0 | 524 |
631 | 525 ; close profile recording |
526 FLASH_LIT_PROFILE 0xFD ; write end-of-profile code, byte 1 | |
527 FLASH_LIT_PROFILE 0xFD ; write end-of-profile code, byte 2 | |
582 | 528 |
631 | 529 ; save end-of-profile pointer for later storage in header and EEPROM |
530 MOVTT ext_flash_address,ext_flash_log_pointer | |
0 | 531 |
634 | 532 ; go back again to start of profile data to store the profile length (number of recorded bytes) |
533 call ghostwriter_load_pointer | |
0 | 534 |
631 | 535 ; skip internal "0xFA 0xFA #Divenumber:2 0xFA 0xFA" header, i.e. the first 6 bytes |
634 | 536 EXT_FLASH_INC_ADDRESS_0x20 d'6' |
0 | 537 |
634 | 538 ; store dive length (NO ext_flash_length_counter increase, NO page delete) |
539 movf ext_flash_length_counter+0,W ; get length of profile data, low byte | |
540 call ext_flash_write_byte_0x20_nodel ; write to flash | |
541 movf ext_flash_length_counter+1,W ; get length of profile data, high byte | |
542 call ext_flash_write_byte_0x20_nodel ; write to flash | |
543 movf ext_flash_length_counter+2,W ; get length of profile data, upper byte | |
544 call ext_flash_write_byte_0x20_nodel ; write to flash | |
623 | 545 |
631 | 546 ; ... profile recording done |
582 | 547 |
634 | 548 ; read, increment, and store updated total number of dives |
631 | 549 call eeprom_total_dives_read ; read total number of dives |
550 INCI mpr ; increment by one | |
551 call eeprom_total_dives_write ; store updated number of total dives | |
0 | 552 |
631 | 553 ; prepare header |
554 CLRR header_buffer,.256 ; initialize header to all zeros | |
582 | 555 |
631 | 556 ; store header start code |
557 MOVLI 0xFAFA,mpr | |
558 MOVII mpr,header_buffer+index_header_start | |
0 | 559 |
582 | 560 ; store pointer to begin of dive profile |
631 | 561 EEPROM_TT_READ eeprom_log_pointer,mpr |
562 MOVTT mpr,header_buffer+index_profile_start_address | |
0 | 563 |
582 | 564 ; store pointer to end of dive profile |
631 | 565 MOVTT ext_flash_log_pointer,header_buffer+index_profile_end_address |
0 | 566 |
631 | 567 ; write the profile format version (defined in hwos.inc) |
568 movlw logbook_profile_version | |
569 MOVCC WREG,header_buffer+index_profile_version | |
0 | 570 |
631 | 571 ; store dive length (in units of recording entries) |
572 MOVTT ext_flash_length_counter,header_buffer+index_profile_byte_count | |
0 | 573 |
631 | 574 ; store time time & date of dive begin |
575 MOVTT start_year,header_buffer+index_date | |
576 MOVTT start_hour,header_buffer+index_time | |
582 | 577 |
631 | 578 ; store max depth |
579 MOVII lastdive_maxdepth,header_buffer+index_max_depth | |
582 | 580 |
631 | 581 ; store dive time (ISR-safe 3 byte copy of minutes:2 and seconds) |
582 SMOVTT counted_divetime_mins,header_buffer+index_divetime | |
0 | 583 |
623 | 584 ; store minimum temperature |
631 | 585 MOVII temperature_min,header_buffer+index_min_temp |
623 | 586 |
587 ; store surface pressure (as used by deco engine) | |
631 | 588 MOVII int_I_pres_surface,header_buffer+index_surface_press |
623 | 589 |
590 ; store desaturation time | |
631 | 591 MOVII int_O_desaturation_time,header_buffer+index_desattime |
592 | |
593 ; store gases / diluents | |
594 lfsr FSR1,header_buffer+index_gas1 ; load FSR1 with base address of gases / diluents in header | |
623 | 595 |
596 IFDEF _ccr_pscr | |
604 | 597 btfsc FLAG_ccr_mode ; in CCR mode? |
631 | 598 bra end_dive_gaslist_diluent ; YES - write diluent gas list |
599 btfsc FLAG_pscr_mode ; NO - in pSCR mode? | |
600 bra end_dive_gaslist_diluent ; YES - write diluent gas list | |
601 ;bra end_dive_gaslist_gas ; NO - write OC gas list | |
623 | 602 ENDIF |
0 | 603 |
631 | 604 end_dive_gaslist_gas: ; write OC gases |
604 | 605 lfsr FSR0,opt_gas_O2_ratio-.1 ; set base address to (opt_gas_O2_ratio - 1) because of pre-increment statement |
631 | 606 bra end_dive_gaslist_common ; write all 5 OC gases |
0 | 607 |
623 | 608 IFDEF _ccr_pscr |
631 | 609 end_dive_gaslist_diluent: ; write diluents |
604 | 610 lfsr FSR0,opt_dil_O2_ratio-.1 ; set base address to (opt_dil_O2_ratio - 1) because of pre-increment statement |
631 | 611 ;bra end_dive_gaslist_common ; write all 5 diluents |
623 | 612 ENDIF |
0 | 613 |
631 | 614 end_dive_gaslist_common: ; helper function for writing gas list entries |
634 | 615 |
604 | 616 ; Memory Map: |
617 ; ------------------------- | |
618 ; opt_gas_O2_ratio res 5 | |
619 ; opt_dil_O2_ratio res 5 | |
620 ; opt_gas_He_ratio res 5 | |
621 ; opt_dil_He_ratio res 5 | |
622 ; opt_gas_type res 5 | |
623 ; opt_dil_type res 5 | |
624 ; opt_gas_change res 5 | |
625 ; opt_dil_change res 5 | |
634 | 626 |
604 | 627 movlw .5 ; 5 gases to store |
628 movwf lo ; use lo as counter | |
629 end_dive_gaslist_loop: | |
631 | 630 movff PREINC0,POSTINC1 ; increment FSR0 address and copy O2 ratio to buffer |
604 | 631 movlw .10 ; offset for H2 ratios |
631 | 632 movff PLUSW0,POSTINC1 ; copy H2 ratio to buffer |
604 | 633 movlw .30 ; offset for change depths |
631 | 634 movff PLUSW0,POSTINC1 ; copy change depth to buffer |
604 | 635 movlw .20 ; offset for types |
631 | 636 movff PLUSW0,POSTINC1 ; copy type to buffer |
604 | 637 decfsz lo ; decrement counter, did it became 0 ? |
638 bra end_dive_gaslist_loop ; NO - loop | |
0 | 639 |
631 | 640 ; store major firmware version |
641 movlw fw_version_major | |
642 MOVCC WREG,header_buffer+index_firmware+0 | |
643 | |
644 ; store minor firmware version | |
645 movlw fw_version_minor | |
646 MOVCC WREG,header_buffer+index_firmware+1 | |
0 | 647 |
623 | 648 ; store battery voltage |
631 | 649 MOVII batt_voltage,header_buffer+index_battery_voltage |
623 | 650 |
651 ; store sampling rate | |
631 | 652 MOVCC sampling_rate,header_buffer+index_samplingrate |
623 | 653 |
654 ; store CNS at beginning of dive | |
631 | 655 MOVII CNS_start,header_buffer+index_cns_start |
0 | 656 |
631 | 657 ; store supersaturations |
658 MOVCC supersat_start, header_buffer+index_supersat_start | |
659 MOVCC int_O_lead_supersat+0,header_buffer+index_supersat_end ; low byte only needed | |
5 | 660 |
623 | 661 ; store logbook offset |
631 | 662 call eeprom_log_offset_read |
663 MOVII mpr,header_buffer+index_logoffset | |
664 | |
665 ; increment log offset | |
666 rcall increment_log_offset | |
5 | 667 |
631 | 668 ; store battery level |
669 MOVCC batt_percent,header_buffer+index_batt_percent | |
604 | 670 |
631 | 671 IFDEF _ccr_pscr |
623 | 672 ; store setpoints |
673 lfsr FSR0,opt_setpoint_cbar ; base address of ppO2 values | |
674 lfsr FSR1,opt_setpoint_change ; base address of change depths | |
631 | 675 lfsr FSR2,header_buffer+index_sp1 ; base address of setpoint data in header buffer |
634 | 676 movlw .5 ; 5 setpoints (ppO2, depth) to be stored |
604 | 677 movwf lo ; use lo as counter |
678 end_dive_sp_loop: | |
631 | 679 movff POSTINC0,POSTINC2 ; copy ppO2 value |
680 movff POSTINC1,POSTINC2 ; copy change depth | |
604 | 681 decfsz lo ; decrement counter, did it became 0 ? |
682 bra end_dive_sp_loop ; NO - loop | |
631 | 683 ELSE |
684 ; just leave the zero bytes written during header initialization in place | |
685 ENDIF | |
0 | 686 |
623 | 687 ; store salinity |
631 | 688 MOVCC opt_salinity,header_buffer+index_salinity |
0 | 689 |
623 | 690 ; store CNS at end of dive |
631 | 691 MOVII int_O_CNS_current,mpr ; get CNS into mpr |
692 bcf mpr+1,int_warning_flag ; clear warning flag | |
693 bcf mpr+1,int_attention_flag ; clear attention flag | |
694 MOVII mpr,header_buffer+index_cns_end ; store CNS | |
0 | 695 |
623 | 696 ; store average depth |
631 | 697 MOVII lastdive_avgdepth,header_buffer+index_avr_depth |
698 | |
699 ; store total dive time (ISR-safe 2 byte copy) | |
700 SMOVII total_divetime_secs,header_buffer+index_total_seconds | |
604 | 701 |
631 | 702 ; store GF low/high or saturation/desaturation multiplier |
703 movff char_I_model,WREG ; get deco model | |
704 xorlw .1 ; deco model = ZH-L16-GF ? | |
705 bz end_dive_gf ; YES - store GFs | |
706 ;bnz end_dive_sat ; NO - store sat/desat | |
0 | 707 |
631 | 708 end_dive_sat: |
709 movff char_I_saturation_multiplier, header_buffer+index_factor_sat_desat+0 ; saturation multiplier | |
710 movff char_I_desaturation_multiplier,header_buffer+index_factor_sat_desat+1 ; desaturation multiplier | |
711 bra end_dive_sat_gf_done ; continue | |
623 | 712 |
631 | 713 end_dive_gf: |
714 movff char_I_GF_Low_percentage, header_buffer+index_gf_lo_hi+0 ; GF low | |
715 movff char_I_GF_High_percentage, header_buffer+index_gf_lo_hi+1 ; GF high | |
716 ;bra end_dive_sat_gf_done ; continue | |
0 | 717 |
631 | 718 end_dive_sat_gf_done: |
623 | 719 ; store deco model |
631 | 720 MOVCC char_I_model,header_buffer+index_decomodel |
0 | 721 |
623 | 722 ; store total dive number |
631 | 723 call eeprom_total_dives_read |
724 MOVII mpr,header_buffer+index_total_dives | |
0 | 725 |
631 | 726 ; store dive mode |
727 MOVCC opt_dive_mode,header_buffer+index_divemode | |
0 | 728 |
631 | 729 ; store tissue data - total tissue pressure |
730 lfsr FSR1,char_O_tissue_pressure ; load base address of total tissue pressures (chars) | |
731 lfsr FSR2,header_buffer+index_tissue_pres_total ; load corresponding base address in header | |
732 bsf aux_flag ; clear bit 7 (on-/off-gassing flag bit) | |
733 movlw .16 ; 16 tissues to copy | |
734 rcall copy_tissuepres_to_header ; store the tissue pressures | |
0 | 735 |
623 | 736 ; store tissue data - N2 floats |
631 | 737 lfsr FSR1,0x700 ; load base address of N2 tissue pressures (floats) |
738 ;lfsr FSR2,header_buffer+index_tissue_pres_N2 ; load corresponding base address in header | |
739 bcf aux_flag ; do not touch bit 7 | |
740 movlw .64 ; 16 tissue x 4 byte/tissue to copy | |
741 rcall copy_tissuepres_to_header ; store the tissue pressures | |
0 | 742 |
631 | 743 ; store tissue data - tissue supersaturations |
744 lfsr FSR1,char_O_tissue_saturation ; load base address of tissue saturations (chars) | |
745 ;lfsr FSR2,header_buffer+index_tissue_supersat ; load corresponding base address in header | |
746 bsf aux_flag ; clear bit 7 (on-/off-gassing flag bit) | |
747 movlw .16 ; 16 tissues to copy | |
748 rcall copy_tissuepres_to_header ; store the tissue pressures | |
0 | 749 |
623 | 750 ; store tissue data - He floats |
631 | 751 lfsr FSR1,0x740 ; load base address of He tissue pressures (floats) |
752 ;lfsr FSR2,header_buffer+index_tissue_pres_He ; load corresponding base address in header | |
753 bcf aux_flag ; do not touch bit 7 | |
754 movlw .64 ; 16 tissue x 4 byte/tissue to copy | |
755 rcall copy_tissuepres_to_header ; store the tissue pressures | |
0 | 756 |
623 | 757 ; store last stop depth |
631 | 758 MOVCC char_I_last_stop_depth,header_buffer+index_last_stop |
0 | 759 |
623 | 760 ; store deco distance |
631 | 761 ; -> the deco distance concept is disposed of, so just store a hard-coded zero |
762 ; --> so just leave the zero written during header initialization in place | |
763 ;clrf WREG | |
764 ;MOVCC WREG,header_buffer+index_decodistance | |
0 | 765 |
623 | 766 IFDEF _external_sensor |
631 | 767 ; store last HUD data (ISR-safe 3 byte copy) |
768 SMOVTT hud_status_byte,header_buffer+index_hud_data | |
623 | 769 ELSE |
631 | 770 ; just leave the zero bytes in place |
623 | 771 ENDIF |
0 | 772 |
631 | 773 ; store battery gauge registers [nAs] (ISR-safe 6 byte copy) |
774 SMOVSS battery_gauge,header_buffer+index_battery_gauge | |
623 | 775 |
776 ; write header stop code | |
631 | 777 MOVLI 0xFBFB,mpr |
778 MOVII mpr,header_buffer+index_header_stop | |
779 | |
634 | 780 ; store header in the FLASH |
631 | 781 call eeprom_total_dives_read ; read total number of dives |
782 decf mpr+0,W ; compute index from low(total number of dives) | |
634 | 783 call log_header_addr_by_index ; compute header start address |
784 call ext_flash_erase_4kB ; erase the FLASH 4 kB block where the header will be stored | |
785 FLASH_RR_WRITE header_buffer,.256 ; write the header to the FLASH | |
631 | 786 |
787 ghostwriter_end_dive_cleanup: | |
788 call eeprom_deco_data_write ; update deco data in EEPROM | |
623 | 789 bsf reset_surface_interval ; request ISR to reset the surface interval timer |
0 | 790 |
791 ghostwriter_end_dive_common: | |
631 | 792 ; memorize current ext_flash_log_pointer in EEPROM |
793 EEPROM_TT_WRITE ext_flash_log_pointer,eeprom_log_pointer | |
0 | 794 |
631 | 795 ; terminate simulator mode |
796 btfss simulatormode ; in simulator mode, i.e. need to restore tissue pressures? | |
797 bra ghostwriter_end_dive_common_1 ; NO - continue | |
798 bcf simulatormode ; YES - end simulator mode | |
799 bcf sensor_override_request ; - request ISR to terminate the simulator mode | |
800 btfsc sensor_override_active ; - has the ISR confirmed termination of simulator mode? | |
801 bra $-2 ; NO - not yet, loop waiting for the ISR | |
802 | |
623 | 803 ifndef _DEBUG |
631 | 804 ; in DEBUG compile, keep tissue pressures from simulated dives |
805 call deco_pull_tissues_from_vault ; - restore tissue pressures (C-code) | |
806 banksel common ; - back to bank common | |
623 | 807 endif |
604 | 808 |
623 | 809 ghostwriter_end_dive_common_1: |
631 | 810 ; restart the timebase |
811 bsf reset_timebase ; request ISR to reset the timebase | |
812 ; btfsc reset_timebase ; has the ISR confirmed reset of timebase? | |
813 ; bra $-2 ; NO - not yet, loop waiting for the ISR | |
814 | |
815 ; update battery gauge into EEPROM | |
816 call eeprom_battery_gauge_write | |
817 | |
818 ; catch-up simulator runtime / calculate deco data for surface mode | |
623 | 819 movff simulator_time,char_I_dive_interval ; get the simulator runtime, reads 0 if exiting from a real dive |
820 call deco_calc_dive_interval ; catch up with tissue desaturation when exiting from simulator, | |
821 ; else calculates for 2 seconds only when exiting from a real dive, | |
631 | 822 ; needed to update CNS, GF and tissue graphics for surface display. |
823 call deco_calc_desaturation_time ; calculate desaturation and no-fly/no-altitude time after catch-up | |
623 | 824 banksel common ; back to bank common |
825 | |
826 ; the last surface pressure sample may have been taken while being submerged a bit already, | |
827 ; therefore it will be replaced by the sample taken one more before, which is the one that | |
828 ; became the surface pressure reference used while this dive. | |
829 MOVII pressure_abs_ref,pressure_abs_sampled | |
830 | |
631 | 831 ; done with post-dive operations, return to surface loop |
832 goto surfloop | |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
833 |
623 | 834 |
631 | 835 ;----------------------------------------------------------------------------- |
634 | 836 ; Helper Function - copy Tissue Pressures |
631 | 837 ; |
838 copy_tissuepres_to_header: | |
839 movwf eeprom_loop ; initialize loop counter (EEPROM var used here) | |
840 copy_tissuepres_to_header_loop: | |
841 movf POSTINC1,W ; copy tissue pressure to WREG | |
842 btfsc aux_flag ; shall clear bit 7 ? | |
843 bcf WREG,7 ; YES - clear bit for on-gassing/off-gassing | |
844 movwf POSTINC2 ; copy WREG to header buffer | |
845 decfsz eeprom_loop,F ; decrement loop counter, all done? | |
846 bra copy_tissuepres_to_header_loop ; NO - loop | |
847 return ; YES - done | |
219
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
848 |
4b2622e0fd50
init new 4kB Page in logbook memory when pointer is not valid.
heinrichsweikamp
parents:
185
diff
changeset
|
849 |
631 | 850 ;----------------------------------------------------------------------------- |
634 | 851 ; Helper Function - increment Log Offset |
852 ; | |
853 increment_log_offset: | |
854 call eeprom_log_offset_read ; read current logbook offset into mpr | |
855 movf mpr+0,W ; get low byte | |
856 iorwf mpr+1,W ; inclusive-or with high byte, result zero? | |
857 bz increment_log_offset_1 ; YES - skip offset correction | |
858 INCI mpr ; NO - increment offset | |
859 call eeprom_log_offset_write ; - store incremented offset as new offset | |
860 increment_log_offset_1: | |
861 return ; done | |
862 | |
863 | |
864 ;----------------------------------------------------------------------------- | |
865 ; start Dive Data Recording (write short Header with Dive Number) | |
631 | 866 ; |
867 global ghostwriter_short_header | |
868 ghostwriter_short_header: | |
869 ; get pointer for profile storing | |
870 rcall ghostwriter_load_pointer | |
871 | |
872 ; the following code is used to write a clean new dive after the previous | |
873 ; hasn't been stored correctly. e.g. after a power loss during the dive | |
874 FLASH_II_READ_0x20 mpr ; read first two bytes | |
875 incfsz mpr+0,F ; is 1st byte = 0xFF ? | |
876 bra ghostwriter_short_header_init ; NO - initialize page | |
877 incfsz mpr+1,F ; - is 2nd byte = 0xFF ? | |
878 bra ghostwriter_short_header_init ; NO - initialize page | |
879 bra ghostwriter_short_header_2 ; YES - page is clean, can continue | |
0 | 880 |
631 | 881 ghostwriter_short_header_init: |
882 clrf ext_flash_address+0 ; low byte: set to zero | |
634 | 883 movlw 0xF0 ; high byte: keep upper nibble, set lower nibble to zero |
631 | 884 andwf ext_flash_address+1,F ; ... |
885 movlw .16 ; increment ext_flash_address to next multiple of 16*256 | |
886 addwf ext_flash_address+1,F ; ... | |
887 movlw .0 ; ... | |
888 addwfc ext_flash_address+2,F ; ... | |
889 movlw 0x20 ; at address 0x200000 ? | |
890 cpfseq ext_flash_address+2 ; ... | |
891 bra ghostwriter_short_header_init_2 ; NO - continue | |
892 clrf ext_flash_address+2 ; YES - rollover to 0x000000 | |
893 | |
894 ghostwriter_short_header_init_2: | |
895 ; update pointer in EEPROM | |
896 EEPROM_TT_WRITE ext_flash_address,eeprom_log_pointer | |
0 | 897 |
631 | 898 ghostwriter_short_header_2: |
899 ; reload the pointer (required after above checks) | |
900 rcall ghostwriter_load_pointer ; reload ext_flash_address from EEPROM | |
901 | |
902 ; clear dive length counter | |
903 CLRT ext_flash_length_counter | |
904 | |
905 ; write short start header with dive number into profile memory | |
906 FLASH_LIT_PROFILE 0xFA ; 1st byte | |
907 FLASH_LIT_PROFILE 0xFA ; 2nd byte | |
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
|
908 |
631 | 909 ; load total number of dives |
634 | 910 call eeprom_total_dives_read ; read total number of dives into mpr:2 |
631 | 911 incf mpr+0,F ; increment low byte + 1 |
634 | 912 FLASH_II_PROFILE mpr ; write mpr:2 to FLASH |
631 | 913 |
914 ; close short header | |
915 FLASH_LIT_PROFILE 0xFA ; 1st byte | |
916 FLASH_LIT_PROFILE 0xFA ; 2nd byte | |
917 | |
634 | 918 ; Keep room for dive length ext_flash_length_counter:3 (stored at the end of the dive), |
919 ; writing 0xFF here is mandatory because 0xFF can be overwritten when closing the dive. | |
920 ; The stored dive length counter itself is not part of the counted dive length. | |
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
|
921 |
634 | 922 setf WREG ; write 0xFF |
923 call ext_flash_write_byte_0x20 ; write to profile (no dive length increment) | |
924 setf WREG ; write 0xFF | |
925 call ext_flash_write_byte_0x20 ; write to profile (no dive length increment) | |
926 setf WREG ; write 0xFF | |
927 call ext_flash_write_byte_0x20 ; write to profile (no dive length increment) | |
0 | 928 |
628 | 929 ; store sizes and sampling rates of recording datasets |
0 | 930 |
631 | 931 FLASH_CC_PROFILE sampling_rate ; get general sampling rate |
0 | 932 |
631 | 933 FLASH_LIT_PROFILE .7 ; number of additional datasets |
0 | 934 |
631 | 935 FLASH_LIT_PROFILE .0 ; type: temperature |
936 FLASH_LIT_PROFILE infolength_temperature ; get size of recording data | |
937 FLASH_LIT_PROFILE div_temperature ; get sampling rate | |
0 | 938 |
628 | 939 |
631 | 940 FLASH_LIT_PROFILE .1 ; type: +++ |
941 FLASH_LIT_PROFILE infolength_deco ; get size of recording data | |
942 FLASH_LIT_PROFILE div_deco ; get sampling rate | |
943 | |
944 FLASH_LIT_PROFILE .2 ; type: saturation | |
945 FLASH_LIT_PROFILE infolength_gf ; get size of recording data | |
946 FLASH_LIT_PROFILE div_gf ; get sampling rate | |
0 | 947 |
631 | 948 FLASH_LIT_PROFILE .3 ; type: ppO2 sensor data |
949 FLASH_LIT_PROFILE infolength_ppo2_sensors ; get size of recording data | |
950 movlw .0 ; default to no ppO2 data | |
951 IFDEF _external_sensor | |
952 btfsc FLAG_ccr_mode ; in CCR mode? | |
953 movlw div_ppo2_sensors ; YES - get sampling rate | |
954 btfsc FLAG_pscr_mode ; in pSCR mode? | |
955 movlw div_ppo2_sensors ; YES - get sampling rate | |
956 ENDIF | |
957 FLASH_WREG_PROFILE ; WREG -> profile in ext. flash | |
0 | 958 |
631 | 959 FLASH_LIT_PROFILE .4 ; type: deco plan (stop times) |
960 FLASH_LIT_PROFILE infolength_decoplan ; get size of recording data | |
961 FLASH_LIT_PROFILE div_decoplan ; get sampling rate | |
962 | |
963 FLASH_LIT_PROFILE .5 ; type: CNS | |
964 FLASH_LIT_PROFILE infolength_cns ; get size of recording data | |
965 FLASH_LIT_PROFILE div_cns ; get sampling rate | |
0 | 966 |
631 | 967 FLASH_LIT_PROFILE .6 ; type: tank pressure |
968 FLASH_LIT_PROFILE infolength_tank ; get size of recording data | |
969 movlw .0 ; default to no tank pressure data | |
970 IFDEF _rx_functions | |
971 btfsc tr_functions_activated ; TR functions activated? | |
972 movlw div_tank ; YES - get sampling rate | |
973 ENDIF | |
974 FLASH_WREG_PROFILE ; WREG -> profile in ext. flash | |
0 | 975 |
634 | 976 return ; done |
977 | |
978 | |
979 ;----------------------------------------------------------------------------- | |
980 ; Helper Function - load ext_flash_address from EEPROM | |
981 ; | |
982 ghostwriter_load_pointer: | |
983 EEPROM_TT_READ eeprom_log_pointer,ext_flash_address | |
0 | 984 return |
582 | 985 |
631 | 986 ;----------------------------------------------------------------------------- |
0 | 987 |
582 | 988 END |