Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 601:08a0162d3ca1
Fix false CNS readings in logbook
author | heinrichsweikamp |
---|---|
date | Tue, 14 Aug 2018 11:01:47 +0200 |
parents | b455b31ce022 |
children | ca4556fb60b9 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
582 | 3 ; File eeprom_rs232.asm V2.98 |
0 | 4 ; |
5 ; Internal EEPROM, RS232 | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-06 : [mH] moving from OSTC code | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "wait.inc" |
582 | 14 #include "shared_definitions.h" |
15 #include "rtc.inc" | |
16 | |
17 write_int_eeprom macro eeprom_address | |
18 movlw eeprom_address | |
19 call write_int_eeprom_1 | |
20 endm | |
21 | |
22 read_int_eeprom macro eeprom_address | |
23 movlw eeprom_address | |
24 call read_int_eeprom_1 | |
25 endm | |
26 | |
27 ;============================================================================= | |
28 eeprom code 0xF00000+0x10 | |
29 ; Skip SERIAL number. Should not be overwritten. | |
30 | |
31 global eeprom_serial_save | |
32 global eeprom_opt_backup | |
33 | |
34 eeprom_serial_save res 2 | |
35 eeprom_opt_backup res 0x3E | |
0 | 36 |
37 ;============================================================================= | |
582 | 38 basic CODE |
0 | 39 |
582 | 40 global write_int_eeprom_1 |
0 | 41 write_int_eeprom_1: |
42 movwf EEADR | |
582 | 43 ; bra write_eeprom ; writes and "returns" after write |
44 | |
45 ;============================================================================= | |
46 ; writes into internal eeprom | |
47 ; Input: EEADRH:EEADR = EEPROM address. | |
48 ; EEDATA = byte to write. | |
49 ; Trashed: WREG. | |
50 global write_eeprom | |
51 write_eeprom: | |
52 bcf EECON1,EEPGD | |
53 bcf EECON1,CFGS | |
54 bsf EECON1,WREN | |
55 | |
56 bcf INTCON,GIE ; Disable interrupts for the next 5 instructions | |
57 movlw 0x55 | |
58 movwf EECON2 | |
59 movlw 0xAA | |
60 movwf EECON2 | |
61 bsf EECON1,WR | |
62 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! | |
63 | |
64 write_eep2: | |
65 btfsc EECON1,WR | |
66 bra write_eep2 ; wait about 4ms... | |
67 bcf EECON1,WREN | |
68 return | |
69 | |
70 | |
0 | 71 |
72 global read_int_eeprom_1 | |
73 read_int_eeprom_1: | |
74 movwf EEADR | |
582 | 75 ; bra read_eeprom ; reads and "returns" after write |
0 | 76 |
77 ;============================================================================= | |
78 ; reads from internal eeprom | |
79 ; Input: EEADRH:EEADR = EEPROM address. | |
80 ; Output: EEDATA. | |
81 ; Trashed: NONE. | |
82 global read_eeprom | |
582 | 83 read_eeprom: |
0 | 84 bcf EECON1,EEPGD |
85 bcf EECON1,CFGS | |
86 bsf EECON1,RD | |
87 return | |
88 | |
582 | 89 global disable_ir_s8 |
90 disable_ir_s8: | |
91 banksel TXSTA2 | |
92 clrf TXSTA2 | |
93 clrf RCSTA2 | |
94 banksel common | |
95 bcf ir_power ; IR off | |
96 bcf mcp_power ; Power-down instrumentation amp | |
97 bsf s8_npower ; Power-down S8 HUD | |
0 | 98 return |
99 | |
100 | |
582 | 101 global enable_ir_s8 |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
151
diff
changeset
|
102 enable_ir_s8: |
0 | 103 ;init serial port2 (TRISG2) |
582 | 104 btfsc analog_o2_input |
105 bra enable_s8 ; Start S8 | |
113 | 106 |
582 | 107 banksel BAUDCON2 |
108 movlw b'00100000' ; BRG16=0 ; inverted for IR | |
113 | 109 movwf BAUDCON2 |
582 | 110 movlw b'00100000' ; BRGH=0, SYNC=0 |
111 movwf TXSTA2 | |
112 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16MHz | |
113 movwf SPBRG2 | |
114 movlw b'10010000' | |
115 movwf RCSTA2 | |
116 banksel common | |
117 bsf ir_power ; Power-up IR | |
118 btfss ir_power | |
119 bra $-6 | |
120 return | |
0 | 121 |
113 | 122 enable_s8: |
582 | 123 ; Check for Digital/Analog |
124 bsf s8_npower ; Power-down S8 HUD | |
125 WAITMS d'1' ; Very short delay | |
126 bsf mcp_power ; Power-up instrumentation amp | |
127 btfss mcp_power | |
128 bra $-6 | |
129 banksel TXSTA2 | |
130 clrf TXSTA2 | |
131 clrf RCSTA2 | |
132 banksel common | |
113 | 133 |
582 | 134 ; It may be digital, check for voltage when isolator is powered |
135 bcf s8_npower ; Power S8 HUD | |
136 WAITMS d'1' ; Very short delay | |
113 | 137 |
582 | 138 btfsc PORTG,2 ; RX2=1? |
139 bra enable_s8_2 ; Yes, digital | |
140 WAITMS d'30' | |
141 btfsc PORTG,2 ; RX2=1? | |
142 bra enable_s8_2 ; Yes, digital | |
143 | |
144 ; Not found, set to analog (fail-safe) | |
113 | 145 |
146 enable_s8_analog: | |
582 | 147 ; S8 Analog |
148 bsf s8_npower ; Power-down S8 HUD | |
149 bcf s8_digital ; Clear flag | |
150 return | |
113 | 151 |
582 | 152 enable_s8_2: ; S8 Digital |
153 banksel BAUDCON2 | |
154 movlw b'00000000' ; BRG16=0 ; normal for S8 | |
113 | 155 movwf BAUDCON2 |
582 | 156 movlw b'00100000' ; BRGH=0, SYNC=0 |
157 movwf TXSTA2 | |
158 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16MHz | |
159 movwf SPBRG2 | |
160 movlw b'10010000' | |
161 movwf RCSTA2 | |
162 banksel common | |
163 bsf s8_digital ; Set flag | |
164 return | |
113 | 165 |
0 | 166 ;============================================================================= |
582 | 167 |
0 | 168 global enable_rs232 |
169 enable_rs232: | |
582 | 170 call speed_normal ; 16MHz |
0 | 171 enable_rs232_2: |
582 | 172 movlw T2CON_NORMAL |
173 cpfseq T2CON | |
174 bra enable_rs232_2 ; Wait until speed is normal | |
175 bcf PORTE,0 ; Start comms | |
0 | 176 ;init serial port1 (TRISC6/7) |
582 | 177 movlw b'00100100' ; BRGH=1, SYNC=0 |
178 movwf TXSTA1 | |
179 movlw b'10010000' | |
180 movwf RCSTA1 | |
0 | 181 return |
182 | |
582 | 183 |
0 | 184 global disable_rs232 |
185 disable_rs232: | |
186 clrf RCSTA1 | |
582 | 187 clrf TXSTA1 ; UART disable |
188 bcf PORTC,6 ; TX hard to GND | |
189 bsf PORTE,0 ; Stop comms | |
0 | 190 return |
191 | |
582 | 192 |
0 | 193 global rs232_wait_tx |
194 rs232_wait_tx: | |
582 | 195 btfss TXSTA1,TRMT ; RS232 Busy? |
196 bra rs232_wait_tx ; yes, wait... | |
197 | |
198 btfss ble_available ; ble available? | |
199 return ; No, done. | |
200 | |
201 btfsc NRTS ; Wait for Bluetooth module | |
202 bra rs232_wait_tx ; yes, wait... | |
203 return ; Done. | |
344
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
204 |
0 | 205 |
582 | 206 global rs232_wait_tx2 |
113 | 207 rs232_wait_tx2: |
582 | 208 banksel TXSTA2 |
209 | 209 rs232_wait_tx2_1: |
582 | 210 btfss TXSTA2,TRMT ; RS232 Busy? |
211 bra rs232_wait_tx2_1 ; yes, wait... | |
212 banksel common | |
213 return ; Done. | |
113 | 214 |
0 | 215 global rs232_get_byte |
216 rs232_get_byte: | |
582 | 217 bcf rs232_receive_overflow ; clear flag |
218 movlw .10 | |
219 movwf uart1_temp | |
220 clrf uart2_temp | |
221 clrf uart3_temp | |
0 | 222 rs232_get_byte2: |
582 | 223 btfsc PIR1,RCIF ; data arrived? |
224 return ; Yes | |
225 decfsz uart3_temp,F | |
378 | 226 bra rs232_get_byte2 |
582 | 227 decfsz uart2_temp,F |
228 bra rs232_get_byte2 | |
229 decfsz uart1_temp,F | |
0 | 230 bra rs232_get_byte2 |
582 | 231 ; timeout occurred (about 400ms) |
232 bsf rs232_receive_overflow ; set flag | |
378 | 233 rs232_get_byte3: |
582 | 234 bcf RCSTA1,CREN ; Clear receiver status |
0 | 235 bsf RCSTA1,CREN |
582 | 236 return ; and return anyway |
237 | |
238 ;============================================================================= | |
239 | |
240 global do_logoffset_common_write | |
241 do_logoffset_common_write: | |
242 ; TODO: limit [lo:hi] to 9999 ? may arrive here as >= 10000 because of +10 increment option | |
243 ; SIMPLER WAY: return without writing to eeprom if hi == 0x27 -> 0x2700 = 9984, this is within | |
244 ; the save range for a +10 increment, shall do it... | |
245 ; mH | |
246 | |
247 movff lo,EEDATA | |
248 write_int_eeprom 0x0D | |
249 movff hi,EEDATA | |
250 write_int_eeprom 0x0E | |
251 return | |
252 | |
253 global do_logoffset_common_read | |
254 do_logoffset_common_read: | |
255 clrf EEADRH | |
256 read_int_eeprom 0x0D | |
257 movff EEDATA,lo | |
258 read_int_eeprom 0x0E | |
259 movff EEDATA,hi ; Existing logbook offset into lo:hi | |
260 return | |
261 | |
262 | |
263 global update_battery_registers | |
264 update_battery_registers: | |
265 ; save battery_gauge:6 into EEPROM 0x07-0x0C | |
266 clrf EEADRH | |
267 movff battery_gauge+0,EEDATA | |
268 write_int_eeprom 0x07 | |
269 movff battery_gauge+1,EEDATA | |
270 write_int_eeprom 0x08 | |
271 movff battery_gauge+2,EEDATA | |
272 write_int_eeprom 0x09 | |
273 movff battery_gauge+3,EEDATA | |
274 write_int_eeprom 0x0A | |
275 movff battery_gauge+4,EEDATA | |
276 write_int_eeprom 0x0B | |
277 movff battery_gauge+5,EEDATA | |
278 write_int_eeprom 0x0C | |
279 movff battery_type,EEDATA ; =0:1.5V, =1:3,6V Saft, =2:LiIon 3,7V/0.8Ah, =3:LiIon 3,7V/3.1Ah, =4: LiIon 3,7V/2.3Ah | |
280 write_int_eeprom 0x0F | |
281 return | |
282 | |
283 | |
284 global vault_decodata_into_eeprom | |
285 vault_decodata_into_eeprom: | |
286 ; Vault in EEPROM 512...1023 | |
287 ; Write 0xAA at 512 to indicate valid data in vault | |
288 ; Store last time/date | |
289 ; Store 0x700 to 0x780 (pres_tissue_N2 and pres_tissue_He) | |
290 movlw HIGH .512 ; =2 | |
291 movwf EEADRH | |
292 movlw 0xAA | |
293 movwf EEDATA | |
294 write_int_eeprom .0 | |
295 ; Store date/time | |
296 movff year,EEDATA | |
297 write_int_eeprom .1 | |
298 movff month,EEDATA | |
299 write_int_eeprom .2 | |
300 movff day,EEDATA | |
301 write_int_eeprom .3 | |
302 movff hours,EEDATA | |
303 write_int_eeprom .4 | |
304 movff mins,EEDATA | |
305 write_int_eeprom .5 | |
306 movff secs,EEDATA | |
307 write_int_eeprom .6 | |
308 | |
309 movff int_O_CNS_fraction+0,EEDATA | |
310 write_int_eeprom .7 | |
311 movff int_O_CNS_fraction+1,EEDATA | |
312 write_int_eeprom .8 | |
313 movff int_O_desaturation_time+0,EEDATA | |
314 write_int_eeprom .9 | |
315 movff int_O_desaturation_time+1,EEDATA | |
316 write_int_eeprom .10 | |
317 movff surface_interval+0,EEDATA | |
318 write_int_eeprom .11 | |
319 movff surface_interval+1,EEDATA | |
320 write_int_eeprom .12 | |
321 movff int_O_gradient_factor+0,EEDATA ; value limited to 255, only lower byte in use for value | |
322 write_int_eeprom .13 | |
323 movff int_O_nofly_time+0,EEDATA | |
324 write_int_eeprom .14 | |
325 movff int_O_nofly_time+1,EEDATA | |
326 write_int_eeprom .15 | |
0 | 327 |
582 | 328 ; Tissue data from 16 to 144 |
329 movlw .16 | |
330 movwf EEADR | |
331 movlw .128 | |
332 movwf lo | |
333 lfsr FSR1,0x700 ; pres_tissue_N2+0, 32*4Byte Float = 128Bytes | |
334 vault_decodata_into_eeprom2: | |
335 movff POSTINC1,EEDATA | |
336 call write_eeprom ; EEDATA into EEPROM@EEADR | |
337 incf EEADR,F | |
338 decfsz lo,F ; All done? | |
339 bra vault_decodata_into_eeprom2 ; No | |
340 clrf EEADRH | |
341 return | |
342 | |
343 global restore_decodata_from_eeprom | |
344 restore_decodata_from_eeprom: | |
345 movlw LOW .512 ; =0 | |
346 movwf EEADR | |
347 movlw HIGH .512 ; =2 | |
348 movwf EEADRH | |
349 | |
350 ; Restore date/time | |
351 read_int_eeprom .1 | |
352 movff EEDATA,year | |
353 read_int_eeprom .2 | |
354 movff EEDATA,month | |
355 read_int_eeprom .3 | |
356 movff EEDATA,day | |
357 read_int_eeprom .4 | |
358 movff EEDATA,hours | |
359 read_int_eeprom .5 | |
360 movff EEDATA,mins | |
361 read_int_eeprom .6 | |
362 movff EEDATA,secs | |
363 call rtc_set_rtc | |
364 | |
365 read_int_eeprom .7 | |
366 movff EEDATA,int_O_CNS_fraction+0 | |
367 read_int_eeprom .8 | |
368 movff EEDATA,int_O_CNS_fraction+1 | |
369 read_int_eeprom .9 | |
370 movff EEDATA,int_O_desaturation_time+0 | |
371 read_int_eeprom .10 | |
372 movff EEDATA,int_O_desaturation_time+1 | |
373 read_int_eeprom .11 | |
374 movff EEDATA,surface_interval+0 | |
375 read_int_eeprom .12 | |
376 movff EEDATA,surface_interval+1 | |
377 read_int_eeprom .13 | |
378 movff EEDATA,int_O_gradient_factor+0 | |
379 read_int_eeprom .14 | |
380 movff EEDATA,int_O_nofly_time+0 | |
381 read_int_eeprom .15 | |
382 movff EEDATA,int_O_nofly_time+1 | |
383 | |
384 ; Tissue data from 16 to 144 | |
385 movlw .16 | |
386 movwf EEADR | |
387 movlw .128 | |
388 movwf lo | |
389 lfsr FSR1,0x700 ; pres_tissue_N2+0, 32*4Byte Float = 128Bytes | |
390 restore_decodata_from_eeprom2: | |
391 call read_eeprom ; EEPROM@EEADR into EEDATA | |
392 movff EEDATA,POSTINC1 | |
393 incf EEADR,F | |
394 decfsz lo,F ; All done? | |
395 bra restore_decodata_from_eeprom2 ; No | |
396 clrf EEADRH | |
397 return | |
398 | |
399 | |
400 global reset_battery_internal_only | |
401 reset_battery_internal_only: | |
402 clrf EEADRH | |
403 clrf EEDATA ; Delete to zero | |
404 write_int_eeprom 0x07 | |
405 write_int_eeprom 0x08 | |
406 write_int_eeprom 0x09 | |
407 write_int_eeprom 0x0A | |
408 write_int_eeprom 0x0B | |
409 write_int_eeprom 0x0C | |
410 banksel battery_gauge+0 | |
411 clrf battery_gauge+0 | |
412 clrf battery_gauge+1 | |
413 clrf battery_gauge+2 | |
414 clrf battery_gauge+3 | |
415 clrf battery_gauge+4 | |
416 clrf battery_gauge+5 | |
417 banksel common | |
418 movlw .100 | |
419 movwf batt_percent | |
420 return | |
421 | |
422 | |
423 global eeprom_reset_logbook_pointers | |
424 eeprom_reset_logbook_pointers: | |
425 clrf EEADRH ; Make sure to select EEPROM bank 0 | |
426 clrf EEDATA | |
427 write_int_eeprom .4 | |
428 write_int_eeprom .5 | |
429 write_int_eeprom .6 | |
430 write_int_eeprom .2 ; Also, delete total dive counter | |
431 write_int_eeprom .3 | |
432 write_int_eeprom .16 | |
433 write_int_eeprom .17 ; And the backup counter, too | |
434 return | |
435 | |
436 END |