Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 609:6341f6663579
TR Battery menu
author | heinrichsweikamp |
---|---|
date | Wed, 09 Jan 2019 15:13:36 +0100 |
parents | ca4556fb60b9 |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File eeprom_rs232.asm V2.99a |
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 ;============================================================================= | |
604 | 28 eeprom code 0xF00000+0x10 |
29 ; skip SERIAL number - it should not be overwritten | |
582 | 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 ;============================================================================= | |
604 | 38 ee_rs232 CODE |
0 | 39 |
582 | 40 global write_int_eeprom_1 |
0 | 41 write_int_eeprom_1: |
42 movwf EEADR | |
604 | 43 bra write_eeprom ; writes and "returns" after write |
582 | 44 |
0 | 45 |
46 global read_int_eeprom_1 | |
47 read_int_eeprom_1: | |
48 movwf EEADR | |
604 | 49 bra read_eeprom ; reads and "returns" after write |
0 | 50 |
51 ;============================================================================= | |
604 | 52 ; reads from internal EEPROM |
53 ; Input: EEADRH:EEADR = EEPROM address | |
54 ; Output: EEDATA | |
55 ; Trashed: NONE | |
0 | 56 global read_eeprom |
582 | 57 read_eeprom: |
0 | 58 bcf EECON1,EEPGD |
59 bcf EECON1,CFGS | |
60 bsf EECON1,RD | |
61 return | |
62 | |
604 | 63 ;============================================================================= |
64 ; writes into internal EEPROM | |
65 ; Input: EEADRH:EEADR = EEPROM address | |
66 ; EEDATA = byte to write | |
67 ; Trashed: WREG | |
68 global write_eeprom | |
69 write_eeprom: | |
70 bcf EECON1,EEPGD | |
71 bcf EECON1,CFGS | |
72 bsf EECON1,WREN | |
73 | |
74 bcf INTCON,GIE ; disable interrupts for the next 5 instructions | |
75 movlw 0x55 | |
76 movwf EECON2 | |
77 movlw 0xAA | |
78 movwf EECON2 | |
79 bsf EECON1,WR | |
80 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! | |
81 | |
82 write_eep2: | |
83 btfsc EECON1,WR | |
84 bra write_eep2 ; wait about 4ms... | |
85 bcf EECON1,WREN | |
86 return | |
87 | |
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 | |
604 | 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 |
604 | 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 | |
604 | 112 movlw .102 ; SPBRGH:SPBRG = .102 : 2403 BAUD @ 16 MHz |
582 | 113 movwf SPBRG2 |
114 movlw b'10010000' | |
115 movwf RCSTA2 | |
116 banksel common | |
604 | 117 bsf ir_power ; power-up IR |
582 | 118 btfss ir_power |
119 bra $-6 | |
120 return | |
0 | 121 |
113 | 122 enable_s8: |
582 | 123 ; Check for Digital/Analog |
604 | 124 bsf s8_npower ; power-down S8 HUD |
125 WAITMS d'1' ; very short delay | |
126 bsf mcp_power ; power-up instrumentation amp | |
582 | 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 |
604 | 135 bcf s8_npower ; power S8 HUD |
136 WAITMS d'1' ; very short delay | |
113 | 137 |
582 | 138 btfsc PORTG,2 ; RX2=1? |
604 | 139 bra enable_s8_2 ; YES - digital |
582 | 140 WAITMS d'30' |
141 btfsc PORTG,2 ; RX2=1? | |
604 | 142 bra enable_s8_2 ; YES - digital |
582 | 143 |
144 ; Not found, set to analog (fail-safe) | |
113 | 145 |
146 enable_s8_analog: | |
582 | 147 ; S8 Analog |
604 | 148 bsf s8_npower ; power-down S8 HUD |
149 bcf s8_digital ; clear flag | |
582 | 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 | |
604 | 158 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16 MHz |
582 | 159 movwf SPBRG2 |
160 movlw b'10010000' | |
161 movwf RCSTA2 | |
162 banksel common | |
604 | 163 bsf s8_digital ; set flag |
582 | 164 return |
113 | 165 |
0 | 166 ;============================================================================= |
582 | 167 |
0 | 168 global enable_rs232 |
169 enable_rs232: | |
604 | 170 call speed_normal ; 16 MHz |
0 | 171 enable_rs232_2: |
582 | 172 movlw T2CON_NORMAL |
173 cpfseq T2CON | |
604 | 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 | |
604 | 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? |
604 | 196 bra rs232_wait_tx ; YES - wait... |
582 | 197 |
198 btfss ble_available ; ble available? | |
604 | 199 return ; NO - done |
582 | 200 |
604 | 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: |
604 | 210 btfss TXSTA2,TRMT ; RS232 busy? |
211 bra rs232_wait_tx2_1 ; YES - wait... | |
582 | 212 banksel common |
604 | 213 return ; done |
113 | 214 |
0 | 215 global rs232_get_byte |
216 rs232_get_byte: | |
582 | 217 bcf rs232_receive_overflow ; clear flag |
604 | 218 clrf uart1_temp ; set uart1_temp to .10 without using WREG: first clear to 0, then... |
219 bsf uart1_temp,1 ; set bit 1 (value 2), | |
220 bsf uart1_temp,3 ; and bit 3 (value 8). | |
582 | 221 clrf uart2_temp |
222 clrf uart3_temp | |
0 | 223 rs232_get_byte2: |
582 | 224 btfsc PIR1,RCIF ; data arrived? |
604 | 225 return ; YES |
582 | 226 decfsz uart3_temp,F |
378 | 227 bra rs232_get_byte2 |
582 | 228 decfsz uart2_temp,F |
229 bra rs232_get_byte2 | |
230 decfsz uart1_temp,F | |
0 | 231 bra rs232_get_byte2 |
582 | 232 ; timeout occurred (about 400ms) |
233 bsf rs232_receive_overflow ; set flag | |
378 | 234 rs232_get_byte3: |
604 | 235 bcf RCSTA1,CREN ; clear receiver status |
0 | 236 bsf RCSTA1,CREN |
582 | 237 return ; and return anyway |
238 | |
239 ;============================================================================= | |
240 | |
241 global do_logoffset_common_write | |
242 do_logoffset_common_write: | |
604 | 243 movlw 0x26 |
244 cpfslt hi ; is offset < 0x26?? (decimal 9983 at max, hence save for another +10) ? | |
245 return ; NO - abort | |
246 movff lo,EEDATA ; YES - proceed writing offset to EEPROM | |
582 | 247 write_int_eeprom 0x0D |
248 movff hi,EEDATA | |
249 write_int_eeprom 0x0E | |
250 return | |
251 | |
252 global do_logoffset_common_read | |
253 do_logoffset_common_read: | |
254 clrf EEADRH | |
255 read_int_eeprom 0x0D | |
256 movff EEDATA,lo | |
257 read_int_eeprom 0x0E | |
604 | 258 movff EEDATA,hi ; existing logbook offset into lo:hi |
582 | 259 return |
260 | |
261 | |
262 global update_battery_registers | |
263 update_battery_registers: | |
264 ; save battery_gauge:6 into EEPROM 0x07-0x0C | |
265 clrf EEADRH | |
266 movff battery_gauge+0,EEDATA | |
267 write_int_eeprom 0x07 | |
268 movff battery_gauge+1,EEDATA | |
269 write_int_eeprom 0x08 | |
270 movff battery_gauge+2,EEDATA | |
271 write_int_eeprom 0x09 | |
272 movff battery_gauge+3,EEDATA | |
273 write_int_eeprom 0x0A | |
274 movff battery_gauge+4,EEDATA | |
275 write_int_eeprom 0x0B | |
276 movff battery_gauge+5,EEDATA | |
277 write_int_eeprom 0x0C | |
278 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 | |
279 write_int_eeprom 0x0F | |
280 return | |
281 | |
282 | |
283 global vault_decodata_into_eeprom | |
284 vault_decodata_into_eeprom: | |
285 ; Vault in EEPROM 512...1023 | |
286 ; Write 0xAA at 512 to indicate valid data in vault | |
287 ; Store last time/date | |
288 ; Store 0x700 to 0x780 (pres_tissue_N2 and pres_tissue_He) | |
289 movlw HIGH .512 ; =2 | |
290 movwf EEADRH | |
291 movlw 0xAA | |
292 movwf EEDATA | |
293 write_int_eeprom .0 | |
294 ; Store date/time | |
295 movff year,EEDATA | |
296 write_int_eeprom .1 | |
297 movff month,EEDATA | |
298 write_int_eeprom .2 | |
299 movff day,EEDATA | |
300 write_int_eeprom .3 | |
301 movff hours,EEDATA | |
302 write_int_eeprom .4 | |
303 movff mins,EEDATA | |
304 write_int_eeprom .5 | |
305 movff secs,EEDATA | |
306 write_int_eeprom .6 | |
307 | |
308 movff int_O_CNS_fraction+0,EEDATA | |
309 write_int_eeprom .7 | |
310 movff int_O_CNS_fraction+1,EEDATA | |
311 write_int_eeprom .8 | |
312 movff int_O_desaturation_time+0,EEDATA | |
313 write_int_eeprom .9 | |
314 movff int_O_desaturation_time+1,EEDATA | |
315 write_int_eeprom .10 | |
316 movff surface_interval+0,EEDATA | |
317 write_int_eeprom .11 | |
318 movff surface_interval+1,EEDATA | |
319 write_int_eeprom .12 | |
320 movff int_O_gradient_factor+0,EEDATA ; value limited to 255, only lower byte in use for value | |
321 write_int_eeprom .13 | |
322 movff int_O_nofly_time+0,EEDATA | |
323 write_int_eeprom .14 | |
324 movff int_O_nofly_time+1,EEDATA | |
325 write_int_eeprom .15 | |
0 | 326 |
582 | 327 ; Tissue data from 16 to 144 |
328 movlw .16 | |
329 movwf EEADR | |
330 movlw .128 | |
331 movwf lo | |
332 lfsr FSR1,0x700 ; pres_tissue_N2+0, 32*4Byte Float = 128Bytes | |
333 vault_decodata_into_eeprom2: | |
334 movff POSTINC1,EEDATA | |
335 call write_eeprom ; EEDATA into EEPROM@EEADR | |
336 incf EEADR,F | |
604 | 337 decfsz lo,F ; all done? |
338 bra vault_decodata_into_eeprom2 ; NO | |
582 | 339 clrf EEADRH |
340 return | |
341 | |
342 global restore_decodata_from_eeprom | |
343 restore_decodata_from_eeprom: | |
344 movlw LOW .512 ; =0 | |
345 movwf EEADR | |
346 movlw HIGH .512 ; =2 | |
347 movwf EEADRH | |
348 | |
349 ; Restore date/time | |
350 read_int_eeprom .1 | |
351 movff EEDATA,year | |
352 read_int_eeprom .2 | |
353 movff EEDATA,month | |
354 read_int_eeprom .3 | |
355 movff EEDATA,day | |
356 read_int_eeprom .4 | |
357 movff EEDATA,hours | |
358 read_int_eeprom .5 | |
359 movff EEDATA,mins | |
360 read_int_eeprom .6 | |
361 movff EEDATA,secs | |
362 call rtc_set_rtc | |
363 | |
364 read_int_eeprom .7 | |
365 movff EEDATA,int_O_CNS_fraction+0 | |
366 read_int_eeprom .8 | |
367 movff EEDATA,int_O_CNS_fraction+1 | |
368 read_int_eeprom .9 | |
369 movff EEDATA,int_O_desaturation_time+0 | |
370 read_int_eeprom .10 | |
371 movff EEDATA,int_O_desaturation_time+1 | |
372 read_int_eeprom .11 | |
373 movff EEDATA,surface_interval+0 | |
374 read_int_eeprom .12 | |
375 movff EEDATA,surface_interval+1 | |
376 read_int_eeprom .13 | |
377 movff EEDATA,int_O_gradient_factor+0 | |
378 read_int_eeprom .14 | |
379 movff EEDATA,int_O_nofly_time+0 | |
380 read_int_eeprom .15 | |
381 movff EEDATA,int_O_nofly_time+1 | |
382 | |
383 ; Tissue data from 16 to 144 | |
384 movlw .16 | |
385 movwf EEADR | |
386 movlw .128 | |
387 movwf lo | |
604 | 388 lfsr FSR1,0x700 ; pres_tissue_N2+0, 32*4Byte Float = 128 Bytes |
582 | 389 restore_decodata_from_eeprom2: |
390 call read_eeprom ; EEPROM@EEADR into EEDATA | |
391 movff EEDATA,POSTINC1 | |
392 incf EEADR,F | |
604 | 393 decfsz lo,F ; all done? |
394 bra restore_decodata_from_eeprom2 ; NO | |
582 | 395 clrf EEADRH |
396 return | |
397 | |
398 | |
399 global reset_battery_internal_only | |
400 reset_battery_internal_only: | |
401 clrf EEADRH | |
604 | 402 clrf EEDATA ; delete to zero |
582 | 403 write_int_eeprom 0x07 |
404 write_int_eeprom 0x08 | |
405 write_int_eeprom 0x09 | |
406 write_int_eeprom 0x0A | |
407 write_int_eeprom 0x0B | |
408 write_int_eeprom 0x0C | |
409 banksel battery_gauge+0 | |
410 clrf battery_gauge+0 | |
411 clrf battery_gauge+1 | |
412 clrf battery_gauge+2 | |
413 clrf battery_gauge+3 | |
414 clrf battery_gauge+4 | |
415 clrf battery_gauge+5 | |
416 banksel common | |
417 movlw .100 | |
418 movwf batt_percent | |
419 return | |
420 | |
421 | |
422 global eeprom_reset_logbook_pointers | |
423 eeprom_reset_logbook_pointers: | |
604 | 424 clrf EEADRH ; make sure to select EEPROM bank 0 |
582 | 425 clrf EEDATA |
426 write_int_eeprom .4 | |
427 write_int_eeprom .5 | |
428 write_int_eeprom .6 | |
604 | 429 write_int_eeprom .2 ; also delete total dive counter |
582 | 430 write_int_eeprom .3 |
431 write_int_eeprom .16 | |
604 | 432 write_int_eeprom .17 ; ...and the backup counter, too |
582 | 433 return |
434 | |
435 END |