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