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