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