Mercurial > public > hwos_code
annotate src/start.asm @ 627:bf5fee575701
minor cleanup, reset rx circuity
author | heinrichsweikamp |
---|---|
date | Sun, 30 Jun 2019 23:22:32 +0200 |
parents | c40025d8e750 |
children | cd58f7fc86db |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
623 | 3 ; File start.asm combined next generation V3.03.2 |
0 | 4 ; |
5 ; Startup subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-06 : [mH] moving from OSTC code | |
11 | |
604 | 12 #include "hwos.inc" ; mandatory header |
582 | 13 #include "ms5541.inc" |
604 | 14 #include "shared_definitions.h" ; mailbox from/to p2_deco.c |
582 | 15 #include "eeprom_rs232.inc" |
16 #include "math.inc" | |
17 #include "tft.inc" | |
18 #include "surfmode.inc" | |
19 #include "wait.inc" | |
20 #include "rtc.inc" | |
21 #include "external_flash.inc" | |
22 #include "strings.inc" | |
23 #include "tft_outputs.inc" | |
24 #include "adc_lightsensor.inc" | |
25 #include "i2c.inc" | |
623 | 26 #include "divemode.inc" |
27 #include "rx_ops.inc" | |
28 | |
0 | 29 |
582 | 30 extern init_ostc |
31 extern option_restore_all | |
623 | 32 extern backup_flash_page |
582 | 33 extern restore_decodata_from_eeprom |
34 extern oPressureAdjust | |
35 extern option_reset | |
36 extern option_save | |
37 extern option_save_all | |
38 extern option_check_all | |
39 extern do_new_battery_select | |
623 | 40 extern get_battery_data |
582 | 41 extern use_old_prior_209 |
604 | 42 extern get_first_gas_to_WREG |
623 | 43 |
44 IFDEF _ccr_pscr | |
604 | 45 extern option_cleanup_oCCRMode_pSCR |
46 extern option_cleanup_oCCRMode_CCR | |
623 | 47 extern get_first_dil_to_WREG |
48 ENDIF | |
604 | 49 |
50 IFDEF _rx_functions | |
51 extern option_cleanup_oTrMode_CCR | |
52 extern option_cleanup_oTrMode_no_CCR | |
623 | 53 extern rx_firmware_new_major |
54 extern rx_firmware_new_minor | |
604 | 55 ENDIF |
56 | |
623 | 57 ;----------------------------------------------------------------------------- |
58 | |
0 | 59 |
60 ;============================================================================= | |
604 | 61 ; Reset Vector: entry point on device wake-up and hard reset |
0 | 62 ; |
623 | 63 reset_v CODE 0x00000 |
64 goto 0x1FF00 ; jump to bootloader | |
0 | 65 |
623 | 66 start_v CODE 0x00004 ; jump to application (cold-)start |
0 | 67 goto start |
582 | 68 |
0 | 69 ;============================================================================= |
582 | 70 |
623 | 71 boot CODE |
604 | 72 |
73 ;============================================================================= | |
623 | 74 ; Entry point after cold start |
75 ; | |
582 | 76 global start |
0 | 77 start: |
623 | 78 ; clear RAM banks 0-14 |
79 lfsr FSR0,0x000 ; load start address into FSR0 | |
80 movlw 0x0F ; load end address into WREG (actually its high byte) | |
81 start_clear_rambank: | |
82 clrf POSTINC0 ; clear memory location and increment FSR0 | |
83 cpfseq FSR0H ; has FSR0 reached begin of bank 15, i.e. banks 0-14 done? | |
84 bra start_clear_rambank ; NO - loop | |
0 | 85 |
623 | 86 ; initialize hardware (ports, timers, interrupts, etc.) |
87 call init_ostc ; also selects bank common and sets CPU to normal speed | |
88 | |
89 ; flag that later restart origins from a cold start | |
90 bsf cold_start | |
0 | 91 |
623 | 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 | |
582 | 97 bsf analog_switches |
98 movlw 0x7C | |
99 movwf TBLPTRL | |
100 movlw 0xF7 | |
101 movwf TBLPTRH | |
102 movlw 0x01 | |
103 movwf TBLPTRU | |
623 | 104 TBLRD*+ ; read configuration byte |
105 movlw 0x07 ; coding for analog buttons | |
106 cpfseq TABLAT ; equal? | |
107 bcf analog_switches ; NO - no analog buttons | |
475 | 108 |
623 | 109 ; get screen type (2) from bootloader info |
110 bsf screen_type2 | |
614 | 111 movlw 0x80 |
623 | 112 movwf TBLPTRL ; only low byte adjustment needed, high and upper are still at 0x01F7xx |
113 TBLRD*+ ; read configuration byte | |
114 movlw 0x83 ; coding for screen type 2 | |
115 cpfseq TABLAT ; equal? | |
116 bcf screen_type2 ; NO - not screen type 2 | |
608 | 117 |
623 | 118 ; get button polarity from configuration data (EEPROM) |
582 | 119 movlw LOW .897 |
475 | 120 movwf EEADR |
582 | 121 movlw HIGH .897 |
475 | 122 movwf EEADRH |
604 | 123 call read_eeprom ; EEDATA into EEPROM @ EEADR |
124 clrf EEADRH ; reset EEADRH | |
125 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) | |
475 | 126 |
623 | 127 ; initialize pressure sensor calibration |
582 | 128 call get_calibration_data ; get calibration data from pressure sensor |
129 call TFT_DisplayOff ; turn off display | |
623 | 130 |
131 ; wait for calibration data to take effect | |
132 bsf LEDr ; turn on red LED | |
582 | 133 |
623 | 134 ; first pass, will not have valid temperature yet |
135 bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on | |
136 btfss trigger_pres_update ; has the ISR confirmed a pressure update? | |
137 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
0 | 138 |
623 | 139 ; second pass - complete sensor initialization |
140 bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on | |
141 btfss trigger_pres_update ; has the ISR confirmed a pressure update? | |
142 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
0 | 143 |
623 | 144 ; sensor calibration completed, first valid pressure value is available |
145 bcf LEDr ; turn off red LED again | |
0 | 146 |
623 | 147 ; load surface pressure into ISR |
148 ; initially needs to be done twice in order to shift the current absolute pressure through the | |
149 ; 15 minutes sampling buffer into the reference buffer from where it is loaded by the ISR | |
150 rcall sample_surface_pressure ; 1st pass | |
151 rcall sample_surface_pressure ; 2nd pass | |
152 btfsc update_surface_pressure ; has the ISR confirmed loading of the surface pressure? | |
153 bra $-2 ; NO - not yet, loop until ISR has confirmed loading | |
560 | 154 |
623 | 155 ; reset all tissue pressures to surface pressure equilibrium state by default |
156 call deco_clear_tissue ; (C-code) | |
157 banksel common | |
0 | 158 |
623 | 159 ; restore tissue pressures from EEPROM (if available) |
582 | 160 movlw HIGH .512 ; =2 |
623 | 161 movwf EEADRH ; set EEPROM address, high byte |
582 | 162 read_int_eeprom .0 |
163 clrf EEADRH | |
623 | 164 movlw 0xAA ; coding for tissue pressures available |
165 cpfseq EEDATA ; tissue pressures available? | |
166 bra start_1 ; NO - no tissue pressures available | |
167 call restore_decodata_from_eeprom ; YES - reload tissue pressures from EEPROM | |
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
168 |
623 | 169 start_1: |
170 bsf reset_surface_interval ; request ISR to reset the surface interval timer | |
582 | 171 |
623 | 172 ; call rtc_init ; initialize the real time clock (will reset to firmware creation date) |
0 | 173 |
623 | 174 ; check for power-on reset |
604 | 175 btfsc RCON,POR ; was this a power-on reset? |
623 | 176 call use_old_prior_209 ; NO - migrate the last battery status from firmware 2.09 or earlier |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
177 |
623 | 178 bcf use_old_batt_flag ; default to no reload of last battery data |
604 | 179 btfsc RCON,POR ; was this a power-on reset? |
623 | 180 bsf use_old_batt_flag ; NO - reload last battery data |
181 | |
604 | 182 call lt2942_get_status ; check for gauge IC |
582 | 183 btfss battery_gauge_available ; cR or 2 hardware? |
623 | 184 bra start_check_new_firmware ; NO - skip next |
185 movlw .30 ; YES - load default button sensitivity | |
186 movff WREG,opt_cR_button_right ; - set default for left button | |
187 movff WREG,opt_cR_button_left ; - set default for right button | |
188 call piezo_config ; - configure buttons, 1st pass | |
189 call piezo_config ; - configure buttons, 2nd pass | |
604 | 190 |
623 | 191 start_check_new_firmware: |
192 call TFT_boot ; initialize TFT (includes clear screen & backlight switch-off) | |
604 | 193 |
623 | 194 ; show heinrichsweikamp logo |
604 | 195 WIN_TOP .40 |
196 WIN_LEFT .10 | |
623 | 197 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block |
604 | 198 |
623 | 199 ; check if a new firmware was loaded, if yes reset option oPressureAdjust |
200 movlw d'1' ; set EEPROM address to 0x101 | |
201 movwf EEADR ; = 0x001 | |
202 movwf EEADRH ; = 0x101 | |
203 call read_eeprom ; read current version, major | |
204 movff EEDATA,lo ; store major in lo | |
205 incf EEADR,F ; set EEPROM address to 0x102 | |
206 call read_eeprom ; read current version, minor | |
207 movff EEDATA,hi ; store minor in hi | |
604 | 208 clrf EEADRH ; reset EEADRH |
0 | 209 |
623 | 210 movlw softwareversion_x ; get current major version |
211 cpfseq lo ; compare with stored version, equal? | |
212 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM | |
0 | 213 |
623 | 214 movlw softwareversion_y ; get current minor version |
215 cpfseq hi ; compare with stored version, equal? | |
216 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM | |
217 bra start_check_new_firmware_old ; YES - both equal, do not reset options | |
582 | 218 |
623 | 219 start_check_new_firmware_new: |
220 ; new firmware version detected | |
221 call show_fw_mesg_update ; show firmware update message | |
222 | |
582 | 223 ; place "after-update reset" here... |
623 | 224 lfsr FSR0,oPressureAdjust ; memory address of option data |
604 | 225 call option_reset ; reset oPressureAdjust to factory default |
623 | 226 lfsr FSR0,oPressureAdjust ; memory address of option data |
227 call option_save ; save reseted value of oPressureAdjust in EEPROM | |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
228 |
623 | 229 ; store current version in EEPROM |
230 movlw d'1' ; set EEPROM address to 0x101 | |
231 movwf EEADR ; = 0x001 | |
232 movwf EEADRH ; = 0x101 | |
233 movlw softwareversion_x ; get version, major number | |
234 movwf EEDATA ; prepare write | |
235 call write_eeprom ; execute write | |
236 incf EEADR,F ; set EEPROM address to 0x102 | |
237 movlw softwareversion_y ; get version, minor number | |
238 movwf EEDATA ; prepare write | |
239 call write_eeprom ; execute write | |
604 | 240 clrf EEADRH ; reset EEADRH |
623 | 241 bra start_check_new_firmware_common ; |
0 | 242 |
623 | 243 start_check_new_firmware_old: |
244 call show_fw_mesg_kept ; show firmware is kept message | |
245 | |
246 start_check_new_firmware_common: | |
247 call TFT_Display_FadeIn ; display resulting screen | |
248 call backup_flash_page ; back-up the first 128 bytes from program flash memory to EEPROM | |
249 | |
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 | |
604 | 257 |
0 | 258 |
623 | 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 ; | |
582 | 265 global restart |
0 | 266 restart: |
623 | 267 banksel common ; for safety purpose only |
268 clrf STKPTR ; clear return addresses stack | |
582 | 269 clrf CCP1CON ; stop PWM |
604 | 270 bcf PORTC,2 ; pull PWM out to GND |
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
271 |
623 | 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? | |
604 | 276 call option_save_all ; YES - save all settings into EEPROM |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
277 |
623 | 278 btfss surfmode_menu ; was restart entered by return from surface menu or comm mode? |
279 call option_restore_all ; NO - load all settings from EEPROM | |
280 | |
281 call option_check_all ; check all options and repair them if not within their min/max boundaries | |
282 | |
283 btfsc option_repaired ; errors found & repaired during options check? | |
284 call option_save_all ; YES - save corrected settings into EEPROM | |
285 | |
286 ; clear flag groups | |
287 clrf HW_descriptor ; hardware - OSTC model descriptor | |
288 clrf HW_flags_state ; hardware - status | |
289 clrf DM_flags_sensor ; hardware - O2 sensors | |
290 | |
291 clrf OS_flags_ISR1 ; operating system - ISR control 1 | |
292 clrf OS_flags_ISR2 ; operating system - ISR control 2 | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
293 |
623 | 294 clrf eventbase ; event triggers generated by ISR |
295 | |
296 clrf DM_flags_deco ; dive deco modes | |
297 | |
298 clrf MS_flags_control ; menu system - control | |
299 clrf MS_flags_imprint ; menu system - data imprinting | |
604 | 300 |
623 | 301 clrf CVT_flags1 ; convert and display functions |
302 clrf CVT_flags2 ; convert and display functions | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
303 |
623 | 304 ; TFT will be dimming soon, ignore ambient sensor |
305 bsf tft_is_dimming | |
236 | 306 |
623 | 307 ; configure the OSTC model descriptor (stored in HW_descriptor) |
604 | 308 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity |
623 | 309 bsf ambient_sensor ; set ambient light sensor as available by default |
310 bsf optical_input ; set optical input as available by default | |
582 | 311 |
604 | 312 call lt2942_get_status ; check for gauge IC |
623 | 313 btfss battery_gauge_available ; OSTC 2, cR or TR? |
604 | 314 bra restart2 ; NO |
236 | 315 |
623 | 316 ; OSTC 2, cR or TR |
317 call lt2942_init ; initialize battery gauge IC | |
318 bcf optical_input ; OSTC 2, cR and TR do not have an optical input | |
319 | |
320 banksel ANCON0 ; ANCON0 is outside access RAM | |
604 | 321 bcf ANCON0,7 ; AN7 digital input |
623 | 322 banksel common ; back to bank common |
604 | 323 bcf lightsen_power ; power-down ambient light sensor |
623 | 324 bcf ambient_sensor ; no ambient light sensor by default |
582 | 325 nop |
623 | 326 btfss PORTF,2 ; ambient light sensor available? |
604 | 327 bsf ambient_sensor ; YES |
623 | 328 banksel ANCON0 ; ANCON0 is outside access RAM |
604 | 329 bsf ANCON0,7 ; AN7 analog again |
623 | 330 banksel common ; back to bank common |
604 | 331 bsf lightsen_power ; power-up ambient light sensor again |
582 | 332 |
243 | 333 restart2: |
623 | 334 btfsc vusb_in ; USB power detected? |
335 bra restart3 ; YES | |
336 bcf PORTE,0 ; start comm | |
337 WAITMS d'5' ; wait 5 ms | |
338 btfss vusb_in ; USB power detected? | |
339 bra restart3 ; NO | |
340 bsf ble_available ; YES - BLE available | |
582 | 341 |
342 restart3: | |
623 | 343 bsf PORTE,0 ; stop comm |
604 | 344 btfsc ble_available ; BLE available? |
345 bra restart4 ; YES - can't be a cR | |
346 btfss battery_gauge_available ; rechargeable? | |
347 bra restart4 ; NO - can't be a cR | |
348 bsf analog_o2_input ; set flag for analog | |
582 | 349 |
604 | 350 restart4: |
623 | 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 | |
604 | 371 IFDEF _rx_functions |
623 | 372 |
373 ; set TR functions as deactivated by default | |
374 bcf tr_functions_activated ; clear flag | |
375 | |
376 ; search for TR module | |
377 WAITMS .200 ; wait 200 ms while RX module boots up | |
378 call I2C_probe_OSTC_rx ; check for RX module and set ostc_rx_present flag if found | |
379 btfss ostc_rx_present ; RX module detected? | |
380 bra restart5 ; NO | |
381 | |
382 ; check if TR module firmware is up to date | |
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 | |
604 | 392 |
623 | 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 | |
582 | 409 |
623 | 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? | |
604 | 429 bra restart5 ; NO |
623 | 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 | |
604 | 433 |
623 | 434 ENDIF ; _rx_functions |
435 | |
604 | 436 |
437 restart5: | |
623 | 438 ; manage hardware |
439 btfss analog_o2_input ; OSTC with analog input? | |
440 bsf TRISB,3 ; NO - shut down power supply for S8 bulkhead | |
0 | 441 |
623 | 442 btfss battery_gauge_available ; OSTC with gauge IC? |
443 bsf TRISG,0 ; NO | |
444 | |
582 | 445 call ext_flash_disable_protection ; disable write protection for external flash |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
446 |
623 | 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 | |
582 | 454 |
623 | 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 | |
582 | 475 |
476 btfsc RCON,POR ; was this a power-on reset? | |
623 | 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 | |
0 | 481 |
482 ;============================================================================= | |
623 | 483 ; Setup all flags and parameters for dive mode and simulator computations |
484 ; | |
485 ; called from divemode.asm, menu_tree.asm and surfmode.asm | |
0 | 486 ; |
487 global restart_set_modes_and_flags | |
623 | 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 | |
493 ENDIF | |
24 | 494 |
623 | 495 ; setup sampling rate |
496 movlw .2 ; default to 2 seconds | |
497 movwf sampling_rate ; write setting | |
498 TSTOSS opt_sampling_rate ; check option: 1= 10s, 0= 2s | |
499 bra restart_set_modes_and_flags1 ; 0 - 2 seconds selected, done | |
500 movlw .10 ; 1 - change to 10 seconds | |
501 movwf sampling_rate ; - write setting | |
582 | 502 |
24 | 503 restart_set_modes_and_flags1: |
623 | 504 clrf DM_flags_deco ; clear all deco mode flags |
0 | 505 |
623 | 506 ; initialize active_gas and active_dil for surface mode pressure display |
604 | 507 call get_first_gas_to_WREG |
508 movwf active_gas | |
623 | 509 |
510 IFDEF _ccr_pscr | |
604 | 511 call get_first_dil_to_WREG |
512 movwf active_dil | |
623 | 513 ENDIF |
582 | 514 |
623 | 515 ; configure saturation / desaturation safety factors |
516 movff opt_sat_multiplier_gf, char_I_saturation_multiplier ; use factors for GF mode by default | |
517 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier ; ... | |
518 TSTOSC char_I_deco_model ; get deco model ZH-L16-GF (1) selected? | |
519 bra restart_set_modes_and_flags2 ; YES - keep them | |
520 movff opt_sat_multiplier_non_gf, char_I_saturation_multiplier ; NO - overwrite them with non-GF factors | |
521 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier ; - ... | |
0 | 522 |
523 restart_set_modes_and_flags2: | |
623 | 524 ; configure GF settings, GF high is needed for color-coding the current GF (supersaturation) factor |
525 movff opt_GF_low, char_I_GF_Low_percentage | |
526 movff opt_GF_high,char_I_GF_High_percentage | |
582 | 527 |
623 | 528 movff opt_dive_mode,lo ; get dive mode: 0= OC, 1= CCR, 2= gauge, 3= apnea, 4= pSCR |
529 tstfsz lo ; OC? | |
530 bra restart_set_modes_and_flags3 ; NO | |
531 bsf FLAG_oc_mode ; YES - set OC flag | |
604 | 532 IFDEF _rx_functions |
623 | 533 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 534 ENDIF |
623 | 535 return ; - done |
0 | 536 |
537 restart_set_modes_and_flags3: | |
623 | 538 decfsz lo,F ; CCR mode? |
539 bra restart_set_modes_and_flags4 ; NO | |
540 IFDEF _ccr_pscr | |
541 bsf FLAG_ccr_mode ; YES - set CCR flag | |
542 call option_cleanup_oCCRMode_CCR ; - revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available | |
604 | 543 IFDEF _rx_functions |
623 | 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 | |
0 | 551 |
552 restart_set_modes_and_flags4: | |
623 | 553 decfsz lo,F ; Gauge mode? |
554 bra restart_set_modes_and_flags5 ; NO | |
555 bsf FLAG_gauge_mode ; YES - set gauge flag | |
604 | 556 IFDEF _rx_functions |
623 | 557 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 558 ENDIF |
623 | 559 return ; - done |
0 | 560 |
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
561 restart_set_modes_and_flags5: |
623 | 562 decfsz lo,F ; Apnea mode? |
563 bra restart_set_modes_and_flags6 ; NO | |
564 bsf FLAG_apnoe_mode ; YES - set apnea flag | |
565 movlw samplingrate_apnoe ; get apnoe sampling rate | |
566 movwf sampling_rate ; overwrite user-selected 2/10 seconds setting with apnoe default | |
604 | 567 IFDEF _rx_functions |
623 | 568 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 569 ENDIF |
623 | 570 return ; - done |
571 | |
572 restart_set_modes_and_flags6: | |
573 ; pSCR mode then | |
574 IFDEF _ccr_pscr | |
575 bsf FLAG_pscr_mode ; - set pSCR mode flag | |
576 call option_cleanup_oCCRMode_pSCR ; - revert AutoSP to calculated SP, additionally revert Sensor to fixed SP if no sensor interface available | |
577 IFDEF _rx_functions | |
578 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' | |
579 ENDIF ; _rx_functions | |
580 IFDEF _external_sensor | |
581 call enable_ir_s8 ; - enable IR/S8 digital interface | |
582 ENDIF ; _external_sensor | |
583 ENDIF ; _ccr_pscr | |
584 return ; - done | |
560 | 585 |
582 | 586 |
623 | 587 ;============================================================================= |
588 ; Sample and store the current surface pressure, update ISR and deco engine | |
589 ; with the surface pressure sampled on last invocation. | |
590 ; | |
591 global sample_surface_pressure | |
592 sample_surface_pressure: | |
593 ; make sure the ISR does not read the surface pressure reference buffer while it is updated | |
594 bcf update_surface_pressure ; cancel any pending load request | |
595 | |
596 ; propagate the surface pressure sampled on last invocation to the reference pressure buffer | |
597 MOVII pressure_abs_sampled,pressure_abs_ref | |
598 | |
599 ; update surface pressure in the ISR | |
600 bsf update_surface_pressure ; request ISR to update its surface pressure | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
601 |
623 | 602 ; update surface pressure in the deco engine |
603 MOVII pressure_abs_ref,int_I_pres_surface | |
604 | |
605 ; sample current absolute pressure (ISR-safe 2 byte copy) | |
606 SMOVII pressure_abs,pressure_abs_sampled | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
607 |
623 | 608 ; limit sampled pressure to max allowed surface pressure |
609 MOVLI max_surfpressure, sub_a ; load upper limit into sub_a | |
610 MOVII pressure_abs_sampled,sub_b ; copy sampled pressure to sub_b | |
611 call cmpU16 ; sub_a - sub_b = max_surfpressure - pressure_abs_sampled | |
612 btfss neg_flag ; sampled pressure > max_surfpressure ? | |
613 return ; NO - below limit, done | |
614 MOVII sub_a,pressure_abs_sampled ; YES - limit to max_surfpressure (still stored in sub_a) | |
615 return ; - done | |
616 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
617 |
0 | 618 END |