comparison src/eeprom_rs232.asm @ 631:185ba2f91f59

3.09 beta 1 release
author heinrichsweikamp
date Fri, 28 Feb 2020 15:45:07 +0100
parents 237931377539
children 4050675965ea
comparison
equal deleted inserted replaced
630:4cd81bdbf15c 631:185ba2f91f59
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File eeprom_rs232.asm combined next generation V3.06.2 3 ; File eeprom_rs232.asm combined next generation V3.08.8
4 ; 4 ;
5 ; Internal EEPROM, RS232 5 ; Internal EEPROM, RS232
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
11 11
12 #include "hwos.inc" 12 #include "hwos.inc"
13 #include "wait.inc" 13 #include "wait.inc"
14 #include "shared_definitions.h" 14 #include "shared_definitions.h"
15 #include "rtc.inc" 15 #include "rtc.inc"
16 #include "external_flash.inc"
17
18 #DEFINE INSIDE_EEPROM_RS232
19 #include "eeprom_rs232.inc"
20
16 21
17 extern lt2942_charge_done 22 extern lt2942_charge_done
18 23
19 ;----------------------------------------------------------------------------- 24 ;-----------------------------------------------------------------------------
20 ; Macros 25 ;
21 26 ; for EEPROM Macros and Memory Map, see eeprom_rs232.inc
22 write_int_eeprom macro eeprom_address 27 ;
23 movlw eeprom_address 28 ;-----------------------------------------------------------------------------
24 call write_int_eeprom_1 29
25 endm 30 ee_rs232 CODE
26 31
27 read_int_eeprom macro eeprom_address 32 ;=============================================================================
28 movlw eeprom_address 33 ; EEPROM Functions
29 call read_int_eeprom_1 34 ;=============================================================================
30 endm 35
31 36 ;-----------------------------------------------------------------------------
32 ;-----------------------------------------------------------------------------
33 ; Reserved memory locations in EEPROM
34
35 eeprom code 0xF00000+0x10 ; skip SERIAL number - it should not be overwritten
36
37 global eeprom_serial_save
38 global eeprom_opt_backup
39
40 eeprom_serial_save res 2
41 eeprom_opt_backup res 0x3E
42
43 ;-----------------------------------------------------------------------------
44
45 ee_rs232 CODE
46
47 ;=============================================================================
48
49 global write_int_eeprom_1
50 write_int_eeprom_1:
51 movwf EEADR
52 bra write_eeprom ; writes and "returns" after write
53
54
55 global read_int_eeprom_1
56 read_int_eeprom_1:
57 movwf EEADR
58 bra read_eeprom ; reads and "returns" after write
59
60 ;=============================================================================
61 ; read from internal EEPROM 37 ; read from internal EEPROM
62 ; 38 ;
63 ; Input: EEADRH:EEADR = EEPROM address 39 ; Input: EEADRH:EEADR = EEPROM address
64 ; Output: EEDATA 40 ; Output: EEDATA
65 ; Trashed: NONE 41 ; Trashed: NONE
66 ; 42 ;
67 global read_eeprom 43 global read_eeprom
68 read_eeprom: 44 read_eeprom:
69 bcf EECON1,EEPGD 45 bcf EECON1,EEPGD ;
70 bcf EECON1,CFGS 46 bcf EECON1,CFGS ;
71 bsf EECON1,RD 47 bsf EECON1,RD ;
72 return 48 return
73 49
74 ;============================================================================= 50 ;-----------------------------------------------------------------------------
75 ; write into internal EEPROM 51 ; write into internal EEPROM
76 ; 52 ;
77 ; Input: EEADRH:EEADR = EEPROM address 53 ; Input: EEADRH:EEADR = EEPROM address
78 ; EEDATA = byte to write 54 ; EEDATA = byte to write
79 ; Trashed: WREG 55 ; Trashed: WREG
80 ; 56 ;
81 global write_eeprom 57 global write_eeprom
82 write_eeprom: 58 write_eeprom:
83 bcf EECON1,EEPGD 59 bcf EECON1,EEPGD ;
84 bcf EECON1,CFGS 60 bcf EECON1,CFGS ;
85 bsf EECON1,WREN 61 bsf EECON1,WREN ;
86 62 bcf INTCON,GIE ; disable interrupts for the next 5 instructions
87 bcf INTCON,GIE ; disable interrupts for the next 5 instructions 63 movlw 0x55 ; unlock sequence
88 movlw 0x55 64 movwf EECON2 ; ...
89 movwf EECON2 65 movlw 0xAA ; ...
90 movlw 0xAA 66 movwf EECON2 ; ...
91 movwf EECON2 67 bsf EECON1,WR ; start write operation
92 bsf EECON1,WR 68 write_eeprom_loop:
93 69 btfsc EECON1,WR ; write completed?
94 write_eep2: 70 bra write_eeprom_loop ; NO - loop waiting
95 btfsc EECON1,WR 71 bcf EECON1,WREN ;
96 bra write_eep2 ; wait about 4ms... 72 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now!
97 bcf EECON1,WREN 73 return
98 bsf INTCON,GIE ; ...but the flag for the ISR routines were still set, so they will interrupt now! 74
99 return 75 ;-----------------------------------------------------------------------------
100 76 ; these 2 functions are meant to be used through the macros, see eeprom_rs232!
77 ;
78 global eeprom_read_common
79 eeprom_read_common:
80 movwf eeprom_loop ; initialize loop counter
81 eeprom_read_common_loop:
82 rcall read_eeprom ; execute read
83 movff EEDATA,POSTINC1 ; copy byte from EEPROM data register to memory
84 incf EEADR,F ; advance to next EEPROM cell
85 decfsz eeprom_loop,F ; decrement loop counter, all done?
86 bra eeprom_read_common_loop ; NO - loop
87 return ; YES - done
88
89 global eeprom_write_common
90 eeprom_write_common:
91 movwf eeprom_loop ; initialize loop counter
92 eeprom_write_common_loop:
93 movff POSTINC1,EEDATA ; copy byte from memory to EEPROM data register
94 rcall write_eeprom ; execute write
95 incf EEADR,F ; advance to next EEPROM cell
96 decfsz eeprom_loop,F ; decrement loop counter, all done?
97 bra eeprom_write_common_loop ; NO - loop
98 return ; YES - done
99
100 ;-----------------------------------------------------------------------------
101 ; REad OSTC serial number
102 ;
103 global eeprom_serial_number_read
104 eeprom_serial_number_read:
105 EEPROM_II_READ eeprom_ostc_serial,mpr
106 return
107
108 ;-----------------------------------------------------------------------------
109 ; Read and write dive number offset
110 ;
111 global eeprom_log_offset_read
112 eeprom_log_offset_read:
113 EEPROM_II_READ eeprom_log_offset,mpr
114 return
115
116 global eeprom_log_offset_write
117 eeprom_log_offset_write:
118 EEPROM_II_WRITE mpr,eeprom_log_offset
119 return
120
121
122 ;-----------------------------------------------------------------------------
123 ; Read and write total number of dives
124 ;
125 global eeprom_total_dives_read
126 eeprom_total_dives_read:
127 EEPROM_II_READ eeprom_num_dives,mpr
128 return
129
130 global eeprom_total_dives_write
131 eeprom_total_dives_write:
132 EEPROM_II_WRITE mpr,eeprom_num_dives
133 return
134
135
136 ;-----------------------------------------------------------------------------
137 ; Read and write the battery gauge and type
138 ;
139 global eeprom_battery_gauge_read
140 eeprom_battery_gauge_read:
141 ; retrieve battery gauge from EEPROM 0x07-0x0C
142 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge
143 EEPROM_CC_READ eeprom_battery_type, battery_type ; 1 byte read from EEPROM
144 EEPROM_RR_READ eeprom_battery_gauge,battery_gauge,.6 ; 6 byte read from EEPROM
145 bcf block_battery_gauge ; allow ISR to access the battery gauge again
146 return
147
148 global eeprom_battery_gauge_write
149 eeprom_battery_gauge_write:
150 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge
151 EEPROM_CC_WRITE battery_type, eeprom_battery_type ; 1 byte write to EEPROM
152 update_battery_gauge:
153 EEPROM_RR_WRITE battery_gauge,eeprom_battery_gauge,.6 ; 6 byte write to EEPROM
154 bcf block_battery_gauge ; allow ISR to access the battery gauge again
155 return
156
157
158 ;-----------------------------------------------------------------------------
159 ; Read and write the deco status
160 ;
161 global eeprom_deco_data_read
162 eeprom_deco_data_read:
163
164 btfsc RCON,POR ; was there a power outage ?
165 bra eeprom_deco_data_read_1 ; NO - RTC is up-to-date
166
167 EEPROM_RR_READ eeprom_deco_data_timestamp,rtc_latched_year,.6 ; 6 byte read from EEPROM
168 call rtc_set_rtc ; recover RTC to last known time & date
169
170 eeprom_deco_data_read_1:
171
172 ; restore surface interval
173 EEPROM_II_READ eeprom_deco_data_surfinterval,mpr ; 2 byte read from EEPROM
174 SMOVII mpr,surface_interval_mins ; ISR-safe copy of surface interval
175
176 ; bank 3: restore desaturation status
177 EEPROM_RR_READ eeprom_deco_data_bank3,0x300,.9 ; 9 byte read from EEPROM
178
179 ; bank 5: restore CNS
180 EEPROM_RR_READ eeprom_deco_data_bank5,0x500,.4 ; 4 byte read from EEPROM
181
182 ; bank 7: restore tissue pressures
183 EEPROM_RR_READ eeprom_deco_data_bank7,0x700,.128 ; 128 byte read from EEPROM
184
185 return ; done
186
187
188 global eeprom_deco_data_write
189 eeprom_deco_data_write:
190
191 ; invalidate current data in vault
192 movlw DECO_DATA_INVALID_TOKEN ; deco data invalid token
193 EEPROM_CC_WRITE WREG,eeprom_deco_data_validity ; 1 byte write to EEPROM
194
195 ; store vault version
196 movlw eeprom_vault_version ; deco data format version
197 EEPROM_CC_WRITE WREG,eeprom_deco_data_version ; 1 byte write to EEPROM
198
199 ; store date/time
200 SMOVSS rtc_year,rtc_latched_year ; ISR-safe 6 byte copy of date and time
201 EEPROM_RR_WRITE rtc_latched_year,eeprom_deco_data_timestamp,.6 ; 6 byte write to EEPROM
202
203 ; store surface interval
204 SMOVII surface_interval_mins,mpr ; ISR-safe copy of surface interval
205 EEPROM_II_WRITE mpr,eeprom_deco_data_surfinterval ; 2 byte write to EEPROM
206
207 ; bank 3: store desaturation status
208 EEPROM_RR_WRITE 0x300,eeprom_deco_data_bank3,.9 ; 9 byte write to EEPROM
209
210 ; bank 5: store CNS
211 EEPROM_RR_WRITE 0x500,eeprom_deco_data_bank5,.4 ; 4 byte write to EEPROM
212
213 ; bank 7: store tissue pressures
214 EEPROM_RR_WRITE 0x700,eeprom_deco_data_bank7,.128 ; 128 byte write to EEPROM
215
216 ; indicate new valid data in vault
217 movlw DECO_DATA_VALID_TOKEN ; deco data valid token
218 EEPROM_CC_WRITE WREG,eeprom_deco_data_validity ; 1 byte write to EEPROM
219
220 return ; done
221
222
223
224 ;=============================================================================
225 ; RS232 Functions
101 ;============================================================================= 226 ;=============================================================================
102 227
103 global disable_ir_s8 228 global disable_ir_s8
104 disable_ir_s8: 229 disable_ir_s8:
105 banksel TXSTA2 ; select bank for IO register access 230 banksel TXSTA2 ; select bank for IO register access
137 bsf PIE3,RC2IE ; - enable RC2 INT 262 bsf PIE3,RC2IE ; - enable RC2 INT
138 return ; - done 263 return ; - done
139 264
140 enable_s8: 265 enable_s8:
141 banksel TXSTA2 ; select bank for IO register access 266 banksel TXSTA2 ; select bank for IO register access
142 clrf TXSTA2 267 clrf TXSTA2 ; reset UART 2 TX function
143 clrf RCSTA2 268 clrf RCSTA2 ; reset UART 2 RX function
144 banksel common ; back to bank common 269 banksel common ; back to bank common
145 ; Check for Digital/Analog 270
146 bsf s8_npower ; power-down S8 HUD 271 bsf mcp_power ; power-up instrumentation amp (for analog AND digital)
147 WAITMS d'2' ; very short delay 272 btfss mcp_power ; power-up completed?
148 bsf mcp_power ; power-up instrumentation amp 273 bra $-4 ; NO - loop
149 btfss mcp_power 274
150 bra $-4 275 ; toggle for digital/analog
151 276 TSTOSS opt_s8_mode ; =0: analog, =1: digital RS232
152 ; It may be digital, check for voltage when isolator is powered 277 bra enable_s8_analog ; -> analog
153 bcf s8_npower ; power S8 HUD 278
154 WAITMS d'1' ; wait 1 ms 279 ; configure S8 digital interface
155 btfsc PORTG,2 ; RX2=1? 280 bcf s8_npower ; power S8 HUD (inverted via P-MOS transistor)
156 bra enable_s8_2 ; YES - digital
157 WAITMS d'30' ; NO - wait 30 ms 281 WAITMS d'30' ; NO - wait 30 ms
158 btfsc PORTG,2 ; - RX2=1? 282 banksel BAUDCON2 ; select bank for IO register access
159 bra enable_s8_2 ; YES - digital
160 ;bra enable_s8_analog ; NO - not found, set to analog (fail-safe)
161
162 enable_s8_analog:
163 ; S8 analog interface
164 bsf s8_npower ; power-down S8 HUD
165 bcf s8_digital_avail ; digital S8 interface not available
166 return
167
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 283 movlw b'00000000' ; BRG16=0, normal for S8
171 movwf BAUDCON2 284 movwf BAUDCON2
172 movlw b'00100000' ; BRGH=0, SYNC=0 285 movlw b'00100000' ; BRGH=0, SYNC=0
173 movwf TXSTA2 286 movwf TXSTA2
174 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16 MHz 287 movlw .25 ; SPBRGH:SPBRG = .25 : 9615 BAUD @ 16 MHz
175 movwf SPBRG2 288 movwf SPBRG2
176 movlw b'10010000' 289 movlw b'10010000'
177 movwf RCSTA2 290 movwf RCSTA2
178 banksel common ; back to bank common 291 banksel common ; back to bank common
292 bsf PIE3,RC2IE ; enable RC2 INT
179 bsf s8_digital_avail ; digital S8 interface available 293 bsf s8_digital_avail ; digital S8 interface available
180 return 294 return
181 295
182 ;============================================================================= 296 enable_s8_analog:
297 ; S8 analog interface
298 bcf PIE3,RC2IE ; disable RC2 INT
299 bsf s8_npower ; power-down S8 HUD
300 bcf s8_digital_avail ; digital S8 interface not available
301 return
302
303
304 global ir_s8_wait_tx
305 ir_s8_wait_tx:
306 banksel TXSTA2 ; select bank for IO register access
307 rs232_wait_tx2_loop:
308 btfss TXSTA2,TRMT ; RS232 busy?
309 bra rs232_wait_tx2_loop ; YES - wait...
310 banksel common ; NO - back to bank common
311 return ; - done
312
313 ;-----------------------------------------------------------------------------
183 314
184 global enable_rs232 315 global enable_rs232
185 enable_rs232: 316 enable_rs232:
186 call request_speed_normal ; request CPU speed change to normal speed 317 call request_speed_normal ; request CPU speed change to normal speed
187 enable_rs232_1: 318 enable_rs232_1:
188 btfss speed_is_normal ; speed = normal? 319 btfss speed_is_normal ; speed = normal?
189 bra enable_rs232_1 ; NO - wait for ISR to adjust speed 320 bra enable_rs232_1 ; NO - loop waiting for ISR to have adjusted the speed
190 bcf PORTE,0 ; start comm 321 bcf PORTE,0 ; YES - switch port to comm
191 bsf PORTJ,2 ; /Reset (for very old OSTC sport) 322 bsf PORTJ,2 ; - /Reset (required for very old OSTC sport)
192 ;initialize serial port1 (TRISC6/7) 323 movlw b'00100100' ; - TX configuration: TX enabled, async, high speed
193 movlw b'00100100' ; BRGH=1, SYNC=0 324 movwf TXSTA1 ; - ...
194 movwf TXSTA1 325 movlw b'10010000' ; - RX configuration: port enabled, RX enabled
195 movlw b'10010000' 326 movwf RCSTA1 ; - ...
196 movwf RCSTA1 327 movlw HIGH(.65536-rx_timeout*.32) ; - define TMR5H initialization value for RX timeout
197 return 328 movwf rx_timoeut_tmr5h_load ; - store for later use
329 return ; - done
198 330
199 331
200 global disable_rs232 332 global disable_rs232
201 disable_rs232: 333 disable_rs232:
202 clrf RCSTA1 334 clrf RCSTA1 ; disable RX
203 clrf TXSTA1 ; UART disable 335 clrf TXSTA1 ; disable TX
204 bcf PORTC,6 ; TX hard to GND 336 bcf PORTC,6 ; switch TX pin hard to GND
205 bsf PORTE,0 ; stop comm 337 bsf PORTE,0 ; stop comm
206 bcf PORTJ,2 ; /Reset (for very old OSTC sport) 338 bcf PORTJ,2 ; /Reset (required for very old OSTC sport)
207 return 339 return
208 340
209 341
210 global rs232_wait_tx 342 global rs232_wait_tx ; ++++ do not touch WREG here! ++++
211 rs232_wait_tx: 343 rs232_wait_tx:
212 btfss TXSTA1,TRMT ; RS232 busy? 344 btfss TXSTA1,TRMT ; last byte completely shifted out on TX pin?
213 bra rs232_wait_tx ; YES - wait... 345 bra rs232_wait_tx ; NO - wait...
214 346 btfss ble_available ; YES - OSTC running with Bluetooth?
215 btfss ble_available ; ble available? 347 return ; NO - done
216 return ; NO - done 348 btfsc NRTS ; YES - Bluetooth module also completed TX?
217 349 bra rs232_wait_tx ; NO - wait...
218 btfsc NRTS ; wait for Bluetooth module 350 return ; YES - done
219 bra rs232_wait_tx ; YES - wait... 351
220 return ; done 352
221 353 ; ++++ make this code as fast as possible! ++++
222 354 global rs232_get_byte ; ++++ do not touch WREG here! ++++
223 global rs232_wait_tx2
224 rs232_wait_tx2:
225 banksel TXSTA2 ; select bank for IO register access
226 rs232_wait_tx2_loop:
227 btfss TXSTA2,TRMT ; RS232 busy?
228 bra rs232_wait_tx2_loop ; YES - wait...
229 banksel common ; back to bank common
230 return ; done
231
232
233 global rs232_get_byte
234 rs232_get_byte: 355 rs232_get_byte:
235 bcf rs232_rx_timeout ; clear timeout flag 356 bcf rs232_rx_timeout ; clear timeout flag
236 ; set timeout timer to approx. 400 ms: 357 btfsc PIR1,RCIF ; received a data byte? (bit is set on RX complete and reset on reading RCREG1)
237 clrf uart_timeout_timer+0 ; set low byte of timeout timer to 0 358 return ; YES - done, received a byte (fast path)
238 clrf uart_timeout_timer+1 ; set high byte of timeout timer to 0 359 movff rx_timoeut_tmr5h_load,TMR5H ; - load TMR5 high with timeout value
239 ; set upper byte of timeout timer to 10 without using WREG: 360 clrf TMR5L ; - load TMR5 low with a zero, writing low starts the timer
240 clrf uart_timeout_timer+2 ; first clear to 0, then... 361 bcf PIR5,TMR5IF ; - clear timer overflow flag
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: 362 rs232_get_byte_loop:
245 btfsc PIR1,RCIF ; received a data byte? 363 btfsc PIR1,RCIF ; received a data byte?
364 return ; YES - done, received a byte
365 btfss PIR5,TMR5IF ; NO - timer overflow (timeout)?
366 bra rs232_get_byte_loop ; NO - continue looping
367 ;bra rs232_rx_get_timeout ; YES - give up
368
369 rs232_rx_get_timeout:
370 bsf rs232_rx_timeout ; set timeout flag
371 bcf RCSTA1,CREN ; clear receiver status by toggling CREN
372 bsf RCSTA1,CREN ; ...
373 return ; done, given up
374
375
376 ;-----------------------------------------------------------------------------
377 ; Send and Receive functions to be used through the macros
378
379 ; send a range of 1-256 bytes from memory to the RS232 interface
380 ;
381 global serial_tx_ram
382 serial_tx_ram:
383 movwf eeprom_loop ; initialize loop counter (eeprom variable used here)
384 serial_tx_ram_loop:
385 rcall rs232_wait_tx ; wait for completion of last transmit
386 movff POSTINC2,TXREG1 ; send a byte from memory to serial
387 decfsz eeprom_loop,F ; decrement loop counter, became zero?
388 bra serial_tx_ram_loop ; NO - loop
246 return ; YES - done 389 return ; YES - done
247 decfsz uart_timeout_timer+0,F ; NO - decrement low byte of timer, became zero? 390
248 bra rs232_get_byte_loop ; NO - loop 391
249 decfsz uart_timeout_timer+1,F ; YES - decrement high byte of timer, became zero? 392 ; receive a range of 1-256 byte from the RS232 interface and write them to memory
250 bra rs232_get_byte_loop ; NO - loop 393 ;
251 decfsz uart_timeout_timer+2,F ; YES - decrement upper byte of timer, became zero? 394 global serial_rx_stream_ram ; ++++ make this code as fast as possible! ++++
252 bra rs232_get_byte_loop ; NO - loop 395 serial_rx_stream_ram:
253 bsf rs232_rx_timeout ; YES - set timeout flag 396 movwf eeprom_loop ; initialize loop counter (eeprom variable used here)
254 bcf RCSTA1,CREN ; - clear receiver status 397 serial_rx_stream_ram_loop_1:
255 bsf RCSTA1,CREN ; - ... 398 btfss PIR1,RCIF ; received a data byte? (bit is set on RX complete and reset on reading RCREG1)
256 return ; - and return anyway 399 bra serial_rx_stream_ram_tmr ; NO - enter loop with timeout
257 400 movff RCREG1,POSTINC2 ; YES - copy received byte to memory
258 ;============================================================================= 401 decfsz eeprom_loop,F ; - decrement loop counter, became zero?
259 402 bra serial_rx_stream_ram_loop_1 ; NO - loop
260 global do_logoffset_common_write 403 bcf rs232_rx_timeout ; YES - clear timeout flag
261 do_logoffset_common_write: 404 return ; - all bytes received, done
262 movff lo,EEDATA 405 serial_rx_stream_ram_tmr:
263 write_int_eeprom 0x0D 406 movff rx_timoeut_tmr5h_load,TMR5H ; load TMR5 high with timeout value
264 movff hi,EEDATA 407 clrf TMR5L ; load TMR5 low with a zero, writing low starts the timer
265 write_int_eeprom 0x0E 408 bcf PIR5,TMR5IF ; clear timer overflow flag
266 return 409 serial_rx_stream_ram_loop_2a:
267 410 clrf TMR5L ; restart timer (see above)
268 global do_logoffset_common_read 411 serial_rx_stream_ram_loop_2b:
269 do_logoffset_common_read: 412 btfss PIR1,RCIF ; received a data byte? (bit is set on RX complete and reset on reading RCREG1)
270 clrf EEADRH 413 bra serial_rx_stream_ram_chk ; NO - check timeout
271 read_int_eeprom 0x0D 414 movff RCREG1,POSTINC2 ; YES - copy received byte to memory
272 movff EEDATA,lo 415 decfsz eeprom_loop,F ; - decrement loop counter, became zero?
273 read_int_eeprom 0x0E 416 bra serial_rx_stream_ram_loop_2a; NO - loop
274 movff EEDATA,hi 417 bcf rs232_rx_timeout ; YES - clear timeout flag
275 return 418 return ; - all bytes received, done
276 419 serial_rx_stream_ram_chk:
277 ;============================================================================= 420 btfss PIR5,TMR5IF ; timer overflow (timeout)?
278 421 bra serial_rx_stream_ram_loop_2b; NO - continue looping
279 global update_battery_registers 422 bra rs232_rx_get_timeout ; YES - give up
280 update_battery_registers: 423
281 ; save battery gauge to EEPROM 0x07-0x0C 424 ;-----------------------------------------------------------------------------
282 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge
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
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
297 write_int_eeprom 0x0F
298 bcf block_battery_gauge ; allow ISR to access the battery gauge again
299 return
300
301
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
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 ; set EEPROM address, high byte
334
335 ; indicate valid data in vault
336 movlw 0xAA
337 movwf EEDATA
338 write_int_eeprom .0
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
343 write_int_eeprom .1
344 movff rtc_latched_year+1,EEDATA
345 write_int_eeprom .2
346 movff rtc_latched_year+2,EEDATA
347 write_int_eeprom .3
348 movff rtc_latched_year+3,EEDATA
349 write_int_eeprom .4
350 movff rtc_latched_year+4,EEDATA
351 write_int_eeprom .5
352 movff rtc_latched_year+5,EEDATA
353 write_int_eeprom .6
354
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_mins,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
372 write_int_eeprom .13
373
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
380 movlw .16
381 movwf EEADR
382 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte
383 movwf lo
384 lfsr FSR1,0x700 ; pres_tissue_N2+0
385 vault_decodata_into_eeprom2:
386 movff POSTINC1,EEDATA
387 call write_eeprom ; EEDATA into EEPROM@EEADR
388 incf EEADR,F
389 decfsz lo,F ; all done?
390 bra vault_decodata_into_eeprom2 ; NO - loop
391 clrf EEADRH ; YES - reset EEPROM pointer
392 return ; - done
393
394
395 global restore_decodata_from_eeprom
396 restore_decodata_from_eeprom:
397 movlw LOW .512 ; =0
398 movwf EEADR ; set EEPROM address, low byte
399 movlw HIGH .512 ; =2
400 movwf EEADRH ; set EEPROM address, high byte
401
402 ; restore date and time
403 read_int_eeprom .1
404 movff EEDATA,rtc_latched_year
405 read_int_eeprom .2
406 movff EEDATA,rtc_latched_month
407 read_int_eeprom .3
408 movff EEDATA,rtc_latched_day
409 read_int_eeprom .4
410 movff EEDATA,rtc_latched_hour
411 read_int_eeprom .5
412 movff EEDATA,rtc_latched_mins
413 read_int_eeprom .6
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
421
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
426
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_mins ; 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
442 movlw .16
443 movwf EEADR
444 movlw .128 ; 2 * 16 floats = 2*16*4 byte = 128 byte
445 movwf lo
446 lfsr FSR1,0x700 ; pres_tissue_N2+0
447 restore_decodata_from_eeprom2:
448 call read_eeprom ; EEPROM@EEADR into EEDATA
449 movff EEDATA,POSTINC1
450 incf EEADR,F
451 decfsz lo,F ; all done?
452 bra restore_decodata_from_eeprom2 ; NO - loop
453 clrf EEADRH ; YES - revert EEPROM high address pointer to default
454 return ; - done
455
456 ;=============================================================================
457
458 global reset_battery_pointer ; called from comm and menu tree
459 global reset_battery_internal_only
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
463 reset_battery_internal_only:
464 clrf EEADRH
465 clrf EEDATA ; delete to zero
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
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
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
481 banksel common ; back to bank common
482 bcf block_battery_gauge ; allow ISR to access the battery gauge again
483
484 movlw .100
485 movwf batt_percent ; set battery level to 100%
486 return
487
488 ;=============================================================================
489
490 global eeprom_reset_logbook_pointers
491 eeprom_reset_logbook_pointers:
492 clrf EEADRH ; make sure to select EEPROM bank 0
493 clrf EEDATA
494 write_int_eeprom .4
495 write_int_eeprom .5
496 write_int_eeprom .6
497 write_int_eeprom .2 ; also delete total dive counter
498 write_int_eeprom .3
499 write_int_eeprom .16
500 write_int_eeprom .17 ; ...and the backup counter, too
501 return
502
503 ;=============================================================================
504
505 END 425 END