Mercurial > public > hwos_code
annotate src/eeprom_rs232.asm @ 628:cd58f7fc86db
3.05 stable work
author | heinrichsweikamp |
---|---|
date | Thu, 19 Sep 2019 12:01:29 +0200 |
parents | c40025d8e750 |
children | 237931377539 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
628 | 3 ; File eeprom_rs232.asm combined next generation V3.04.3 |
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 | |
94 write_eep2: | |
95 btfsc EECON1,WR | |
96 bra write_eep2 ; wait about 4ms... | |
97 bcf EECON1,WREN | |
628 | 98 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! |
604 | 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 |
628 | 111 bcf ir_power ; IR off |
112 bcf mcp_power ; power-down instrumentation amp | |
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: |
628 | 141 banksel TXSTA2 ; select bank for IO register access |
582 | 142 clrf TXSTA2 |
143 clrf RCSTA2 | |
623 | 144 banksel common ; back to bank common |
628 | 145 ; Check for Digital/Analog |
146 bsf s8_npower ; power-down S8 HUD | |
147 WAITMS d'2' ; very short delay | |
148 bsf mcp_power ; power-up instrumentation amp | |
149 btfss mcp_power | |
150 bra $-4 | |
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 | |
628 | 193 bsf PORTJ,2 ; /Reset (for very old OSTC sport) |
623 | 194 ;initialize serial port1 (TRISC6/7) |
582 | 195 movlw b'00100100' ; BRGH=1, SYNC=0 |
196 movwf TXSTA1 | |
197 movlw b'10010000' | |
198 movwf RCSTA1 | |
0 | 199 return |
200 | |
582 | 201 |
0 | 202 global disable_rs232 |
203 disable_rs232: | |
204 clrf RCSTA1 | |
582 | 205 clrf TXSTA1 ; UART disable |
206 bcf PORTC,6 ; TX hard to GND | |
623 | 207 bsf PORTE,0 ; stop comm |
628 | 208 bcf PORTJ,2 ; /Reset (for very old OSTC sport) |
0 | 209 return |
210 | |
582 | 211 |
0 | 212 global rs232_wait_tx |
213 rs232_wait_tx: | |
623 | 214 btfss TXSTA1,TRMT ; RS232 busy? |
604 | 215 bra rs232_wait_tx ; YES - wait... |
582 | 216 |
217 btfss ble_available ; ble available? | |
604 | 218 return ; NO - done |
582 | 219 |
604 | 220 btfsc NRTS ; wait for Bluetooth module |
221 bra rs232_wait_tx ; YES - wait... | |
222 return ; done | |
344
1e342e433839
CHANGE: GF and aGF high range increased to 45-110%
heinrichsweikamp
parents:
276
diff
changeset
|
223 |
0 | 224 |
582 | 225 global rs232_wait_tx2 |
113 | 226 rs232_wait_tx2: |
623 | 227 banksel TXSTA2 ; select bank for IO register access |
228 rs232_wait_tx2_loop: | |
604 | 229 btfss TXSTA2,TRMT ; RS232 busy? |
623 | 230 bra rs232_wait_tx2_loop ; YES - wait... |
231 banksel common ; back to bank common | |
604 | 232 return ; done |
113 | 233 |
623 | 234 |
0 | 235 global rs232_get_byte |
236 rs232_get_byte: | |
623 | 237 bcf rs232_rx_timeout ; clear timeout flag |
238 ; set timeout timer to approx. 400 ms: | |
239 clrf uart_timeout_timer+0 ; set low byte of timeout timer to 0 | |
240 clrf uart_timeout_timer+1 ; set high byte of timeout timer to 0 | |
241 ; set upper byte of timeout timer to 10 without using WREG: | |
242 clrf uart_timeout_timer+2 ; first clear to 0, then... | |
243 bsf uart_timeout_timer+2,1 ; set bit 1 (value 2), | |
244 bsf uart_timeout_timer+2,3 ; and bit 3 (value 8). | |
245 | |
246 rs232_get_byte_loop: | |
247 btfsc PIR1,RCIF ; received a data byte? | |
248 return ; YES - done | |
249 decfsz uart_timeout_timer+0,F ; NO - decrement low byte of timer, became zero? | |
250 bra rs232_get_byte_loop ; NO - loop | |
251 decfsz uart_timeout_timer+1,F ; YES - decrement high byte of timer, became zero? | |
252 bra rs232_get_byte_loop ; NO - loop | |
253 decfsz uart_timeout_timer+2,F ; YES - decrement upper byte of timer, became zero? | |
254 bra rs232_get_byte_loop ; NO - loop | |
255 bsf rs232_rx_timeout ; YES - set timeout flag | |
256 bcf RCSTA1,CREN ; - clear receiver status | |
257 bsf RCSTA1,CREN ; - ... | |
258 return ; - and return anyway | |
582 | 259 |
260 ;============================================================================= | |
261 | |
262 global do_logoffset_common_write | |
263 do_logoffset_common_write: | |
623 | 264 movff lo,EEDATA |
582 | 265 write_int_eeprom 0x0D |
266 movff hi,EEDATA | |
267 write_int_eeprom 0x0E | |
268 return | |
269 | |
270 global do_logoffset_common_read | |
271 do_logoffset_common_read: | |
272 clrf EEADRH | |
273 read_int_eeprom 0x0D | |
274 movff EEDATA,lo | |
275 read_int_eeprom 0x0E | |
623 | 276 movff EEDATA,hi |
582 | 277 return |
278 | |
623 | 279 ;============================================================================= |
582 | 280 |
281 global update_battery_registers | |
282 update_battery_registers: | |
623 | 283 ; save battery gauge to EEPROM 0x07-0x0C |
284 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
582 | 285 clrf EEADRH |
286 movff battery_gauge+0,EEDATA | |
287 write_int_eeprom 0x07 | |
288 movff battery_gauge+1,EEDATA | |
289 write_int_eeprom 0x08 | |
290 movff battery_gauge+2,EEDATA | |
291 write_int_eeprom 0x09 | |
292 movff battery_gauge+3,EEDATA | |
293 write_int_eeprom 0x0A | |
294 movff battery_gauge+4,EEDATA | |
295 write_int_eeprom 0x0B | |
296 movff battery_gauge+5,EEDATA | |
297 write_int_eeprom 0x0C | |
623 | 298 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 | 299 write_int_eeprom 0x0F |
623 | 300 bcf block_battery_gauge ; allow ISR to access the battery gauge again |
582 | 301 return |
302 | |
303 | |
623 | 304 global retrieve_battery_registers |
305 retrieve_battery_registers: | |
306 ; retrieve battery gauge from EEPROM 0x07-0x0C | |
307 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
308 clrf EEADRH | |
309 read_int_eeprom 0x07 | |
310 movff EEDATA,battery_gauge+0 | |
311 read_int_eeprom 0x08 | |
312 movff EEDATA,battery_gauge+1 | |
313 read_int_eeprom 0x09 | |
314 movff EEDATA,battery_gauge+2 | |
315 read_int_eeprom 0x0A | |
316 movff EEDATA,battery_gauge+3 | |
317 read_int_eeprom 0x0B | |
318 movff EEDATA,battery_gauge+4 | |
319 read_int_eeprom 0x0C | |
320 movff EEDATA,battery_gauge+5 | |
321 read_int_eeprom 0x0F | |
322 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 | |
323 bcf block_battery_gauge ; allow ISR to access the battery gauge again | |
324 return | |
325 | |
326 ;============================================================================= | |
327 | |
582 | 328 global vault_decodata_into_eeprom |
329 vault_decodata_into_eeprom: | |
330 ; Vault in EEPROM 512...1023 | |
331 ; Write 0xAA at 512 to indicate valid data in vault | |
332 ; Store last time/date | |
333 ; Store 0x700 to 0x780 (pres_tissue_N2 and pres_tissue_He) | |
334 movlw HIGH .512 ; =2 | |
335 movwf EEADRH | |
623 | 336 |
337 ; indicate valid data in vault | |
582 | 338 movlw 0xAA |
339 movwf EEDATA | |
340 write_int_eeprom .0 | |
623 | 341 |
342 ; store date/time | |
343 SMOVSS rtc_year,rtc_latched_year ; ISR-safe 6 byte copy of date and time | |
344 movff rtc_latched_year+0,EEDATA | |
582 | 345 write_int_eeprom .1 |
623 | 346 movff rtc_latched_year+1,EEDATA |
582 | 347 write_int_eeprom .2 |
623 | 348 movff rtc_latched_year+2,EEDATA |
582 | 349 write_int_eeprom .3 |
623 | 350 movff rtc_latched_year+3,EEDATA |
582 | 351 write_int_eeprom .4 |
623 | 352 movff rtc_latched_year+4,EEDATA |
582 | 353 write_int_eeprom .5 |
623 | 354 movff rtc_latched_year+5,EEDATA |
582 | 355 write_int_eeprom .6 |
356 | |
623 | 357 movff int_O_CNS_current+0,EEDATA ; get current CNS, low byte |
358 write_int_eeprom .7 ; store value | |
359 movff int_O_CNS_current+1,EEDATA ; get current CNS, high byte | |
360 write_int_eeprom .8 ; store value | |
361 | |
362 movff int_O_desaturation_time+0,EEDATA; get desaturation time, low byte | |
363 write_int_eeprom .9 ; store value | |
364 movff int_O_desaturation_time+1,EEDATA; get desaturation time, high byte | |
365 write_int_eeprom .10 ; store value | |
366 | |
367 SMOVII surface_interval,mpr ; ISR-safe copy of surface interval | |
368 movff mpr+0,EEDATA ; get surface interval, low byte | |
369 write_int_eeprom .11 ; store value | |
370 movff mpr+1,EEDATA ; get surface interval, high byte | |
371 write_int_eeprom .12 ; store value | |
372 | |
373 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 | 374 write_int_eeprom .13 |
0 | 375 |
623 | 376 movff int_O_nofly_time+0,EEDATA ; get time, low byte |
377 write_int_eeprom .14 ; store value | |
378 movff int_O_nofly_time+1,EEDATA ; get time, high byte | |
379 write_int_eeprom .15 ; store value | |
380 | |
381 ; tissue data from 16 to 144 | |
582 | 382 movlw .16 |
383 movwf EEADR | |
623 | 384 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte |
582 | 385 movwf lo |
623 | 386 lfsr FSR1,0x700 ; pres_tissue_N2+0 |
582 | 387 vault_decodata_into_eeprom2: |
388 movff POSTINC1,EEDATA | |
389 call write_eeprom ; EEDATA into EEPROM@EEADR | |
390 incf EEADR,F | |
604 | 391 decfsz lo,F ; all done? |
623 | 392 bra vault_decodata_into_eeprom2 ; NO - loop |
393 clrf EEADRH ; YES - reset EEPROM pointer | |
394 return ; - done | |
395 | |
582 | 396 |
397 global restore_decodata_from_eeprom | |
398 restore_decodata_from_eeprom: | |
399 movlw LOW .512 ; =0 | |
400 movwf EEADR | |
401 movlw HIGH .512 ; =2 | |
402 movwf EEADRH | |
403 | |
623 | 404 ; restore date and time |
582 | 405 read_int_eeprom .1 |
623 | 406 movff EEDATA,rtc_latched_year |
582 | 407 read_int_eeprom .2 |
623 | 408 movff EEDATA,rtc_latched_month |
582 | 409 read_int_eeprom .3 |
623 | 410 movff EEDATA,rtc_latched_day |
582 | 411 read_int_eeprom .4 |
623 | 412 movff EEDATA,rtc_latched_hour |
582 | 413 read_int_eeprom .5 |
623 | 414 movff EEDATA,rtc_latched_mins |
582 | 415 read_int_eeprom .6 |
623 | 416 movff EEDATA,rtc_latched_secs |
417 call rtc_set_rtc ; write time and date to RTC module | |
418 | |
419 read_int_eeprom .7 ; read CNS%, low byte | |
420 movff EEDATA,int_O_CNS_current+0 ; restore value | |
421 read_int_eeprom .8 ; read CNS%, high byte | |
422 movff EEDATA,int_O_CNS_current+1 ; restore value | |
582 | 423 |
623 | 424 read_int_eeprom .9 ; read desaturation time, low byte |
425 movff EEDATA,int_O_desaturation_time+0; restore value | |
426 read_int_eeprom .10 ; read desaturation time, high byte | |
427 movff EEDATA,int_O_desaturation_time+1; restore value | |
582 | 428 |
623 | 429 read_int_eeprom .11 ; read surface interval, low byte |
430 movff EEDATA,mpr+0 ; cache value in mpr | |
431 read_int_eeprom .12 ; read surface interval, high byte | |
432 movff EEDATA,mpr+1 ; cache value in mpr | |
433 SMOVII mpr,surface_interval ; ISR-safe copy-back of surface interval | |
434 | |
435 read_int_eeprom .13 ; read leading tissue's supersaturation | |
436 movff EEDATA,int_O_lead_supersat+0 ; restore value | |
437 | |
438 read_int_eeprom .14 ; read no-fly/no-altitude time, low byte | |
439 movff EEDATA,int_O_nofly_time+0 ; restore value | |
440 read_int_eeprom .15 ; read no-fly/no-altitude time, high byte | |
441 movff EEDATA,int_O_nofly_time+1 ; restore value | |
442 | |
443 ; tissue data from 16 to 144 | |
582 | 444 movlw .16 |
445 movwf EEADR | |
623 | 446 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte |
582 | 447 movwf lo |
623 | 448 lfsr FSR1,0x700 ; pres_tissue_N2+0 |
582 | 449 restore_decodata_from_eeprom2: |
450 call read_eeprom ; EEPROM@EEADR into EEDATA | |
451 movff EEDATA,POSTINC1 | |
452 incf EEADR,F | |
604 | 453 decfsz lo,F ; all done? |
623 | 454 bra restore_decodata_from_eeprom2 ; NO - loop |
455 clrf EEADRH ; YES | |
582 | 456 return |
457 | |
623 | 458 ;============================================================================= |
582 | 459 |
623 | 460 global reset_battery_pointer ; called from comm and menu tree |
582 | 461 global reset_battery_internal_only |
623 | 462 reset_battery_pointer: ; reset battery pointer 0x07-0x0C and battery gauge |
463 btfsc battery_gauge_available ; something to reset? | |
464 call lt2942_charge_done ; YES - reset accumulating registers to 0xFFFF | |
582 | 465 reset_battery_internal_only: |
466 clrf EEADRH | |
604 | 467 clrf EEDATA ; delete to zero |
582 | 468 write_int_eeprom 0x07 |
469 write_int_eeprom 0x08 | |
470 write_int_eeprom 0x09 | |
471 write_int_eeprom 0x0A | |
472 write_int_eeprom 0x0B | |
473 write_int_eeprom 0x0C | |
623 | 474 |
475 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge | |
476 banksel battery_gauge ; select bank ISR data | |
477 clrf battery_gauge+0 ; null the battery gauge | |
582 | 478 clrf battery_gauge+1 |
479 clrf battery_gauge+2 | |
480 clrf battery_gauge+3 | |
481 clrf battery_gauge+4 | |
482 clrf battery_gauge+5 | |
623 | 483 banksel common ; back to bank common |
484 bcf block_battery_gauge ; allow ISR to access the battery gauge again | |
485 | |
582 | 486 movlw .100 |
623 | 487 movwf batt_percent ; set battery level to 100% |
582 | 488 return |
489 | |
623 | 490 ;============================================================================= |
582 | 491 |
492 global eeprom_reset_logbook_pointers | |
493 eeprom_reset_logbook_pointers: | |
604 | 494 clrf EEADRH ; make sure to select EEPROM bank 0 |
582 | 495 clrf EEDATA |
496 write_int_eeprom .4 | |
497 write_int_eeprom .5 | |
498 write_int_eeprom .6 | |
604 | 499 write_int_eeprom .2 ; also delete total dive counter |
582 | 500 write_int_eeprom .3 |
501 write_int_eeprom .16 | |
604 | 502 write_int_eeprom .17 ; ...and the backup counter, too |
582 | 503 return |
504 | |
623 | 505 ;============================================================================= |
506 | |
582 | 507 END |