Mercurial > public > hwos_code
annotate src/start.asm @ 629:237931377539
3.07 stable release
author | heinrichsweikamp |
---|---|
date | Fri, 29 Nov 2019 18:48:11 +0100 |
parents | cd58f7fc86db |
children | 185ba2f91f59 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
629 | 3 ; File start.asm combined next generation V3.06.1 |
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 | |
628 | 53 ENDIF |
54 | |
55 IFDEF _rx_update | |
623 | 56 extern rx_firmware_new_major |
57 extern rx_firmware_new_minor | |
604 | 58 ENDIF |
59 | |
623 | 60 ;----------------------------------------------------------------------------- |
61 | |
0 | 62 |
63 ;============================================================================= | |
604 | 64 ; Reset Vector: entry point on device wake-up and hard reset |
0 | 65 ; |
623 | 66 reset_v CODE 0x00000 |
67 goto 0x1FF00 ; jump to bootloader | |
0 | 68 |
623 | 69 start_v CODE 0x00004 ; jump to application (cold-)start |
0 | 70 goto start |
582 | 71 |
0 | 72 ;============================================================================= |
582 | 73 |
623 | 74 boot CODE |
604 | 75 |
76 ;============================================================================= | |
623 | 77 ; Entry point after cold start |
78 ; | |
582 | 79 global start |
0 | 80 start: |
623 | 81 ; clear RAM banks 0-14 |
82 lfsr FSR0,0x000 ; load start address into FSR0 | |
83 movlw 0x0F ; load end address into WREG (actually its high byte) | |
84 start_clear_rambank: | |
85 clrf POSTINC0 ; clear memory location and increment FSR0 | |
86 cpfseq FSR0H ; has FSR0 reached begin of bank 15, i.e. banks 0-14 done? | |
87 bra start_clear_rambank ; NO - loop | |
0 | 88 |
623 | 89 ; initialize hardware (ports, timers, interrupts, etc.) |
90 call init_ostc ; also selects bank common and sets CPU to normal speed | |
91 | |
92 ; flag that later restart origins from a cold start | |
93 bsf cold_start | |
0 | 94 |
623 | 95 ; initialize averaging for analog buttons |
96 movlw .16 ; set averaging span | |
97 movff WREG,analog_counter ; write to counter | |
98 | |
99 ; get button type from bootloader info | |
582 | 100 bsf analog_switches |
101 movlw 0x7C | |
102 movwf TBLPTRL | |
103 movlw 0xF7 | |
104 movwf TBLPTRH | |
105 movlw 0x01 | |
106 movwf TBLPTRU | |
623 | 107 TBLRD*+ ; read configuration byte |
108 movlw 0x07 ; coding for analog buttons | |
109 cpfseq TABLAT ; equal? | |
110 bcf analog_switches ; NO - no analog buttons | |
475 | 111 |
623 | 112 ; get screen type (2) from bootloader info |
113 bsf screen_type2 | |
628 | 114 bsf screen_type3 |
614 | 115 movlw 0x80 |
623 | 116 movwf TBLPTRL ; only low byte adjustment needed, high and upper are still at 0x01F7xx |
117 TBLRD*+ ; read configuration byte | |
118 movlw 0x83 ; coding for screen type 2 | |
119 cpfseq TABLAT ; equal? | |
628 | 120 bcf screen_type2 ; NO - not screen type 2 |
121 movlw 0x84 ; coding for screen type 3 | |
122 cpfseq TABLAT ; equal? | |
123 bcf screen_type3 ; NO - not screen type 3 | |
608 | 124 |
623 | 125 ; get button polarity from configuration data (EEPROM) |
582 | 126 movlw LOW .897 |
475 | 127 movwf EEADR |
582 | 128 movlw HIGH .897 |
475 | 129 movwf EEADRH |
604 | 130 call read_eeprom ; EEDATA into EEPROM @ EEADR |
131 clrf EEADRH ; reset EEADRH | |
132 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) | |
475 | 133 |
623 | 134 ; initialize pressure sensor calibration |
582 | 135 call get_calibration_data ; get calibration data from pressure sensor |
136 call TFT_DisplayOff ; turn off display | |
623 | 137 |
138 ; wait for calibration data to take effect | |
139 bsf LEDr ; turn on red LED | |
582 | 140 |
623 | 141 ; first pass, will not have valid temperature yet |
628 | 142 call wait_1s |
143 call wait_1s | |
144 ; bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on | |
145 ; btfss trigger_pres_update ; has the ISR confirmed a pressure update? | |
146 ; bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
0 | 147 |
623 | 148 ; second pass - complete sensor initialization |
628 | 149 call wait_1s |
150 call wait_1s | |
151 ; bcf trigger_pres_update ; make sure ISR pressure update confirmation is not older than from now on | |
152 ; btfss trigger_pres_update ; has the ISR confirmed a pressure update? | |
153 ; bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
0 | 154 |
623 | 155 ; sensor calibration completed, first valid pressure value is available |
156 bcf LEDr ; turn off red LED again | |
0 | 157 |
623 | 158 ; load surface pressure into ISR |
159 ; initially needs to be done twice in order to shift the current absolute pressure through the | |
160 ; 15 minutes sampling buffer into the reference buffer from where it is loaded by the ISR | |
161 rcall sample_surface_pressure ; 1st pass | |
162 rcall sample_surface_pressure ; 2nd pass | |
629 | 163 |
164 ; wait until initial surface pressure value has been loaded into the ISR | |
623 | 165 btfsc update_surface_pressure ; has the ISR confirmed loading of the surface pressure? |
166 bra $-2 ; NO - not yet, loop until ISR has confirmed loading | |
560 | 167 |
623 | 168 ; reset all tissue pressures to surface pressure equilibrium state by default |
169 call deco_clear_tissue ; (C-code) | |
170 banksel common | |
0 | 171 |
623 | 172 ; restore tissue pressures from EEPROM (if available) |
582 | 173 movlw HIGH .512 ; =2 |
623 | 174 movwf EEADRH ; set EEPROM address, high byte |
629 | 175 read_int_eeprom .0 ; read tissue storage information flag |
176 clrf EEADRH ; revert EEPROM high address pointer to default | |
177 movlw 0xAA ; load coding for tissue pressures available | |
623 | 178 cpfseq EEDATA ; tissue pressures available? |
179 bra start_1 ; NO - no tissue pressures available | |
180 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
|
181 |
623 | 182 start_1: |
183 bsf reset_surface_interval ; request ISR to reset the surface interval timer | |
582 | 184 |
623 | 185 ; call rtc_init ; initialize the real time clock (will reset to firmware creation date) |
0 | 186 |
623 | 187 ; check for power-on reset |
604 | 188 btfsc RCON,POR ; was this a power-on reset? |
623 | 189 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
|
190 |
623 | 191 bcf use_old_batt_flag ; default to no reload of last battery data |
604 | 192 btfsc RCON,POR ; was this a power-on reset? |
623 | 193 bsf use_old_batt_flag ; NO - reload last battery data |
194 | |
604 | 195 call lt2942_get_status ; check for gauge IC |
582 | 196 btfss battery_gauge_available ; cR or 2 hardware? |
623 | 197 bra start_check_new_firmware ; NO - skip next |
198 movlw .30 ; YES - load default button sensitivity | |
199 movff WREG,opt_cR_button_right ; - set default for left button | |
200 movff WREG,opt_cR_button_left ; - set default for right button | |
201 call piezo_config ; - configure buttons, 1st pass | |
202 call piezo_config ; - configure buttons, 2nd pass | |
604 | 203 |
623 | 204 start_check_new_firmware: |
205 call TFT_boot ; initialize TFT (includes clear screen & backlight switch-off) | |
604 | 206 |
623 | 207 ; show heinrichsweikamp logo |
604 | 208 WIN_TOP .40 |
209 WIN_LEFT .10 | |
623 | 210 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block |
604 | 211 |
623 | 212 ; check if a new firmware was loaded, if yes reset option oPressureAdjust |
213 movlw d'1' ; set EEPROM address to 0x101 | |
214 movwf EEADR ; = 0x001 | |
215 movwf EEADRH ; = 0x101 | |
216 call read_eeprom ; read current version, major | |
217 movff EEDATA,lo ; store major in lo | |
218 incf EEADR,F ; set EEPROM address to 0x102 | |
219 call read_eeprom ; read current version, minor | |
220 movff EEDATA,hi ; store minor in hi | |
604 | 221 clrf EEADRH ; reset EEADRH |
0 | 222 |
623 | 223 movlw softwareversion_x ; get current major version |
224 cpfseq lo ; compare with stored version, equal? | |
225 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM | |
0 | 226 |
623 | 227 movlw softwareversion_y ; get current minor version |
228 cpfseq hi ; compare with stored version, equal? | |
229 bra start_check_new_firmware_new ; NO - reset some options and store new version in EEPROM | |
230 bra start_check_new_firmware_old ; YES - both equal, do not reset options | |
582 | 231 |
623 | 232 start_check_new_firmware_new: |
233 ; new firmware version detected | |
234 call show_fw_mesg_update ; show firmware update message | |
235 | |
582 | 236 ; place "after-update reset" here... |
623 | 237 lfsr FSR0,oPressureAdjust ; memory address of option data |
604 | 238 call option_reset ; reset oPressureAdjust to factory default |
623 | 239 lfsr FSR0,oPressureAdjust ; memory address of option data |
240 call option_save ; save reseted value of oPressureAdjust in EEPROM | |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
241 |
623 | 242 ; store current version in EEPROM |
243 movlw d'1' ; set EEPROM address to 0x101 | |
244 movwf EEADR ; = 0x001 | |
245 movwf EEADRH ; = 0x101 | |
246 movlw softwareversion_x ; get version, major number | |
247 movwf EEDATA ; prepare write | |
248 call write_eeprom ; execute write | |
249 incf EEADR,F ; set EEPROM address to 0x102 | |
250 movlw softwareversion_y ; get version, minor number | |
251 movwf EEDATA ; prepare write | |
252 call write_eeprom ; execute write | |
604 | 253 clrf EEADRH ; reset EEADRH |
623 | 254 bra start_check_new_firmware_common ; |
0 | 255 |
623 | 256 start_check_new_firmware_old: |
257 call show_fw_mesg_kept ; show firmware is kept message | |
258 | |
259 start_check_new_firmware_common: | |
260 call TFT_Display_FadeIn ; display resulting screen | |
261 call backup_flash_page ; back-up the first 128 bytes from program flash memory to EEPROM | |
262 | |
263 ; pause 5 seconds | |
264 movlw .5 ; load loop counter | |
265 start_check_new_firmware_wait: | |
266 call wait_1s ; wait <= 1 second | |
267 decfsz WREG,W ; decrement loop counter, did it became zero? | |
268 bra start_check_new_firmware_wait ; NO - loop | |
269 ;bra restart ; YES - proceed with restart | |
604 | 270 |
0 | 271 |
623 | 272 ;============================================================================= |
273 ; Entry point after warm start | |
274 ; | |
275 ; called on leaving sleep mode, surface menu, communication mode, and | |
276 ; when a start of a dive is detected in all modes except surface mode. | |
277 ; | |
582 | 278 global restart |
0 | 279 restart: |
623 | 280 banksel common ; for safety purpose only |
281 clrf STKPTR ; clear return addresses stack | |
582 | 282 clrf CCP1CON ; stop PWM |
604 | 283 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
|
284 |
623 | 285 call request_speed_normal ; request CPU speed change to normal speed (for safety only) |
286 | |
287 ; manage the option settings | |
288 btfsc surfmode_menu ; was restart entered by return from surface menu or comm mode? | |
604 | 289 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
|
290 |
623 | 291 btfss surfmode_menu ; was restart entered by return from surface menu or comm mode? |
292 call option_restore_all ; NO - load all settings from EEPROM | |
293 | |
294 call option_check_all ; check all options and repair them if not within their min/max boundaries | |
295 | |
296 btfsc option_repaired ; errors found & repaired during options check? | |
297 call option_save_all ; YES - save corrected settings into EEPROM | |
298 | |
299 ; clear flag groups | |
300 clrf HW_descriptor ; hardware - OSTC model descriptor | |
628 | 301 clrf HW_flags_state1 ; hardware - states |
302 ; ; do not clear HW_flags_state2 ! | |
623 | 303 clrf DM_flags_sensor ; hardware - O2 sensors |
304 | |
305 clrf OS_flags_ISR1 ; operating system - ISR control 1 | |
306 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
|
307 |
623 | 308 clrf eventbase ; event triggers generated by ISR |
309 | |
310 clrf DM_flags_deco ; dive deco modes | |
311 | |
312 clrf MS_flags_control ; menu system - control | |
313 clrf MS_flags_imprint ; menu system - data imprinting | |
604 | 314 |
623 | 315 clrf CVT_flags1 ; convert and display functions |
316 clrf CVT_flags2 ; convert and display functions | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
317 |
623 | 318 ; TFT will be dimming soon, ignore ambient sensor |
319 bsf tft_is_dimming | |
236 | 320 |
623 | 321 ; configure the OSTC model descriptor (stored in HW_descriptor) |
604 | 322 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity |
623 | 323 bsf ambient_sensor ; set ambient light sensor as available by default |
324 bsf optical_input ; set optical input as available by default | |
582 | 325 |
604 | 326 call lt2942_get_status ; check for gauge IC |
623 | 327 btfss battery_gauge_available ; OSTC 2, cR or TR? |
604 | 328 bra restart2 ; NO |
236 | 329 |
623 | 330 ; OSTC 2, cR or TR |
331 call lt2942_init ; initialize battery gauge IC | |
332 bcf optical_input ; OSTC 2, cR and TR do not have an optical input | |
333 | |
334 banksel ANCON0 ; ANCON0 is outside access RAM | |
604 | 335 bcf ANCON0,7 ; AN7 digital input |
623 | 336 banksel common ; back to bank common |
604 | 337 bcf lightsen_power ; power-down ambient light sensor |
623 | 338 bcf ambient_sensor ; no ambient light sensor by default |
582 | 339 nop |
623 | 340 btfss PORTF,2 ; ambient light sensor available? |
604 | 341 bsf ambient_sensor ; YES |
623 | 342 banksel ANCON0 ; ANCON0 is outside access RAM |
604 | 343 bsf ANCON0,7 ; AN7 analog again |
623 | 344 banksel common ; back to bank common |
604 | 345 bsf lightsen_power ; power-up ambient light sensor again |
582 | 346 |
243 | 347 restart2: |
628 | 348 IFNDEF _hwos_sport |
623 | 349 btfsc vusb_in ; USB power detected? |
350 bra restart3 ; YES | |
351 bcf PORTE,0 ; start comm | |
352 WAITMS d'5' ; wait 5 ms | |
353 btfss vusb_in ; USB power detected? | |
354 bra restart3 ; NO | |
628 | 355 ENDIF |
623 | 356 bsf ble_available ; YES - BLE available |
582 | 357 |
358 restart3: | |
623 | 359 bsf PORTE,0 ; stop comm |
604 | 360 btfsc ble_available ; BLE available? |
361 bra restart4 ; YES - can't be a cR | |
362 btfss battery_gauge_available ; rechargeable? | |
363 bra restart4 ; NO - can't be a cR | |
364 bsf analog_o2_input ; set flag for analog | |
582 | 365 |
604 | 366 restart4: |
623 | 367 bsf lv_core ; default to low voltage core |
368 movlw 0x80 ; point to 0x1F780 | |
369 movwf TBLPTRL | |
370 movlw 0xF7 | |
371 movwf TBLPTRH | |
372 movlw 0x01 | |
373 movwf TBLPTRU | |
374 TBLRD*+ ; read from 0x1F780 | |
375 movlw 0x83 ; coding for low voltage core, part 1 | |
376 cpfseq TABLAT ; equal? | |
377 bra restart4a ; NO - no low voltage core then | |
378 movlw 0x81 ; point to 0x1F781 | |
379 movwf TBLPTRL | |
380 TBLRD*+ ; read from 0x1F781 | |
381 movlw 0x94 ; coding for low voltage core, part 2 | |
382 cpfseq TABLAT ; equal? | |
383 restart4a: | |
384 bcf lv_core ; NO - no low voltage core then | |
385 | |
386 | |
604 | 387 IFDEF _rx_functions |
623 | 388 |
389 ; set TR functions as deactivated by default | |
390 bcf tr_functions_activated ; clear flag | |
391 | |
392 ; search for TR module | |
393 WAITMS .200 ; wait 200 ms while RX module boots up | |
394 call I2C_probe_OSTC_rx ; check for RX module and set ostc_rx_present flag if found | |
395 btfss ostc_rx_present ; RX module detected? | |
396 bra restart5 ; NO | |
397 | |
628 | 398 IFDEF _rx_update |
399 | |
623 | 400 ; check if TR module firmware is up to date |
401 movff rx_firmware_cur_major,hi ; copy current firmware on RX module to bank common, major | |
402 movff rx_firmware_cur_minor,lo ; copy current firmware on RX module to bank common, minor | |
403 call rx_firmware_new_major ; get latest firmware version into WREG, major | |
404 cpfseq hi ; equal to current firmware on RX module, major ? | |
405 bra restart4b ; NO - update | |
406 call rx_firmware_new_minor ; YES - get latest firmware version into WREG, minor | |
407 cpfseq lo ; - equal to current firmware on RX module, minor ? | |
408 bra restart4b ; NO - update TR module | |
409 bra restart4e ; YES - no need to update | |
604 | 410 |
623 | 411 restart4b: |
412 ; print TR module update message | |
413 call TFT_boot ; initialize TFT (includes clear screen & backlight switch-off) | |
414 WIN_TOP .40 ; show heinrichsweikamp logo | |
415 WIN_LEFT .10 | |
416 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block | |
417 WIN_SMALL .10,.130 | |
418 STRCAT_PRINT "Updating TR Module..." ; print update message | |
419 call TFT_Display_FadeIn ; display screen | |
420 WIN_SMALL .10,.160 | |
421 STRCAT "TR Update " ; prepare result message | |
422 | |
423 ; update firmware in RX module | |
424 call I2C_sleep_compass ; stop compass | |
425 call update_tr_module ; update TR module | |
582 | 426 |
623 | 427 WIN_SMALL .10,.160 ; set next output position |
428 STRCAT "Update " ; common part of result message | |
429 btfss ostc_rx_present ; data transfer successful and TR module up & running again? | |
430 bra restart4c ; NO | |
431 STRCAT "to " ; YES - print success message | |
432 call TFT_print_firmware_rx ; - print installed version | |
433 STRCAT_PRINT " done" ; - complete result message | |
434 bra restart4d ; - show message for a while | |
435 | |
436 restart4c: | |
437 STRCAT_PRINT "failed" ; complete result message - failure | |
438 | |
439 restart4d: | |
440 call wait_1s ; wait (up to) 1 second | |
441 call wait_1s ; wait (another full) 1 second | |
442 call wait_1s ; wait (another full) 1 second | |
443 | |
628 | 444 ENDIF ; _rx_update |
445 | |
623 | 446 restart4e: |
447 btfss ostc_rx_present ; TR module up & running? | |
604 | 448 bra restart5 ; NO |
623 | 449 movff opt_TR_mode,WREG ; YES - get TR mode |
450 tstfsz WREG ; - TR mode <> off ? | |
451 bsf tr_functions_activated ; YES - set TR functions as activated | |
604 | 452 |
623 | 453 ENDIF ; _rx_functions |
454 | |
604 | 455 |
456 restart5: | |
623 | 457 ; manage hardware |
458 btfss analog_o2_input ; OSTC with analog input? | |
459 bsf TRISB,3 ; NO - shut down power supply for S8 bulkhead | |
0 | 460 |
623 | 461 btfss battery_gauge_available ; OSTC with gauge IC? |
462 bsf TRISG,0 ; NO | |
463 | |
582 | 464 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
|
465 |
623 | 466 btfsc use_old_batt_flag ; shall reload last battery data? |
467 call get_battery_data ; YES - get last battery data | |
468 | |
469 ; set screen orientation | |
470 bcf flip_screen ; set default screen orientation | |
471 TSTOSC opt_flip_screen ; shall show screen outputs upside down? (=1: flip the screen) | |
472 bsf flip_screen ; YES - set upside-down orientation | |
582 | 473 |
623 | 474 ; check if high-altitude mode is applicable |
475 bcf high_altitude_mode ; disable high altitude mode by default | |
476 MOVII pressure_abs_ref, sub_a ; copy last surface pressure to sub_a | |
477 MOVLI high_altitude_threshold+1,sub_b ; copy high-altitude threshold (880 mbar) + 1 to sub_a | |
478 call cmpU16 ; sub_a - sub_b = pressure_abs_ref - (high_altitude_threshold + 1) | |
479 btfsc neg_flag ; result negative (absolute pressure <= 880 mbar) ? | |
480 bsf high_altitude_mode ; YES - enable high altitude mode | |
481 | |
482 ; check if there was a cold start, if yes do initial computation of further deco data | |
483 btfss cold_start ; did a cold start? | |
484 bra restart6 ; NO | |
485 bcf cold_start ; YES - clear flag | |
486 call deco_calc_dive_interval_1min ; - calculate tissues for 1 minute at surface conditions (C-code) | |
487 call deco_calc_desaturation_time ; - calculate desaturation and no-fly/no-altitude time (C-code) | |
488 banksel common ; - back to bank common | |
489 | |
490 restart6: | |
491 ; the dive mode flag can not be set right after cold start, must have been in surface mode before | |
492 btfsc divemode ; shall enter dive mode? | |
493 goto diveloop ; YES | |
582 | 494 |
495 btfsc RCON,POR ; was this a power-on reset? | |
623 | 496 goto surfloop ; NO - enter surface mode |
497 bsf RCON,POR ; YES - acknowledge detection and re-arm detector | |
498 goto do_new_battery_select ; - prompt for battery selection, will proceed to surface mode | |
499 | |
0 | 500 |
501 ;============================================================================= | |
623 | 502 ; Setup all flags and parameters for dive mode and simulator computations |
503 ; | |
504 ; called from divemode.asm, menu_tree.asm and surfmode.asm | |
0 | 505 ; |
506 global restart_set_modes_and_flags | |
623 | 507 restart_set_modes_and_flags: |
508 call option_restore_all ; restore all options settings from EEPROM | |
629 | 509 call disable_ir_s8 ; switch off IR/S8 digital interface by default (for all compile versions!) |
623 | 510 |
511 IFDEF _external_sensor | |
629 | 512 WAITMS d'100' ; some delay to power down S8-HUD properly |
623 | 513 ENDIF |
629 | 514 |
623 | 515 ; setup sampling rate |
516 movlw .2 ; default to 2 seconds | |
517 movwf sampling_rate ; write setting | |
518 TSTOSS opt_sampling_rate ; check option: 1= 10s, 0= 2s | |
519 bra restart_set_modes_and_flags1 ; 0 - 2 seconds selected, done | |
520 movlw .10 ; 1 - change to 10 seconds | |
521 movwf sampling_rate ; - write setting | |
582 | 522 |
24 | 523 restart_set_modes_and_flags1: |
623 | 524 clrf DM_flags_deco ; clear all deco mode flags |
0 | 525 |
623 | 526 ; initialize active_gas and active_dil for surface mode pressure display |
604 | 527 call get_first_gas_to_WREG |
528 movwf active_gas | |
623 | 529 |
530 IFDEF _ccr_pscr | |
604 | 531 call get_first_dil_to_WREG |
532 movwf active_dil | |
623 | 533 ENDIF |
582 | 534 |
623 | 535 ; configure saturation / desaturation safety factors |
536 movff opt_sat_multiplier_gf, char_I_saturation_multiplier ; use factors for GF mode by default | |
537 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier ; ... | |
538 TSTOSC char_I_deco_model ; get deco model ZH-L16-GF (1) selected? | |
539 bra restart_set_modes_and_flags2 ; YES - keep them | |
540 movff opt_sat_multiplier_non_gf, char_I_saturation_multiplier ; NO - overwrite them with non-GF factors | |
541 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier ; - ... | |
0 | 542 |
543 restart_set_modes_and_flags2: | |
623 | 544 ; configure GF settings, GF high is needed for color-coding the current GF (supersaturation) factor |
545 movff opt_GF_low, char_I_GF_Low_percentage | |
546 movff opt_GF_high,char_I_GF_High_percentage | |
582 | 547 |
623 | 548 movff opt_dive_mode,lo ; get dive mode: 0= OC, 1= CCR, 2= gauge, 3= apnea, 4= pSCR |
549 tstfsz lo ; OC? | |
550 bra restart_set_modes_and_flags3 ; NO | |
551 bsf FLAG_oc_mode ; YES - set OC flag | |
604 | 552 IFDEF _rx_functions |
623 | 553 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 554 ENDIF |
623 | 555 return ; - done |
0 | 556 |
557 restart_set_modes_and_flags3: | |
623 | 558 decfsz lo,F ; CCR mode? |
559 bra restart_set_modes_and_flags4 ; NO | |
560 IFDEF _ccr_pscr | |
561 bsf FLAG_ccr_mode ; YES - set CCR flag | |
562 call option_cleanup_oCCRMode_CCR ; - revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available | |
604 | 563 IFDEF _rx_functions |
623 | 564 call option_cleanup_oTrMode_CCR ; - revert TR mode from 'ind.double' to 'on' |
565 ENDIF ; _rx_functions | |
566 IFDEF _external_sensor | |
567 call enable_ir_s8 ; - enable IR/S8 digital interface | |
568 ENDIF ; _external_sensor | |
569 ENDIF ; _ccr_pscr | |
570 return ; - done | |
0 | 571 |
572 restart_set_modes_and_flags4: | |
623 | 573 decfsz lo,F ; Gauge mode? |
574 bra restart_set_modes_and_flags5 ; NO | |
575 bsf FLAG_gauge_mode ; YES - set gauge flag | |
604 | 576 IFDEF _rx_functions |
623 | 577 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 578 ENDIF |
623 | 579 return ; - done |
0 | 580 |
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
581 restart_set_modes_and_flags5: |
623 | 582 decfsz lo,F ; Apnea mode? |
583 bra restart_set_modes_and_flags6 ; NO | |
584 bsf FLAG_apnoe_mode ; YES - set apnea flag | |
585 movlw samplingrate_apnoe ; get apnoe sampling rate | |
586 movwf sampling_rate ; overwrite user-selected 2/10 seconds setting with apnoe default | |
604 | 587 IFDEF _rx_functions |
623 | 588 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
604 | 589 ENDIF |
623 | 590 return ; - done |
591 | |
592 restart_set_modes_and_flags6: | |
593 ; pSCR mode then | |
594 IFDEF _ccr_pscr | |
595 bsf FLAG_pscr_mode ; - set pSCR mode flag | |
596 call option_cleanup_oCCRMode_pSCR ; - revert AutoSP to calculated SP, additionally revert Sensor to fixed SP if no sensor interface available | |
597 IFDEF _rx_functions | |
598 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' | |
599 ENDIF ; _rx_functions | |
600 IFDEF _external_sensor | |
601 call enable_ir_s8 ; - enable IR/S8 digital interface | |
602 ENDIF ; _external_sensor | |
603 ENDIF ; _ccr_pscr | |
604 return ; - done | |
560 | 605 |
582 | 606 |
623 | 607 ;============================================================================= |
608 ; Sample and store the current surface pressure, update ISR and deco engine | |
609 ; with the surface pressure sampled on last invocation. | |
610 ; | |
611 global sample_surface_pressure | |
612 sample_surface_pressure: | |
613 ; make sure the ISR does not read the surface pressure reference buffer while it is updated | |
614 bcf update_surface_pressure ; cancel any pending load request | |
615 | |
616 ; propagate the surface pressure sampled on last invocation to the reference pressure buffer | |
617 MOVII pressure_abs_sampled,pressure_abs_ref | |
618 | |
619 ; update surface pressure in the ISR | |
620 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
|
621 |
623 | 622 ; update surface pressure in the deco engine |
623 MOVII pressure_abs_ref,int_I_pres_surface | |
624 | |
625 ; sample current absolute pressure (ISR-safe 2 byte copy) | |
626 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
|
627 |
623 | 628 ; limit sampled pressure to max allowed surface pressure |
629 MOVLI max_surfpressure, sub_a ; load upper limit into sub_a | |
630 MOVII pressure_abs_sampled,sub_b ; copy sampled pressure to sub_b | |
631 call cmpU16 ; sub_a - sub_b = max_surfpressure - pressure_abs_sampled | |
632 btfss neg_flag ; sampled pressure > max_surfpressure ? | |
633 return ; NO - below limit, done | |
634 MOVII sub_a,pressure_abs_sampled ; YES - limit to max_surfpressure (still stored in sub_a) | |
635 return ; - done | |
636 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
637 |
0 | 638 END |