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