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