annotate src/ghostwriter.asm @ 31:53a09c1b7410

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