comparison src/eeprom_rs232.asm @ 623:c40025d8e750

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