Mercurial > public > hwos_code
comparison src/start.asm @ 623:c40025d8e750
3.03 beta released
author | heinrichsweikamp |
---|---|
date | Mon, 03 Jun 2019 14:01:48 +0200 |
parents | b87f23fae743 |
children | cd58f7fc86db |
comparison
equal
deleted
inserted
replaced
622:02d1386429a6 | 623:c40025d8e750 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File start.asm REFACTORED VERSION V2.99g | 3 ; File start.asm combined next generation V3.03.2 |
4 ; | 4 ; |
5 ; Startup subroutines | 5 ; Startup subroutines |
6 ; | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
9 ; HISTORY | 9 ; HISTORY |
10 ; 2011-08-06 : [mH] moving from OSTC code | 10 ; 2011-08-06 : [mH] moving from OSTC code |
11 | 11 |
12 #include "hwos.inc" ; mandatory header | 12 #include "hwos.inc" ; mandatory header |
13 #include "ms5541.inc" | 13 #include "ms5541.inc" |
14 #include "isr.inc" | |
15 #include "shared_definitions.h" ; mailbox from/to p2_deco.c | 14 #include "shared_definitions.h" ; mailbox from/to p2_deco.c |
16 #include "eeprom_rs232.inc" | 15 #include "eeprom_rs232.inc" |
17 #include "math.inc" | 16 #include "math.inc" |
18 #include "tft.inc" | 17 #include "tft.inc" |
19 #include "surfmode.inc" | 18 #include "surfmode.inc" |
20 #include "wait.inc" | 19 #include "wait.inc" |
21 #include "rtc.inc" | 20 #include "rtc.inc" |
22 #include "external_flash.inc" | 21 #include "external_flash.inc" |
23 #include "convert.inc" | |
24 #include "strings.inc" | 22 #include "strings.inc" |
25 #include "tft_outputs.inc" | 23 #include "tft_outputs.inc" |
26 #include "adc_lightsensor.inc" | 24 #include "adc_lightsensor.inc" |
27 #include "i2c.inc" | 25 #include "i2c.inc" |
26 #include "divemode.inc" | |
27 #include "rx_ops.inc" | |
28 | |
28 | 29 |
29 extern init_ostc | 30 extern init_ostc |
30 extern option_restore_all | 31 extern option_restore_all |
32 extern backup_flash_page | |
31 extern restore_decodata_from_eeprom | 33 extern restore_decodata_from_eeprom |
32 extern oPressureAdjust | 34 extern oPressureAdjust |
33 extern option_reset | 35 extern option_reset |
34 extern option_save | 36 extern option_save |
35 extern option_save_all | 37 extern option_save_all |
36 extern option_check_all | 38 extern option_check_all |
37 extern do_new_battery_select | 39 extern do_new_battery_select |
38 extern use_old_batteries | 40 extern get_battery_data |
39 extern use_old_prior_209 | 41 extern use_old_prior_209 |
40 extern get_first_gas_to_WREG | 42 extern get_first_gas_to_WREG |
41 extern get_first_dil_to_WREG | 43 |
44 IFDEF _ccr_pscr | |
42 extern option_cleanup_oCCRMode_pSCR | 45 extern option_cleanup_oCCRMode_pSCR |
43 extern option_cleanup_oCCRMode_CCR | 46 extern option_cleanup_oCCRMode_CCR |
47 extern get_first_dil_to_WREG | |
48 ENDIF | |
44 | 49 |
45 IFDEF _rx_functions | 50 IFDEF _rx_functions |
46 extern option_cleanup_oTrMode_CCR | 51 extern option_cleanup_oTrMode_CCR |
47 extern option_cleanup_oTrMode_no_CCR | 52 extern option_cleanup_oTrMode_no_CCR |
53 extern rx_firmware_new_major | |
54 extern rx_firmware_new_minor | |
48 ENDIF | 55 ENDIF |
49 | 56 |
57 ;----------------------------------------------------------------------------- | |
58 | |
50 | 59 |
51 ;============================================================================= | 60 ;============================================================================= |
52 ; Reset Vector: entry point on device wake-up and hard reset | 61 ; Reset Vector: entry point on device wake-up and hard reset |
53 ; | 62 ; |
54 reset_v code 0x00000 | 63 reset_v CODE 0x00000 |
55 | 64 goto 0x1FF00 ; jump to bootloader |
56 ; goto start | 65 |
57 goto 0x1FF00 ; bootloader | 66 start_v CODE 0x00004 ; jump to application (cold-)start |
58 | |
59 ORG 0x00004 ; needed for second-level bootloader | |
60 goto start | 67 goto start |
61 | 68 |
62 ;============================================================================= | 69 ;============================================================================= |
63 | 70 |
64 boot CODE | 71 boot CODE |
65 | 72 |
66 ;============================================================================= | 73 ;============================================================================= |
67 | 74 ; Entry point after cold start |
75 ; | |
68 global start | 76 global start |
69 start: | 77 start: |
70 lfsr FSR0,0x000 ; clear ram-banks 0-14 | 78 ; clear RAM banks 0-14 |
71 clear_rambank: | 79 lfsr FSR0,0x000 ; load start address into FSR0 |
72 clrf POSTINC0 | 80 movlw 0x0F ; load end address into WREG (actually its high byte) |
73 movlw 0x0F | 81 start_clear_rambank: |
74 cpfseq FSR0H ; bank 14 done? | 82 clrf POSTINC0 ; clear memory location and increment FSR0 |
75 bra clear_rambank ; NO - loop | 83 cpfseq FSR0H ; has FSR0 reached begin of bank 15, i.e. banks 0-14 done? |
76 | 84 bra start_clear_rambank ; NO - loop |
77 call init_ostc ; initialize hardware (ports, timers, etc.) | 85 |
78 | 86 ; initialize hardware (ports, timers, interrupts, etc.) |
79 ; get button type from Bootloader-Info | 87 call init_ostc ; also selects bank common and sets CPU to normal speed |
80 movlw .16 | 88 |
81 movff WREG,analog_counter ; initialize averaging | 89 ; flag that later restart origins from a cold start |
90 bsf cold_start | |
91 | |
92 ; initialize averaging for analog buttons | |
93 movlw .16 ; set averaging span | |
94 movff WREG,analog_counter ; write to counter | |
95 | |
96 ; get button type from bootloader info | |
82 bsf analog_switches | 97 bsf analog_switches |
83 movlw 0x7C | 98 movlw 0x7C |
84 movwf TBLPTRL | 99 movwf TBLPTRL |
85 movlw 0xF7 | 100 movlw 0xF7 |
86 movwf TBLPTRH | 101 movwf TBLPTRH |
87 movlw 0x01 | 102 movlw 0x01 |
88 movwf TBLPTRU | 103 movwf TBLPTRU |
89 TBLRD*+ ; reads 0x07 for analog buttons | 104 TBLRD*+ ; read configuration byte |
90 movlw 0x07 | 105 movlw 0x07 ; coding for analog buttons |
91 cpfseq TABLAT | 106 cpfseq TABLAT ; equal? |
92 bcf analog_switches | 107 bcf analog_switches ; NO - no analog buttons |
93 | 108 |
94 ; get screen type (2) from Bootloader-Info | 109 ; get screen type (2) from bootloader info |
95 bsf screen_type2 | 110 bsf screen_type2 |
96 movlw 0x80 | 111 movlw 0x80 |
97 movwf TBLPTRL ; only adjust low byte, high and upper are still 0x01F7... | 112 movwf TBLPTRL ; only low byte adjustment needed, high and upper are still at 0x01F7xx |
98 TBLRD*+ ; reads 0x83 if OSTC has screen type 2 | 113 TBLRD*+ ; read configuration byte |
99 movlw 0x83 | 114 movlw 0x83 ; coding for screen type 2 |
100 cpfseq TABLAT | 115 cpfseq TABLAT ; equal? |
101 bcf screen_type2 | 116 bcf screen_type2 ; NO - not screen type 2 |
102 | 117 |
103 ; read button polarity | 118 ; get button polarity from configuration data (EEPROM) |
104 movlw LOW .897 | 119 movlw LOW .897 |
105 movwf EEADR | 120 movwf EEADR |
106 movlw HIGH .897 | 121 movlw HIGH .897 |
107 movwf EEADRH | 122 movwf EEADRH |
108 call read_eeprom ; EEDATA into EEPROM @ EEADR | 123 call read_eeprom ; EEDATA into EEPROM @ EEADR |
109 clrf EEADRH ; reset EEADRH | 124 clrf EEADRH ; reset EEADRH |
110 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) | 125 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) |
111 | 126 |
112 ; air pressure compensation after reset | 127 ; initialize pressure sensor calibration |
113 call get_calibration_data ; get calibration data from pressure sensor | 128 call get_calibration_data ; get calibration data from pressure sensor |
114 banksel common ; get_calibration_data uses isr_backup | |
115 | |
116 call TFT_DisplayOff ; turn off display | 129 call TFT_DisplayOff ; turn off display |
117 bsf LEDr ; turn on red LED | 130 |
118 bcf pressure_refresh | 131 ; wait for calibration data to take effect |
119 ; first pass will not have valid temperature | 132 bsf LEDr ; turn on red LED |
120 btfss pressure_refresh ; air pressure compensation | 133 |
121 bra $-2 | 134 ; first pass, will not have valid temperature yet |
122 ; second pass | 135 bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on |
123 bcf pressure_refresh | 136 btfss trigger_pres_update ; has the ISR confirmed a pressure update? |
124 btfss pressure_refresh ; air pressure compensation | 137 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in |
125 bra $-2 | 138 |
126 bcf LEDr | 139 ; second pass - complete sensor initialization |
127 | 140 bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on |
128 clrf rel_pressure+0 | 141 btfss trigger_pres_update ; has the ISR confirmed a pressure update? |
129 clrf rel_pressure+1 | 142 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in |
130 clrf surface_interval+0 | 143 |
131 clrf surface_interval+1 | 144 ; sensor calibration completed, first valid pressure value is available |
132 | 145 bcf LEDr ; turn off red LED again |
133 SAFE_2BYTE_COPY amb_pressure, last_surfpressure | 146 |
134 | 147 ; load surface pressure into ISR |
135 movlw LOW max_surfpressure | 148 ; initially needs to be done twice in order to shift the current absolute pressure through the |
136 movff WREG,sub_a+0 ; max. "allowed" air pressure in mbar | 149 ; 15 minutes sampling buffer into the reference buffer from where it is loaded by the ISR |
137 movlw HIGH max_surfpressure | 150 rcall sample_surface_pressure ; 1st pass |
138 movff WREG,sub_a+1 ; max. "allowed" air pressure in mbar | 151 rcall sample_surface_pressure ; 2nd pass |
139 movff last_surfpressure+0,sub_b+0 | 152 btfsc update_surface_pressure ; has the ISR confirmed loading of the surface pressure? |
140 movff last_surfpressure+1,sub_b+1 | 153 bra $-2 ; NO - not yet, loop until ISR has confirmed loading |
141 call subU16 ; sub_c = sub_a - sub_b | 154 |
142 btfss neg_flag ; is 1080 mbar < amb_pressure ? | 155 ; reset all tissue pressures to surface pressure equilibrium state by default |
143 bra start_copy_pressure ; NO - current air pressure is lower then "allowed" air pressure, ok | 156 call deco_clear_tissue ; (C-code) |
144 | 157 banksel common |
145 ; not ok - overwrite with max. "allowed" air pressure | 158 |
146 movlw LOW max_surfpressure | 159 ; restore tissue pressures from EEPROM (if available) |
147 movff WREG,last_surfpressure+0 ; max. "allowed" air pressure in mbar | |
148 movlw HIGH max_surfpressure | |
149 movff WREG,last_surfpressure+1 ; max. "allowed" air pressure in mbar | |
150 | |
151 start_copy_pressure: | |
152 movff last_surfpressure+0,last_surfpressure_15min+0 | |
153 movff last_surfpressure+1,last_surfpressure_15min+1 | |
154 movff last_surfpressure+0,last_surfpressure_30min+0 | |
155 movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all air pressure registers | |
156 | |
157 ; initialize GF high (needed by deco engine for color-coding the GF value) | |
158 movff opt_GF_high,char_I_GF_High_percentage | |
159 | |
160 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface | |
161 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressure | |
162 movff int_I_pres_respiration+1,int_I_pres_surface+1 | |
163 | |
164 call deco_clear_tissue ; set all tissues to Pamb * N2_ratio (code located in p2_deco.c) | |
165 banksel common ; back to bank 1, needed after every return from C code | |
166 | |
167 call rtc_init ; init clock | |
168 | |
169 movlw HIGH .512 ; =2 | 160 movlw HIGH .512 ; =2 |
170 movwf EEADRH | 161 movwf EEADRH ; set EEPROM address, high byte |
171 read_int_eeprom .0 | 162 read_int_eeprom .0 |
172 clrf EEADRH | 163 clrf EEADRH |
173 movlw 0xAA | 164 movlw 0xAA ; coding for tissue pressures available |
174 cpfseq EEDATA ; =0xAA | 165 cpfseq EEDATA ; tissue pressures available? |
175 bra no_deco_restore ; NO | 166 bra start_1 ; NO - no tissue pressures available |
176 call restore_decodata_from_eeprom ; reload deco data and date/time from eeprom | 167 call restore_decodata_from_eeprom ; YES - reload tissue pressures from EEPROM |
177 no_deco_restore: | 168 |
178 call deco_calc_dive_interval_1min ; calculate deco in surface mode | 169 start_1: |
179 call deco_calc_desaturation_time ; calculate desaturation and no-fly time | 170 bsf reset_surface_interval ; request ISR to reset the surface interval timer |
180 banksel common | 171 |
181 | 172 ; call rtc_init ; initialize the real time clock (will reset to firmware creation date) |
182 bcf menubit ; clear menu flag | 173 |
183 | 174 ; check for power-on reset |
184 ; check for power-on reset here | |
185 | |
186 ; ***************************************************************************** | |
187 ; "do_new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
188 ; ***************************************************************************** | |
189 | |
190 ; Try to migrate the old battery status from firmware 2.09 or earlier.. | |
191 btfsc RCON,POR ; was this a power-on reset? | 175 btfsc RCON,POR ; was this a power-on reset? |
192 call use_old_prior_209 ; NO | 176 call use_old_prior_209 ; NO - migrate the last battery status from firmware 2.09 or earlier |
193 | 177 |
194 bcf use_old_batt_flag | 178 bcf use_old_batt_flag ; default to no reload of last battery data |
195 btfsc RCON,POR ; was this a power-on reset? | 179 btfsc RCON,POR ; was this a power-on reset? |
196 bsf use_old_batt_flag ; NO | 180 bsf use_old_batt_flag ; NO - reload last battery data |
197 | 181 |
198 call lt2942_get_status ; check for gauge IC | 182 call lt2942_get_status ; check for gauge IC |
199 btfss battery_gauge_available ; cR or 2 hardware? | 183 btfss battery_gauge_available ; cR or 2 hardware? |
200 bra check_firmware_new ; NO - skip next | 184 bra start_check_new_firmware ; NO - skip next |
201 movlw .30 ; YES - reset button sensitivity | 185 movlw .30 ; YES - load default button sensitivity |
202 movff WREG,opt_cR_button_right | 186 movff WREG,opt_cR_button_right ; - set default for left button |
203 movff WREG,opt_cR_button_left ; reset on power-on reset | 187 movff WREG,opt_cR_button_left ; - set default for right button |
204 call piezo_config ; configure buttons | 188 call piezo_config ; - configure buttons, 1st pass |
205 call piezo_config ; configure buttons (2 times) | 189 call piezo_config ; - configure buttons, 2nd pass |
206 | 190 |
207 check_firmware_new: | 191 start_check_new_firmware: |
208 call TFT_boot ; initialize TFT (includes clear screen) | 192 call TFT_boot ; initialize TFT (includes clear screen & backlight switch-off) |
209 clrf CCPR1L ; backlight off | 193 |
210 | 194 ; show heinrichsweikamp logo |
211 WIN_TOP .40 | 195 WIN_TOP .40 |
212 WIN_LEFT .10 | 196 WIN_LEFT .10 |
213 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block ; show heinrichsweikamp logo | 197 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block |
214 | 198 |
215 call TFT_standard_color | 199 ; check if a new firmware was loaded, if yes reset option oPressureAdjust |
216 | 200 movlw d'1' ; set EEPROM address to 0x101 |
217 WIN_SMALL .20,.100 | 201 movwf EEADR ; = 0x001 |
218 STRCPY_PRINT "Update successful!" ; hard coded since language switch does not work here | 202 movwf EEADRH ; = 0x101 |
219 | 203 call read_eeprom ; read current version, major |
220 WIN_SMALL .20,.140 | 204 movff EEDATA,lo ; store major in lo |
221 STRCPY "New Firmware: " | 205 incf EEADR,F ; set EEPROM address to 0x102 |
222 call TFT_cat_firmware ; show firmware version x.y and color-code if outdated | 206 call read_eeprom ; read current version, minor |
223 STRCAT_PRINT "" ; finalize output | 207 movff EEDATA,hi ; store minor in hi |
224 bcf win_invert ; reset inverted output if firmware is outdated | |
225 call TFT_standard_color ; reset color if firmware is outdated | |
226 | |
227 WIN_SMALL .60,.180 | |
228 call TFT_cat_beta_release ; if it is a beta version, show "BETA" + issue, else "Release" | |
229 STRCAT_PRINT "" ; finalize output | |
230 call TFT_standard_color ; reset color | |
231 | |
232 call TFT_Display_FadeIn ; display resulting surface screen | |
233 | |
234 ; check if a new firmware was loaded, if yes reset Custom Function oPressureAdjust | |
235 movlw d'1' | |
236 movwf EEADR ; =1 | |
237 movwf EEADRH ; =1 | |
238 call read_eeprom ; read current version x | |
239 movff EEDATA,lo | |
240 incf EEADR,F ; set to 0x102 | |
241 call read_eeprom ; read current version y | |
242 movff EEDATA,hi | |
243 clrf EEADRH ; reset EEADRH | 208 clrf EEADRH ; reset EEADRH |
244 | 209 |
245 movlw softwareversion_x | 210 movlw softwareversion_x ; get current major version |
246 cpfseq lo ; compare version x | 211 cpfseq lo ; compare with stored version, equal? |
247 bra check_firmware_new4 ; is not equal -> reset CF and store new version in EEPROM | 212 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM |
248 | 213 |
249 movlw softwareversion_y | 214 movlw softwareversion_y ; get current minor version |
250 cpfseq hi ; compare version y | 215 cpfseq hi ; compare with stored version, equal? |
251 bra check_firmware_new4 ; is not equal -> reset CF and store new version in EEPROM | 216 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM |
252 bra check_firmware_new5 ; x and y are equal -> do not reset CF | 217 bra start_check_new_firmware_old ; YES - both equal, do not reset options |
253 | 218 |
254 check_firmware_new4: | 219 start_check_new_firmware_new: |
220 ; new firmware version detected | |
221 call show_fw_mesg_update ; show firmware update message | |
222 | |
255 ; place "after-update reset" here... | 223 ; place "after-update reset" here... |
256 lfsr FSR0,oPressureAdjust | 224 lfsr FSR0,oPressureAdjust ; memory address of option data |
257 call option_reset ; reset oPressureAdjust to factory default | 225 call option_reset ; reset oPressureAdjust to factory default |
258 lfsr FSR0,oPressureAdjust | 226 lfsr FSR0,oPressureAdjust ; memory address of option data |
259 call option_save ; save new value of oPressureAdjust in EEPROM | 227 call option_save ; save reseted value of oPressureAdjust in EEPROM |
260 | 228 |
261 check_firmware_new5: | 229 ; store current version in EEPROM |
262 rcall backup_flash_page ; backup the first 128 bytes from flash to EEPROM | 230 movlw d'1' ; set EEPROM address to 0x101 |
263 | 231 movwf EEADR ; = 0x001 |
264 movlw d'1' ; store current version in EEPROM | 232 movwf EEADRH ; = 0x101 |
265 movwf EEADR ; =1 | 233 movlw softwareversion_x ; get version, major number |
266 movwf EEADRH ; =1 | 234 movwf EEDATA ; prepare write |
267 movlw softwareversion_x | 235 call write_eeprom ; execute write |
268 movwf EEDATA | 236 incf EEADR,F ; set EEPROM address to 0x102 |
269 call write_eeprom ; write version, major number | 237 movlw softwareversion_y ; get version, minor number |
270 incf EEADR,F ; set to 0x102 | 238 movwf EEDATA ; prepare write |
271 movlw softwareversion_y | 239 call write_eeprom ; execute write |
272 movwf EEDATA | |
273 call write_eeprom ; write version, minor number | |
274 clrf EEADRH ; reset EEADRH | 240 clrf EEADRH ; reset EEADRH |
275 | 241 bra start_check_new_firmware_common ; |
276 ; wait 10 seconds | 242 |
277 movlw .10 ; load loop counter | 243 start_check_new_firmware_old: |
278 check_firmware_new6: | 244 call show_fw_mesg_kept ; show firmware is kept message |
279 call wait_1s ; wait (about) 1 second | 245 |
280 decfsz WREG,W ; YES - decrement loop counter, did it became zero? | 246 start_check_new_firmware_common: |
281 bra check_firmware_new6 ; NO - loop | 247 call TFT_Display_FadeIn ; display resulting screen |
282 ;bra restart ; YES - proceed with restart | 248 call backup_flash_page ; back-up the first 128 bytes from program flash memory to EEPROM |
283 | 249 |
284 | 250 ; pause 5 seconds |
251 movlw .5 ; load loop counter | |
252 start_check_new_firmware_wait: | |
253 call wait_1s ; wait <= 1 second | |
254 decfsz WREG,W ; decrement loop counter, did it became zero? | |
255 bra start_check_new_firmware_wait ; NO - loop | |
256 ;bra restart ; YES - proceed with restart | |
257 | |
258 | |
259 ;============================================================================= | |
260 ; Entry point after warm start | |
261 ; | |
262 ; called on leaving sleep mode, surface menu, communication mode, and | |
263 ; when a start of a dive is detected in all modes except surface mode. | |
264 ; | |
285 global restart | 265 global restart |
286 restart: | 266 restart: |
287 clrf STKPTR ; never return from here | 267 banksel common ; for safety purpose only |
268 clrf STKPTR ; clear return addresses stack | |
288 clrf CCP1CON ; stop PWM | 269 clrf CCP1CON ; stop PWM |
289 bcf PORTC,2 ; pull PWM out to GND | 270 bcf PORTC,2 ; pull PWM out to GND |
290 | 271 |
291 btfsc menubit ; return from Menu/COMM mode or timeout? | 272 call request_speed_normal ; request CPU speed change to normal speed (for safety only) |
273 | |
274 ; manage the option settings | |
275 btfsc surfmode_menu ; was restart entered by return from surface menu or comm mode? | |
292 call option_save_all ; YES - save all settings into EEPROM | 276 call option_save_all ; YES - save all settings into EEPROM |
293 | 277 |
294 call option_restore_all ; restore everything from EEPROM into RAM | 278 btfss surfmode_menu ; was restart entered by return from surface menu or comm mode? |
295 call option_check_all ; check all options (and reset if not within their min/max boundaries) | 279 call option_restore_all ; NO - load all settings from EEPROM |
296 call option_save_all ; save all settings into EEPROM after they have been checked | 280 |
297 | 281 call option_check_all ; check all options and repair them if not within their min/max boundaries |
298 clrf flag1 ; clear all flags | 282 |
299 clrf flag2 | 283 btfsc option_repaired ; errors found & repaired during options check? |
300 clrf flag3 | 284 call option_save_all ; YES - save corrected settings into EEPROM |
301 clrf flag4 | 285 |
302 clrf flag5 | 286 ; clear flag groups |
303 clrf flag6 | 287 clrf HW_descriptor ; hardware - OSTC model descriptor |
304 clrf flag7 | 288 clrf HW_flags_state ; hardware - status |
305 clrf flag8 | 289 clrf DM_flags_sensor ; hardware - O2 sensors |
306 clrf flag9 | 290 |
307 clrf flag10 ; Clears flag "enable_screen_dumps" - making screen dumps impossible... TODO | 291 clrf OS_flags_ISR1 ; operating system - ISR control 1 |
308 ; do not clear flag11 (sensor calibration and charger status) | 292 clrf OS_flags_ISR2 ; operating system - ISR control 2 |
309 clrf flag12 | 293 |
310 ; do not clear flag13 (important hardware flags) | 294 clrf eventbase ; event triggers generated by ISR |
311 clrf flag14 | 295 |
312 clrf flag15 | 296 clrf DM_flags_deco ; dive deco modes |
313 clrf flag16 | 297 |
314 clrf flag17 | 298 clrf MS_flags_control ; menu system - control |
315 ; do not clear flag18 (important hardware flags) | 299 clrf MS_flags_imprint ; menu system - data imprinting |
316 | 300 |
317 clrf cvt_flags | 301 clrf CVT_flags1 ; convert and display functions |
318 | 302 clrf CVT_flags2 ; convert and display functions |
319 clrf tft_update_flags+0 | 303 |
320 clrf tft_update_flags+1 | 304 ; TFT will be dimming soon, ignore ambient sensor |
321 clrf tft_update_flags+2 | 305 bsf tft_is_dimming |
322 | 306 |
323 clrf hardware_flag1 ; hardware descriptor 1 | 307 ; configure the OSTC model descriptor (stored in HW_descriptor) |
324 ; hardware_flag2 ; hardware descriptor 2 - do not clear here! | |
325 | |
326 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! | |
327 | |
328 ; configure hardware descriptor 1 | |
329 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity | 308 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity |
330 bsf ambient_sensor ; set flag | 309 bsf ambient_sensor ; set ambient light sensor as available by default |
331 bsf optical_input ; set flag | 310 bsf optical_input ; set optical input as available by default |
332 | 311 |
333 call lt2942_get_status ; check for gauge IC | 312 call lt2942_get_status ; check for gauge IC |
334 btfss battery_gauge_available ; cR/2 hardware? | 313 btfss battery_gauge_available ; OSTC 2, cR or TR? |
335 bra restart2 ; NO | 314 bra restart2 ; NO |
336 call lt2942_init ; YES - initialize battery gauge IC | 315 |
337 bcf optical_input ; clear flag | 316 ; OSTC 2, cR or TR |
338 | 317 call lt2942_init ; initialize battery gauge IC |
339 banksel 0xF16 | 318 bcf optical_input ; OSTC 2, cR and TR do not have an optical input |
319 | |
320 banksel ANCON0 ; ANCON0 is outside access RAM | |
340 bcf ANCON0,7 ; AN7 digital input | 321 bcf ANCON0,7 ; AN7 digital input |
341 banksel common | 322 banksel common ; back to bank common |
342 bcf lightsen_power ; power-down ambient light sensor | 323 bcf lightsen_power ; power-down ambient light sensor |
343 bcf ambient_sensor ; clear flag | 324 bcf ambient_sensor ; no ambient light sensor by default |
344 nop | 325 nop |
345 btfss PORTF,2 ; light sensor available? | 326 btfss PORTF,2 ; ambient light sensor available? |
346 bsf ambient_sensor ; YES | 327 bsf ambient_sensor ; YES |
347 banksel 0xF16 | 328 banksel ANCON0 ; ANCON0 is outside access RAM |
348 bsf ANCON0,7 ; AN7 analog again | 329 bsf ANCON0,7 ; AN7 analog again |
349 banksel common | 330 banksel common ; back to bank common |
350 bsf lightsen_power ; power-up ambient light sensor again | 331 bsf lightsen_power ; power-up ambient light sensor again |
351 | 332 |
352 restart2: | 333 restart2: |
353 btfsc vusb_in | 334 btfsc vusb_in ; USB power detected? |
354 bra restart3 ; USB (and powered on) | 335 bra restart3 ; YES |
355 bcf PORTE,0 ; start comms | 336 bcf PORTE,0 ; start comm |
356 WAITMS d'5' | 337 WAITMS d'5' ; wait 5 ms |
357 btfss vusb_in | 338 btfss vusb_in ; USB power detected? |
358 bra restart3 ; USB (and powered off) | 339 bra restart3 ; NO |
359 bsf ble_available ; BLE available | 340 bsf ble_available ; YES - BLE available |
360 | 341 |
361 restart3: | 342 restart3: |
362 bsf PORTE,0 ; stop comms | 343 bsf PORTE,0 ; stop comm |
363 btfsc ble_available ; BLE available? | 344 btfsc ble_available ; BLE available? |
364 bra restart4 ; YES - can't be a cR | 345 bra restart4 ; YES - can't be a cR |
365 btfss battery_gauge_available ; rechargeable? | 346 btfss battery_gauge_available ; rechargeable? |
366 bra restart4 ; NO - can't be a cR | 347 bra restart4 ; NO - can't be a cR |
367 bsf analog_o2_input ; set flag for analog | 348 bsf analog_o2_input ; set flag for analog |
368 | 349 |
369 restart4: | 350 restart4: |
351 bsf lv_core ; default to low voltage core | |
352 movlw 0x80 ; point to 0x1F780 | |
353 movwf TBLPTRL | |
354 movlw 0xF7 | |
355 movwf TBLPTRH | |
356 movlw 0x01 | |
357 movwf TBLPTRU | |
358 TBLRD*+ ; read from 0x1F780 | |
359 movlw 0x83 ; coding for low voltage core, part 1 | |
360 cpfseq TABLAT ; equal? | |
361 bra restart4a ; NO - no low voltage core then | |
362 movlw 0x81 ; point to 0x1F781 | |
363 movwf TBLPTRL | |
364 TBLRD*+ ; read from 0x1F781 | |
365 movlw 0x94 ; coding for low voltage core, part 2 | |
366 cpfseq TABLAT ; equal? | |
367 restart4a: | |
368 bcf lv_core ; NO - no low voltage core then | |
369 | |
370 | |
370 IFDEF _rx_functions | 371 IFDEF _rx_functions |
371 WAITMS d'200' | 372 |
372 call I2C_probe_OSTC_rx ; set ostc_rx_present flag if this is an OSTC TR model | 373 ; set TR functions as deactivated by default |
373 | 374 bcf tr_functions_activated ; clear flag |
374 ; The hardware descriptor is now: | 375 |
375 ; 0x11: 2 with BLE | 376 ; search for TR module |
376 ; 0x12; Sport | 377 WAITMS .200 ; wait 200 ms while RX module boots up |
377 ; 0x13: +/2 with BLE & ambient ; PLUS ??? OSTC 3 (2016) ??? | 378 call I2C_probe_OSTC_rx ; check for RX module and set ostc_rx_present flag if found |
378 ; 0x05: cR | 379 btfss ostc_rx_present ; RX module detected? |
379 ; 0x0A: 3 | |
380 ; 0x1A: 3 with BLE | |
381 ; 0x33: 2 TR | |
382 | |
383 btfss ostc_rx_present ; OSTC TR detected? | |
384 bra restart5 ; NO | 380 bra restart5 ; NO |
385 movff opt_TR_mode,WREG ; YES - get user-selected TR mode | 381 |
386 tstfsz WREG ; TR functions switched on? | 382 ; check if TR module firmware is up to date |
387 bsf FLAG_tr_enabled ; YES - switch on displays and calculation functions | 383 movff rx_firmware_cur_major,hi ; copy current firmware on RX module to bank common, major |
384 movff rx_firmware_cur_minor,lo ; copy current firmware on RX module to bank common, minor | |
385 call rx_firmware_new_major ; get latest firmware version into WREG, major | |
386 cpfseq hi ; equal to current firmware on RX module, major ? | |
387 bra restart4b ; NO - update | |
388 call rx_firmware_new_minor ; YES - get latest firmware version into WREG, minor | |
389 cpfseq lo ; - equal to current firmware on RX module, minor ? | |
390 bra restart4b ; NO - update TR module | |
391 bra restart4e ; YES - no need to update | |
392 | |
393 restart4b: | |
394 ; print TR module update message | |
395 call TFT_boot ; initialize TFT (includes clear screen & backlight switch-off) | |
396 WIN_TOP .40 ; show heinrichsweikamp logo | |
397 WIN_LEFT .10 | |
398 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block | |
399 WIN_SMALL .10,.130 | |
400 STRCAT_PRINT "Updating TR Module..." ; print update message | |
401 call TFT_Display_FadeIn ; display screen | |
402 WIN_SMALL .10,.160 | |
403 STRCAT "TR Update " ; prepare result message | |
404 | |
405 ; update firmware in RX module | |
406 call I2C_sleep_accelerometer ; stop accelerometer | |
407 call I2C_sleep_compass ; stop compass | |
408 call update_tr_module ; update TR module | |
409 | |
410 WIN_SMALL .10,.160 ; set next output position | |
411 STRCAT "Update " ; common part of result message | |
412 btfss ostc_rx_present ; data transfer successful and TR module up & running again? | |
413 bra restart4c ; NO | |
414 STRCAT "to " ; YES - print success message | |
415 call TFT_print_firmware_rx ; - print installed version | |
416 STRCAT_PRINT " done" ; - complete result message | |
417 bra restart4d ; - show message for a while | |
418 | |
419 restart4c: | |
420 STRCAT_PRINT "failed" ; complete result message - failure | |
421 | |
422 restart4d: | |
423 call wait_1s ; wait (up to) 1 second | |
424 call wait_1s ; wait (another full) 1 second | |
425 call wait_1s ; wait (another full) 1 second | |
426 | |
427 restart4e: | |
428 btfss ostc_rx_present ; TR module up & running? | |
429 bra restart5 ; NO | |
430 movff opt_TR_mode,WREG ; YES - get TR mode | |
431 tstfsz WREG ; - TR mode <> off ? | |
432 bsf tr_functions_activated ; YES - set TR functions as activated | |
433 | |
434 ENDIF ; _rx_functions | |
435 | |
436 | |
437 restart5: | |
438 ; manage hardware | |
439 btfss analog_o2_input ; OSTC with analog input? | |
440 bsf TRISB,3 ; NO - shut down power supply for S8 bulkhead | |
441 | |
442 btfss battery_gauge_available ; OSTC with gauge IC? | |
443 bsf TRISG,0 ; NO | |
444 | |
445 call ext_flash_disable_protection ; disable write protection for external flash | |
446 | |
447 btfsc use_old_batt_flag ; shall reload last battery data? | |
448 call get_battery_data ; YES - get last battery data | |
449 | |
450 ; set screen orientation | |
451 bcf flip_screen ; set default screen orientation | |
452 TSTOSC opt_flip_screen ; shall show screen outputs upside down? (=1: flip the screen) | |
453 bsf flip_screen ; YES - set upside-down orientation | |
454 | |
455 ; check if high-altitude mode is applicable | |
456 bcf high_altitude_mode ; disable high altitude mode by default | |
457 MOVII pressure_abs_ref, sub_a ; copy last surface pressure to sub_a | |
458 MOVLI high_altitude_threshold+1,sub_b ; copy high-altitude threshold (880 mbar) + 1 to sub_a | |
459 call cmpU16 ; sub_a - sub_b = pressure_abs_ref - (high_altitude_threshold + 1) | |
460 btfsc neg_flag ; result negative (absolute pressure <= 880 mbar) ? | |
461 bsf high_altitude_mode ; YES - enable high altitude mode | |
462 | |
463 ; check if there was a cold start, if yes do initial computation of further deco data | |
464 btfss cold_start ; did a cold start? | |
465 bra restart6 ; NO | |
466 bcf cold_start ; YES - clear flag | |
467 call deco_calc_dive_interval_1min ; - calculate tissues for 1 minute at surface conditions (C-code) | |
468 call deco_calc_desaturation_time ; - calculate desaturation and no-fly/no-altitude time (C-code) | |
469 banksel common ; - back to bank common | |
470 | |
471 restart6: | |
472 ; the dive mode flag can not be set right after cold start, must have been in surface mode before | |
473 btfsc divemode ; shall enter dive mode? | |
474 goto diveloop ; YES | |
475 | |
476 btfsc RCON,POR ; was this a power-on reset? | |
477 goto surfloop ; NO - enter surface mode | |
478 bsf RCON,POR ; YES - acknowledge detection and re-arm detector | |
479 goto do_new_battery_select ; - prompt for battery selection, will proceed to surface mode | |
480 | |
481 | |
482 ;============================================================================= | |
483 ; Setup all flags and parameters for dive mode and simulator computations | |
484 ; | |
485 ; called from divemode.asm, menu_tree.asm and surfmode.asm | |
486 ; | |
487 global restart_set_modes_and_flags | |
488 restart_set_modes_and_flags: | |
489 call option_restore_all ; restore all options settings from EEPROM | |
490 | |
491 IFDEF _external_sensor | |
492 call disable_ir_s8 ; switch off IR/S8 digital interface by default | |
388 ENDIF | 493 ENDIF |
389 | 494 |
390 ; configure hardware descriptor 2 | 495 ; setup sampling rate |
391 ; flag screen_type will be configured on each call of TFT_boot | 496 movlw .2 ; default to 2 seconds |
392 ; flags compass_type & compass_type2 will be configured on each call of I2C_init_compass | 497 movwf sampling_rate ; write setting |
393 ; flag analog_switches will be configured directly after hard start (in start:) | 498 TSTOSS opt_sampling_rate ; check option: 1= 10s, 0= 2s |
394 | 499 bra restart_set_modes_and_flags1 ; 0 - 2 seconds selected, done |
395 restart5: | 500 movlw .10 ; 1 - change to 10 seconds |
396 ; Select high altitude (fly) mode? | 501 movwf sampling_rate ; - write setting |
397 movff last_surfpressure_30min+0,sub_b+0 | |
398 movff last_surfpressure_30min+1,sub_b+1 | |
399 movlw HIGH high_altitude_threshold | |
400 movwf sub_a+1 | |
401 movlw LOW high_altitude_threshold ; hard-wired 880 hPa | |
402 movwf sub_a+0 | |
403 call subU16 ; sub_c = sub_a - sub_b | |
404 btfss neg_flag ; result negative (ambient > 880 hPa)? | |
405 bsf high_altitude_mode ; NO - set flag | |
406 | |
407 btfss analog_o2_input | |
408 bsf TRISB,3 | |
409 btfss battery_gauge_available | |
410 bsf TRISG,0 | |
411 call ext_flash_disable_protection ; disable write protection for external flash | |
412 | |
413 bsf flip_screen ; select screen flip 180° | |
414 TSTOSS opt_flip_screen ; shall actually flip? (=1: flip the screen) | |
415 bcf flip_screen ; NO - revert to normal orientation | |
416 | |
417 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset | |
418 goto use_old_batteries ; returns to surface loop | |
419 | |
420 btfsc RCON,POR ; was this a power-on reset? | |
421 goto surfloop ; NO - jump to surface loop | |
422 bsf RCON,POR ; set bit for next detection | |
423 ; Things to do after a power-on reset | |
424 goto do_new_battery_select ; returns to surface loop | |
425 | |
426 ;============================================================================= | |
427 ; Setup all flags and parameters for divemode and simulator computations. | |
428 ; | |
429 global restart_set_modes_and_flags | |
430 restart_set_modes_and_flags: ; "Call"ed from dive mode as well | |
431 call option_restore_all ; restore everything from EEPROM | |
432 | |
433 ; Setup sampling rate | |
434 movlw .2 | |
435 movwf samplingrate | |
436 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
437 bra restart_set_modes_and_flags1 | |
438 movlw .10 | |
439 movwf samplingrate | |
440 | 502 |
441 restart_set_modes_and_flags1: | 503 restart_set_modes_and_flags1: |
442 bcf FLAG_gauge_mode | 504 clrf DM_flags_deco ; clear all deco mode flags |
443 bcf FLAG_apnoe_mode | 505 |
444 bcf FLAG_oc_mode | 506 ; initialize active_gas and active_dil for surface mode pressure display |
445 bcf FLAG_ccr_mode | |
446 bcf FLAG_pscr_mode | |
447 bcf FLAG_bailout_mode | |
448 call disable_ir_s8 ; IR off | |
449 | |
450 IFDEF _cave_mode | |
451 bsf FLAG_cave_mode ; enable cave mode by default | |
452 movff opt_calc_asc_gasvolume,WREG ; get gas needs calculation mode (0=off, 1=on, 2=cave mode) | |
453 xorlw .2 ; coding for cave mode | |
454 tstfsz WREG ; cave mode enabled? | |
455 bcf FLAG_cave_mode ; NO - disable cave mode again | |
456 bcf FLAG_cave_mode_shutdown ; clear flag for cave mode shutdown | |
457 bcf FLAG_dive_turned ; clear flag for dive turned | |
458 bcf gas_needs_mode_last ; set last gas calculation results as direct ascent needs | |
459 ENDIF | |
460 | |
461 ; Initialize active_gas and active_dil for surface mode pressure display | |
462 call get_first_gas_to_WREG | 507 call get_first_gas_to_WREG |
463 movwf active_gas | 508 movwf active_gas |
509 | |
510 IFDEF _ccr_pscr | |
464 call get_first_dil_to_WREG | 511 call get_first_dil_to_WREG |
465 movwf active_dil | 512 movwf active_dil |
466 | 513 ENDIF |
467 ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier | 514 |
468 movff opt_sat_multiplier_gf,char_I_saturation_multiplier | 515 ; configure saturation / desaturation safety factors |
469 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier | 516 movff opt_sat_multiplier_gf, char_I_saturation_multiplier ; use factors for GF mode by default |
470 movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF | 517 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier ; ... |
471 tstfsz lo | 518 TSTOSC char_I_deco_model ; get deco model ZH-L16-GF (1) selected? |
472 bra restart_set_modes_and_flags1b | 519 bra restart_set_modes_and_flags2 ; YES - keep them |
473 movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier | 520 movff opt_sat_multiplier_non_gf, char_I_saturation_multiplier ; NO - overwrite them with non-GF factors |
474 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier | 521 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier ; - ... |
475 | 522 |
476 restart_set_modes_and_flags1b: | 523 restart_set_modes_and_flags2: |
477 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR | 524 ; configure GF settings, GF high is needed for color-coding the current GF (supersaturation) factor |
478 tstfsz lo | 525 movff opt_GF_low, char_I_GF_Low_percentage |
479 bra restart_set_modes_and_flags2 | 526 movff opt_GF_high,char_I_GF_High_percentage |
480 | 527 |
481 ; OC Mode | 528 movff opt_dive_mode,lo ; get dive mode: 0= OC, 1= CCR, 2= gauge, 3= apnea, 4= pSCR |
482 bsf FLAG_oc_mode ; =1: OC mode active | 529 tstfsz lo ; OC? |
530 bra restart_set_modes_and_flags3 ; NO | |
531 bsf FLAG_oc_mode ; YES - set OC flag | |
483 IFDEF _rx_functions | 532 IFDEF _rx_functions |
484 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | 533 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
485 ENDIF | 534 ENDIF |
486 return | 535 return ; - done |
487 | 536 |
488 restart_set_modes_and_flags2: | 537 restart_set_modes_and_flags3: |
489 decfsz lo,F | 538 decfsz lo,F ; CCR mode? |
490 bra restart_set_modes_and_flags3 | 539 bra restart_set_modes_and_flags4 ; NO |
491 | 540 IFDEF _ccr_pscr |
492 ; CCR Mode | 541 bsf FLAG_ccr_mode ; YES - set CCR flag |
493 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active | 542 call option_cleanup_oCCRMode_CCR ; - revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available |
494 call option_cleanup_oCCRMode_CCR ; revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available | |
495 IFDEF _rx_functions | 543 IFDEF _rx_functions |
496 call option_cleanup_oTrMode_CCR ; revert TR mode from 'ind.double' to 'on' | 544 call option_cleanup_oTrMode_CCR ; - revert TR mode from 'ind.double' to 'on' |
545 ENDIF ; _rx_functions | |
546 IFDEF _external_sensor | |
547 call enable_ir_s8 ; - enable IR/S8 digital interface | |
548 ENDIF ; _external_sensor | |
549 ENDIF ; _ccr_pscr | |
550 return ; - done | |
551 | |
552 restart_set_modes_and_flags4: | |
553 decfsz lo,F ; Gauge mode? | |
554 bra restart_set_modes_and_flags5 ; NO | |
555 bsf FLAG_gauge_mode ; YES - set gauge flag | |
556 IFDEF _rx_functions | |
557 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' | |
497 ENDIF | 558 ENDIF |
498 call enable_ir_s8 ; enable IR/S8 port | 559 return ; - done |
499 return | 560 |
500 | 561 restart_set_modes_and_flags5: |
501 restart_set_modes_and_flags3: | 562 decfsz lo,F ; Apnea mode? |
502 decfsz lo,F | 563 bra restart_set_modes_and_flags6 ; NO |
503 bra restart_set_modes_and_flags4 | 564 bsf FLAG_apnoe_mode ; YES - set apnea flag |
504 | 565 movlw samplingrate_apnoe ; get apnoe sampling rate |
505 ; Gauge Mode | 566 movwf sampling_rate ; overwrite user-selected 2/10 seconds setting with apnoe default |
506 bsf FLAG_gauge_mode ; =1: in gauge mode | |
507 IFDEF _rx_functions | 567 IFDEF _rx_functions |
508 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | 568 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
509 ENDIF | 569 ENDIF |
510 return | 570 return ; - done |
511 | 571 |
512 restart_set_modes_and_flags4: | 572 restart_set_modes_and_flags6: |
513 decfsz lo,F | 573 ; pSCR mode then |
514 bra restart_set_modes_and_flags5 | 574 IFDEF _ccr_pscr |
515 | 575 bsf FLAG_pscr_mode ; - set pSCR mode flag |
516 ; Apnea Mode | 576 call option_cleanup_oCCRMode_pSCR ; - revert AutoSP to calculated SP, additionally revert Sensor to fixed SP if no sensor interface available |
517 bsf FLAG_apnoe_mode ; =1: in Apnea mode | |
518 IFDEF _rx_functions | 577 IFDEF _rx_functions |
519 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | 578 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
520 ENDIF | 579 ENDIF ; _rx_functions |
521 return ; start in surface mode | 580 IFDEF _external_sensor |
522 | 581 call enable_ir_s8 ; - enable IR/S8 digital interface |
523 restart_set_modes_and_flags5: | 582 ENDIF ; _external_sensor |
524 ; pSCR Mode | 583 ENDIF ; _ccr_pscr |
525 bsf FLAG_pscr_mode ; set pSCR mode flag | 584 return ; - done |
526 call option_cleanup_oCCRMode_pSCR ; in pSCR mode, revert AutoSP (2) to calculated SP (0), additionally revert Sensor to fixed SP if no sensor interface available | 585 |
527 IFDEF _rx_functions | 586 |
528 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | 587 ;============================================================================= |
529 ENDIF | 588 ; Sample and store the current surface pressure, update ISR and deco engine |
530 call enable_ir_s8 ; enable IR/S8 port | 589 ; with the surface pressure sampled on last invocation. |
531 return ; start in surface mode | 590 ; |
532 | 591 global sample_surface_pressure |
533 | 592 sample_surface_pressure: |
534 ; backup the first 128 bytes from flash to EEPROM | 593 ; make sure the ISR does not read the surface pressure reference buffer while it is updated |
535 backup_flash_page: | 594 bcf update_surface_pressure ; cancel any pending load request |
536 ; Start address in internal flash | 595 |
537 movlw 0x00 | 596 ; propagate the surface pressure sampled on last invocation to the reference pressure buffer |
538 movwf TBLPTRL | 597 MOVII pressure_abs_sampled,pressure_abs_ref |
539 movwf TBLPTRH | 598 |
540 movwf TBLPTRU | 599 ; update surface pressure in the ISR |
541 | 600 bsf update_surface_pressure ; request ISR to update its surface pressure |
542 movlw .128 | 601 |
543 movwf lo ; byte counter | 602 ; update surface pressure in the deco engine |
544 clrf EEADR | 603 MOVII pressure_abs_ref,int_I_pres_surface |
545 movlw .3 | 604 |
546 movwf EEADRH ; setup backup address | 605 ; sample current absolute pressure (ISR-safe 2 byte copy) |
547 | 606 SMOVII pressure_abs,pressure_abs_sampled |
548 TBLRD*- ; dummy read to be in 128 byte block | 607 |
549 backup_flash_loop: | 608 ; limit sampled pressure to max allowed surface pressure |
550 tblrd+* ; table read with pre-increment | 609 MOVLI max_surfpressure, sub_a ; load upper limit into sub_a |
551 movff TABLAT,EEDATA ; put 1 byte | 610 MOVII pressure_abs_sampled,sub_b ; copy sampled pressure to sub_b |
552 call write_eeprom ; save it in EEPROM | 611 call cmpU16 ; sub_a - sub_b = max_surfpressure - pressure_abs_sampled |
553 incf EEADR,F | 612 btfss neg_flag ; sampled pressure > max_surfpressure ? |
554 decfsz lo,F ; 128 byte done? | 613 return ; NO - below limit, done |
555 bra backup_flash_loop ; NO - loop | 614 MOVII sub_a,pressure_abs_sampled ; YES - limit to max_surfpressure (still stored in sub_a) |
556 clrf EEADRH ; reset EEADRH | 615 return ; - done |
557 return ; done | 616 |
558 | 617 |
559 END | 618 END |