Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 627:bf5fee575701
minor cleanup, reset rx circuity
author | heinrichsweikamp |
---|---|
date | Sun, 30 Jun 2019 23:22:32 +0200 |
parents | c40025d8e750 |
children | cd58f7fc86db |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
623 | 3 ; File eeprom_rs232.asm combined next generation V3.03.1 |
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 | |
623 | 17 extern lt2942_charge_done |
18 | |
19 ;----------------------------------------------------------------------------- | |
20 ; Macros | |
21 | |
582 | 22 write_int_eeprom macro eeprom_address |
23 movlw eeprom_address | |
24 call write_int_eeprom_1 | |
25 endm | |
26 | |
27 read_int_eeprom macro eeprom_address | |
28 movlw eeprom_address | |
29 call read_int_eeprom_1 | |
30 endm | |
31 | |
623 | 32 ;----------------------------------------------------------------------------- |
33 ; Reserved memory locations in EEPROM | |
34 | |
35 eeprom code 0xF00000+0x10 ; skip SERIAL number - it should not be overwritten | |
582 | 36 |
37 global eeprom_serial_save | |
38 global eeprom_opt_backup | |
39 | |
40 eeprom_serial_save res 2 | |
41 eeprom_opt_backup res 0x3E | |
0 | 42 |
623 | 43 ;----------------------------------------------------------------------------- |
44 | |
45 ee_rs232 CODE | |
46 | |
0 | 47 ;============================================================================= |
48 | |
582 | 49 global write_int_eeprom_1 |
0 | 50 write_int_eeprom_1: |
51 movwf EEADR | |
604 | 52 bra write_eeprom ; writes and "returns" after write |
582 | 53 |
0 | 54 |
623 | 55 global read_int_eeprom_1 |
0 | 56 read_int_eeprom_1: |
57 movwf EEADR | |
604 | 58 bra read_eeprom ; reads and "returns" after write |
0 | 59 |
60 ;============================================================================= | |
623 | 61 ; read from internal EEPROM |
62 ; | |
604 | 63 ; Input: EEADRH:EEADR = EEPROM address |
64 ; Output: EEDATA | |
65 ; Trashed: NONE | |
623 | 66 ; |
0 | 67 global read_eeprom |
582 | 68 read_eeprom: |
0 | 69 bcf EECON1,EEPGD |
70 bcf EECON1,CFGS | |
71 bsf EECON1,RD | |
72 return | |
73 | |
604 | 74 ;============================================================================= |
623 | 75 ; write into internal EEPROM |
76 ; | |
604 | 77 ; Input: EEADRH:EEADR = EEPROM address |
78 ; EEDATA = byte to write | |
79 ; Trashed: WREG | |
623 | 80 ; |
604 | 81 global write_eeprom |
82 write_eeprom: | |
83 bcf EECON1,EEPGD | |
84 bcf EECON1,CFGS | |
85 bsf EECON1,WREN | |
86 | |
87 bcf INTCON,GIE ; disable interrupts for the next 5 instructions | |
88 movlw 0x55 | |
89 movwf EECON2 | |
90 movlw 0xAA | |
91 movwf EECON2 | |
92 bsf EECON1,WR | |
93 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! | |
94 | |
95 write_eep2: | |
96 btfsc EECON1,WR | |
97 bra write_eep2 ; wait about 4ms... | |
98 bcf EECON1,WREN | |
99 return | |
100 | |
623 | 101 ;============================================================================= |
102 | |
103 IFDEF _external_sensor | |
604 | 104 |
582 | 105 global disable_ir_s8 |
106 disable_ir_s8: | |
623 | 107 banksel TXSTA2 ; select bank for IO register access |
582 | 108 clrf TXSTA2 |
109 clrf RCSTA2 | |
623 | 110 banksel common ; back to bank common |
582 | 111 bcf ir_power ; IR off |
604 | 112 bcf mcp_power ; power-down instrumentation amp |
623 | 113 bsf s8_npower ; power-down S8 digital interface |
114 bcf s8_digital_avail ; digital S8 interface not available | |
0 | 115 return |
116 | |
117 | |
582 | 118 global enable_ir_s8 |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
151
diff
changeset
|
119 enable_ir_s8: |
623 | 120 ;initialize serial port2 (TRISG2) |
121 btfsc analog_o2_input ; do we have an analog input? | |
122 bra enable_s8 ; YES - search for S8 digital input | |
123 ; NO - start IR digital input | |
124 banksel BAUDCON2 ; - select bank for IO register access | |
125 movlw b'00100000' ; - BRG16=0, inverted for IR | |
113 | 126 movwf BAUDCON2 |
623 | 127 movlw b'00100000' ; - BRGH=0, SYNC=0 |
582 | 128 movwf TXSTA2 |
623 | 129 movlw .102 ; - SPBRGH:SPBRG = .102 : 2403 BAUD @ 16 MHz |
582 | 130 movwf SPBRG2 |
623 | 131 clrf SPBRGH2 |
582 | 132 movlw b'10010000' |
133 movwf RCSTA2 | |
623 | 134 banksel common ; - back to bank common |
135 bsf ir_power ; - power-up IR | |
582 | 136 btfss ir_power |
137 bra $-6 | |
138 return | |
0 | 139 |
113 | 140 enable_s8: |
582 | 141 ; Check for Digital/Analog |
604 | 142 bsf s8_npower ; power-down S8 HUD |
143 WAITMS d'1' ; very short delay | |
144 bsf mcp_power ; power-up instrumentation amp | |
582 | 145 btfss mcp_power |
146 bra $-6 | |
623 | 147 banksel TXSTA2 ; select bank for IO register access |
582 | 148 clrf TXSTA2 |
149 clrf RCSTA2 | |
623 | 150 banksel common ; back to bank common |
113 | 151 |
582 | 152 ; It may be digital, check for voltage when isolator is powered |
604 | 153 bcf s8_npower ; power S8 HUD |
623 | 154 WAITMS d'1' ; wait 1 ms |
582 | 155 btfsc PORTG,2 ; RX2=1? |
604 | 156 bra enable_s8_2 ; YES - digital |
623 | 157 WAITMS d'30' ; NO - wait 30 ms |
158 btfsc PORTG,2 ; - RX2=1? | |
159 bra enable_s8_2 ; YES - digital | |
160 ;bra enable_s8_analog ; NO - not found, set to analog (fail-safe) | |
113 | 161 |
162 enable_s8_analog: | |
623 | 163 ; S8 analog interface |
604 | 164 bsf s8_npower ; power-down S8 HUD |
623 | 165 bcf s8_digital_avail ; digital S8 interface not available |
582 | 166 return |
113 | 167 |
623 | 168 enable_s8_2: ; configure S8 digital interface |
169 banksel BAUDCON2 ; select bank for IO register access | |
170 movlw b'00000000' ; BRG16=0, normal for S8 | |
113 | 171 movwf BAUDCON2 |
582 | 172 movlw b'00100000' ; BRGH=0, SYNC=0 |
173 movwf TXSTA2 | |
604 | 174 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16 MHz |
582 | 175 movwf SPBRG2 |
176 movlw b'10010000' | |
177 movwf RCSTA2 | |
623 | 178 banksel common ; back to bank common |
179 bsf s8_digital_avail ; digital S8 interface available | |
582 | 180 return |
113 | 181 |
623 | 182 ENDIF ; _external_sensor |
183 | |
0 | 184 ;============================================================================= |
582 | 185 |
0 | 186 global enable_rs232 |
187 enable_rs232: | |
623 | 188 call request_speed_normal ; request CPU speed change to normal speed |
189 enable_rs232_1: | |
190 btfss speed_is_normal ; speed = normal? | |
191 bra enable_rs232_1 ; NO - wait for ISR to adjust speed | |
192 bcf PORTE,0 ; start comm | |
193 ;initialize serial port1 (TRISC6/7) | |
582 | 194 movlw b'00100100' ; BRGH=1, SYNC=0 |
195 movwf TXSTA1 | |
196 movlw b'10010000' | |
197 movwf RCSTA1 | |
0 | 198 return |
199 | |
582 | 200 |
0 | 201 global disable_rs232 |
202 disable_rs232: | |
203 clrf RCSTA1 | |
582 | 204 clrf TXSTA1 ; UART disable |
205 bcf PORTC,6 ; TX hard to GND | |
623 | 206 bsf PORTE,0 ; stop comm |
0 | 207 return |
208 | |
582 | 209 |
0 | 210 global rs232_wait_tx |
211 rs232_wait_tx: | |
623 | 212 btfss TXSTA1,TRMT ; RS232 busy? |
604 | 213 bra rs232_wait_tx ; YES - wait... |
582 | 214 |
215 btfss ble_available ; ble available? | |
604 | 216 return ; NO - done |
582 | 217 |
604 | 218 btfsc NRTS ; wait for Bluetooth module |
219 bra rs232_wait_tx ; YES - wait... | |
220 return ; done | |
344
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
221 |
0 | 222 |
582 | 223 global rs232_wait_tx2 |
113 | 224 rs232_wait_tx2: |
623 | 225 banksel TXSTA2 ; select bank for IO register access |
226 rs232_wait_tx2_loop: | |
604 | 227 btfss TXSTA2,TRMT ; RS232 busy? |
623 | 228 bra rs232_wait_tx2_loop ; YES - wait... |
229 banksel common ; back to bank common | |
604 | 230 return ; done |
113 | 231 |
623 | 232 |
0 | 233 global rs232_get_byte |
234 rs232_get_byte: | |
623 | 235 bcf rs232_rx_timeout ; clear timeout flag |
236 ; set timeout timer to approx. 400 ms: | |
237 clrf uart_timeout_timer+0 ; set low byte of timeout timer to 0 | |
238 clrf uart_timeout_timer+1 ; set high byte of timeout timer to 0 | |
239 ; set upper byte of timeout timer to 10 without using WREG: | |
240 clrf uart_timeout_timer+2 ; first clear to 0, then... | |
241 bsf uart_timeout_timer+2,1 ; set bit 1 (value 2), | |
242 bsf uart_timeout_timer+2,3 ; and bit 3 (value 8). | |
243 | |
244 rs232_get_byte_loop: | |
245 btfsc PIR1,RCIF ; received a data byte? | |
246 return ; YES - done | |
247 decfsz uart_timeout_timer+0,F ; NO - decrement low byte of timer, became zero? | |
248 bra rs232_get_byte_loop ; NO - loop | |
249 decfsz uart_timeout_timer+1,F ; YES - decrement high byte of timer, became zero? | |
250 bra rs232_get_byte_loop ; NO - loop | |
251 decfsz uart_timeout_timer+2,F ; YES - decrement upper byte of timer, became zero? | |
252 bra rs232_get_byte_loop ; NO - loop | |
253 bsf rs232_rx_timeout ; YES - set timeout flag | |
254 bcf RCSTA1,CREN ; - clear receiver status | |
255 bsf RCSTA1,CREN ; - ... | |
256 return ; - and return anyway | |
582 | 257 |
258 ;============================================================================= | |
259 | |
260 global do_logoffset_common_write | |
261 do_logoffset_common_write: | |
623 | 262 movff lo,EEDATA |
582 | 263 write_int_eeprom 0x0D |
264 movff hi,EEDATA | |
265 write_int_eeprom 0x0E | |
266 return | |
267 | |
268 global do_logoffset_common_read | |
269 do_logoffset_common_read: | |
270 clrf EEADRH | |
271 read_int_eeprom 0x0D | |
272 movff EEDATA,lo | |
273 read_int_eeprom 0x0E | |
623 | 274 movff EEDATA,hi |
582 | 275 return |
276 | |
623 | 277 ;============================================================================= |
582 | 278 |
279 global update_battery_registers | |
280 update_battery_registers: | |
623 | 281 ; save battery gauge to EEPROM 0x07-0x0C |
282 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
582 | 283 clrf EEADRH |
284 movff battery_gauge+0,EEDATA | |
285 write_int_eeprom 0x07 | |
286 movff battery_gauge+1,EEDATA | |
287 write_int_eeprom 0x08 | |
288 movff battery_gauge+2,EEDATA | |
289 write_int_eeprom 0x09 | |
290 movff battery_gauge+3,EEDATA | |
291 write_int_eeprom 0x0A | |
292 movff battery_gauge+4,EEDATA | |
293 write_int_eeprom 0x0B | |
294 movff battery_gauge+5,EEDATA | |
295 write_int_eeprom 0x0C | |
623 | 296 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 |
582 | 297 write_int_eeprom 0x0F |
623 | 298 bcf block_battery_gauge ; allow ISR to access the battery gauge again |
582 | 299 return |
300 | |
301 | |
623 | 302 global retrieve_battery_registers |
303 retrieve_battery_registers: | |
304 ; retrieve battery gauge from EEPROM 0x07-0x0C | |
305 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
306 clrf EEADRH | |
307 read_int_eeprom 0x07 | |
308 movff EEDATA,battery_gauge+0 | |
309 read_int_eeprom 0x08 | |
310 movff EEDATA,battery_gauge+1 | |
311 read_int_eeprom 0x09 | |
312 movff EEDATA,battery_gauge+2 | |
313 read_int_eeprom 0x0A | |
314 movff EEDATA,battery_gauge+3 | |
315 read_int_eeprom 0x0B | |
316 movff EEDATA,battery_gauge+4 | |
317 read_int_eeprom 0x0C | |
318 movff EEDATA,battery_gauge+5 | |
319 read_int_eeprom 0x0F | |
320 movff EEDATA,battery_type ; =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 | |
321 bcf block_battery_gauge ; allow ISR to access the battery gauge again | |
322 return | |
323 | |
324 ;============================================================================= | |
325 | |
582 | 326 global vault_decodata_into_eeprom |
327 vault_decodata_into_eeprom: | |
328 ; Vault in EEPROM 512...1023 | |
329 ; Write 0xAA at 512 to indicate valid data in vault | |
330 ; Store last time/date | |
331 ; Store 0x700 to 0x780 (pres_tissue_N2 and pres_tissue_He) | |
332 movlw HIGH .512 ; =2 | |
333 movwf EEADRH | |
623 | 334 |
335 ; indicate valid data in vault | |
582 | 336 movlw 0xAA |
337 movwf EEDATA | |
338 write_int_eeprom .0 | |
623 | 339 |
340 ; store date/time | |
341 SMOVSS rtc_year,rtc_latched_year ; ISR-safe 6 byte copy of date and time | |
342 movff rtc_latched_year+0,EEDATA | |
582 | 343 write_int_eeprom .1 |
623 | 344 movff rtc_latched_year+1,EEDATA |
582 | 345 write_int_eeprom .2 |
623 | 346 movff rtc_latched_year+2,EEDATA |
582 | 347 write_int_eeprom .3 |
623 | 348 movff rtc_latched_year+3,EEDATA |
582 | 349 write_int_eeprom .4 |
623 | 350 movff rtc_latched_year+4,EEDATA |
582 | 351 write_int_eeprom .5 |
623 | 352 movff rtc_latched_year+5,EEDATA |
582 | 353 write_int_eeprom .6 |
354 | |
623 | 355 movff int_O_CNS_current+0,EEDATA ; get current CNS, low byte |
356 write_int_eeprom .7 ; store value | |
357 movff int_O_CNS_current+1,EEDATA ; get current CNS, high byte | |
358 write_int_eeprom .8 ; store value | |
359 | |
360 movff int_O_desaturation_time+0,EEDATA; get desaturation time, low byte | |
361 write_int_eeprom .9 ; store value | |
362 movff int_O_desaturation_time+1,EEDATA; get desaturation time, high byte | |
363 write_int_eeprom .10 ; store value | |
364 | |
365 SMOVII surface_interval,mpr ; ISR-safe copy of surface interval | |
366 movff mpr+0,EEDATA ; get surface interval, low byte | |
367 write_int_eeprom .11 ; store value | |
368 movff mpr+1,EEDATA ; get surface interval, high byte | |
369 write_int_eeprom .12 ; store value | |
370 | |
371 movff int_O_lead_supersat+0,EEDATA ; get leading tissue's supersaturation, value is limited to 255 so only the lower byte is used for the value | |
582 | 372 write_int_eeprom .13 |
0 | 373 |
623 | 374 movff int_O_nofly_time+0,EEDATA ; get time, low byte |
375 write_int_eeprom .14 ; store value | |
376 movff int_O_nofly_time+1,EEDATA ; get time, high byte | |
377 write_int_eeprom .15 ; store value | |
378 | |
379 ; tissue data from 16 to 144 | |
582 | 380 movlw .16 |
381 movwf EEADR | |
623 | 382 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte |
582 | 383 movwf lo |
623 | 384 lfsr FSR1,0x700 ; pres_tissue_N2+0 |
582 | 385 vault_decodata_into_eeprom2: |
386 movff POSTINC1,EEDATA | |
387 call write_eeprom ; EEDATA into EEPROM@EEADR | |
388 incf EEADR,F | |
604 | 389 decfsz lo,F ; all done? |
623 | 390 bra vault_decodata_into_eeprom2 ; NO - loop |
391 clrf EEADRH ; YES - reset EEPROM pointer | |
392 return ; - done | |
393 | |
582 | 394 |
395 global restore_decodata_from_eeprom | |
396 restore_decodata_from_eeprom: | |
397 movlw LOW .512 ; =0 | |
398 movwf EEADR | |
399 movlw HIGH .512 ; =2 | |
400 movwf EEADRH | |
401 | |
623 | 402 ; restore date and time |
582 | 403 read_int_eeprom .1 |
623 | 404 movff EEDATA,rtc_latched_year |
582 | 405 read_int_eeprom .2 |
623 | 406 movff EEDATA,rtc_latched_month |
582 | 407 read_int_eeprom .3 |
623 | 408 movff EEDATA,rtc_latched_day |
582 | 409 read_int_eeprom .4 |
623 | 410 movff EEDATA,rtc_latched_hour |
582 | 411 read_int_eeprom .5 |
623 | 412 movff EEDATA,rtc_latched_mins |
582 | 413 read_int_eeprom .6 |
623 | 414 movff EEDATA,rtc_latched_secs |
415 call rtc_set_rtc ; write time and date to RTC module | |
416 | |
417 read_int_eeprom .7 ; read CNS%, low byte | |
418 movff EEDATA,int_O_CNS_current+0 ; restore value | |
419 read_int_eeprom .8 ; read CNS%, high byte | |
420 movff EEDATA,int_O_CNS_current+1 ; restore value | |
582 | 421 |
623 | 422 read_int_eeprom .9 ; read desaturation time, low byte |
423 movff EEDATA,int_O_desaturation_time+0; restore value | |
424 read_int_eeprom .10 ; read desaturation time, high byte | |
425 movff EEDATA,int_O_desaturation_time+1; restore value | |
582 | 426 |
623 | 427 read_int_eeprom .11 ; read surface interval, low byte |
428 movff EEDATA,mpr+0 ; cache value in mpr | |
429 read_int_eeprom .12 ; read surface interval, high byte | |
430 movff EEDATA,mpr+1 ; cache value in mpr | |
431 SMOVII mpr,surface_interval ; ISR-safe copy-back of surface interval | |
432 | |
433 read_int_eeprom .13 ; read leading tissue's supersaturation | |
434 movff EEDATA,int_O_lead_supersat+0 ; restore value | |
435 | |
436 read_int_eeprom .14 ; read no-fly/no-altitude time, low byte | |
437 movff EEDATA,int_O_nofly_time+0 ; restore value | |
438 read_int_eeprom .15 ; read no-fly/no-altitude time, high byte | |
439 movff EEDATA,int_O_nofly_time+1 ; restore value | |
440 | |
441 ; tissue data from 16 to 144 | |
582 | 442 movlw .16 |
443 movwf EEADR | |
623 | 444 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte |
582 | 445 movwf lo |
623 | 446 lfsr FSR1,0x700 ; pres_tissue_N2+0 |
582 | 447 restore_decodata_from_eeprom2: |
448 call read_eeprom ; EEPROM@EEADR into EEDATA | |
449 movff EEDATA,POSTINC1 | |
450 incf EEADR,F | |
604 | 451 decfsz lo,F ; all done? |
623 | 452 bra restore_decodata_from_eeprom2 ; NO - loop |
453 clrf EEADRH ; YES | |
582 | 454 return |
455 | |
623 | 456 ;============================================================================= |
582 | 457 |
623 | 458 global reset_battery_pointer ; called from comm and menu tree |
582 | 459 global reset_battery_internal_only |
623 | 460 reset_battery_pointer: ; reset battery pointer 0x07-0x0C and battery gauge |
461 btfsc battery_gauge_available ; something to reset? | |
462 call lt2942_charge_done ; YES - reset accumulating registers to 0xFFFF | |
582 | 463 reset_battery_internal_only: |
464 clrf EEADRH | |
604 | 465 clrf EEDATA ; delete to zero |
582 | 466 write_int_eeprom 0x07 |
467 write_int_eeprom 0x08 | |
468 write_int_eeprom 0x09 | |
469 write_int_eeprom 0x0A | |
470 write_int_eeprom 0x0B | |
471 write_int_eeprom 0x0C | |
623 | 472 |
473 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
474 banksel battery_gauge ; select bank ISR data | |
475 clrf battery_gauge+0 ; null the battery gauge | |
582 | 476 clrf battery_gauge+1 |
477 clrf battery_gauge+2 | |
478 clrf battery_gauge+3 | |
479 clrf battery_gauge+4 | |
480 clrf battery_gauge+5 | |
623 | 481 banksel common ; back to bank common |
482 bcf block_battery_gauge ; allow ISR to access the battery gauge again | |
483 | |
582 | 484 movlw .100 |
623 | 485 movwf batt_percent ; set battery level to 100% |
582 | 486 return |
487 | |
623 | 488 ;============================================================================= |
582 | 489 |
490 global eeprom_reset_logbook_pointers | |
491 eeprom_reset_logbook_pointers: | |
604 | 492 clrf EEADRH ; make sure to select EEPROM bank 0 |
582 | 493 clrf EEDATA |
494 write_int_eeprom .4 | |
495 write_int_eeprom .5 | |
496 write_int_eeprom .6 | |
604 | 497 write_int_eeprom .2 ; also delete total dive counter |
582 | 498 write_int_eeprom .3 |
499 write_int_eeprom .16 | |
604 | 500 write_int_eeprom .17 ; ...and the backup counter, too |
582 | 501 return |
502 | |
623 | 503 ;============================================================================= |
504 | |
582 | 505 END |