Mercurial > public > hwos_code
comparison src/start.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 690c48db7b5b |
children | 8c1f1f334275 |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File start.asm combined next generation V3.09.1 fix | 3 ; File start.asm * combined next generation V3.09.5 |
4 ; | 4 ; |
5 ; Startup subroutines | 5 ; Startup subroutines |
6 ; | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
34 extern option_restore_and_check | 34 extern option_restore_and_check |
35 extern option_check_and_store_all | 35 extern option_check_and_store_all |
36 extern option_check_and_store | 36 extern option_check_and_store |
37 extern option_reset | 37 extern option_reset |
38 extern rtc_init | 38 extern rtc_init |
39 extern do_new_battery_select | 39 extern new_battery_select |
40 extern get_battery_data | 40 extern get_battery_data |
41 extern use_old_prior_209 | 41 extern use_old_prior_209 |
42 extern get_first_gas_to_WREG | 42 extern get_first_gas_to_WREG |
43 | 43 |
44 extern oFirmwareMajor | 44 extern oFirmwareMajor |
57 ENDIF | 57 ENDIF |
58 | 58 |
59 IFDEF _rx_update | 59 IFDEF _rx_update |
60 extern rx_firmware_new_major | 60 extern rx_firmware_new_major |
61 extern rx_firmware_new_minor | 61 extern rx_firmware_new_minor |
62 ENDIF | 62 extern dyn_show_firmware_rx |
63 | 63 ENDIF |
64 ;----------------------------------------------------------------------------- | 64 |
65 | 65 |
66 | 66 ;============================================================================= |
67 ;============================================================================= | 67 ; Reset Vector: Entry Point on Device Wake-up and hard Reset |
68 ; Reset Vector: entry point on device wake-up and hard reset | |
69 ; | 68 ; |
70 reset_v CODE 0x00000 | 69 reset_v CODE 0x00000 |
71 goto 0x1FF00 ; jump to bootloader | 70 goto 0x1FF00 ; jump to bootloader |
72 | 71 |
73 start_v CODE 0x00004 ; jump to application (cold-)start | 72 start_v CODE 0x00004 ; jump to application (cold-)start |
74 goto start | 73 goto start |
75 | 74 ; |
76 ;============================================================================= | 75 ;============================================================================= |
77 | 76 |
78 boot CODE | 77 |
79 | 78 ;============================================================================= |
80 ;============================================================================= | 79 ; Firmware Identification |
81 ; Entry point after cold start | 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 | |
82 ; | 101 ; |
83 global start | 102 global start |
84 start: | 103 start: |
104 | |
85 ; clear RAM banks 0-14 | 105 ; clear RAM banks 0-14 |
86 lfsr FSR0,0x000 ; load start address into FSR0 | 106 lfsr FSR0,0x000 ; load start address into FSR0 |
87 movlw 0x0F ; load end address into WREG (actually its high byte) | 107 movlw 0x0F ; load end address into WREG (actually its high byte) |
88 start_clear_rambank: | 108 start_clear_rambank: |
89 clrf POSTINC0 ; clear memory location and increment FSR0 | 109 clrf POSTINC0 ; clear memory location and increment FSR0 |
90 cpfseq FSR0H ; has FSR0 reached begin of bank 15, i.e. banks 0-14 done? | 110 cpfseq FSR0H ; has FSR0 reached begin of bank 15, i.e. banks 0-14 done? |
91 bra start_clear_rambank ; NO - loop | 111 bra start_clear_rambank ; NO - loop |
92 | 112 |
93 ; initialize hardware (ports, timers, interrupts, etc.) | 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 | |
94 call init_ostc ; also selects bank common and sets CPU to normal speed | 118 call init_ostc ; also selects bank common and sets CPU to normal speed |
95 | 119 |
96 ; flag that later restart origins from a cold start | 120 ; flag that later restart origins from a cold start |
97 bsf cold_start | 121 bsf cold_start |
98 | 122 |
99 ; initialize averaging for analog buttons | |
100 movlw .16 ; set averaging span | |
101 movff WREG,analog_counter ; write to counter (in bank isr_backup) | |
102 | |
103 ; get button type from bootloader info | 123 ; get button type from bootloader info |
104 bsf analog_switches ; assume analog buttons by default | 124 bsf analog_switches ; assume analog buttons by default |
105 movlw 0x7C ; address bootloader at 0x01F77C | 125 movlw 0x7C ; set up read from 0x01F77C |
106 movwf TBLPTRL ; ... | 126 movwf TBLPTRL ; ... |
107 movlw 0xF7 ; ... | 127 movlw 0xF7 ; ... |
108 movwf TBLPTRH ; ... | 128 movwf TBLPTRH ; ... |
109 movlw 0x01 ; ... | 129 movlw 0x01 ; ... |
110 movwf TBLPTRU ; ... | 130 movwf TBLPTRU ; ... |
112 movlw 0x07 ; coding for analog buttons | 132 movlw 0x07 ; coding for analog buttons |
113 cpfseq TABLAT ; equal? | 133 cpfseq TABLAT ; equal? |
114 bcf analog_switches ; NO - no analog buttons | 134 bcf analog_switches ; NO - no analog buttons |
115 | 135 |
116 ; get screen type (2) from bootloader info | 136 ; get screen type (2) from bootloader info |
117 bsf screen_type2 | 137 bsf screen_type2 ; set flags for later clear of the false one |
118 bsf screen_type3 | 138 bsf screen_type3 ; ... |
119 movlw 0x80 | 139 movlw 0x80 ; set up read from 0x01F780 |
120 movwf TBLPTRL ; only low byte adjustment needed, high and upper are still at 0x01F7xx | 140 movwf TBLPTRL ; ... |
141 ;movlw 0xF7 ; high and upper are still at 0x01F7xx | |
142 ;movwf TBLPTRH ; ... | |
143 ;movlw 0x01 ; ... | |
144 ;movwf TBLPTRU ; ... | |
121 TBLRD*+ ; read configuration byte | 145 TBLRD*+ ; read configuration byte |
122 movlw 0x83 ; coding for screen type 2 | 146 movlw 0x83 ; coding for screen type 2 |
123 cpfseq TABLAT ; equal? | 147 cpfseq TABLAT ; equal? |
124 bcf screen_type2 ; NO - not screen type 2 | 148 bcf screen_type2 ; NO - not screen type 2 |
125 movlw 0x84 ; coding for screen type 3 | 149 movlw 0x84 ; coding for screen type 3 |
129 ; get button polarity from configuration data (EEPROM) | 153 ; get button polarity from configuration data (EEPROM) |
130 EEPROM_CC_READ eeprom_button_polarity,button_polarity | 154 EEPROM_CC_READ eeprom_button_polarity,button_polarity |
131 | 155 |
132 ; initialize pressure sensor calibration | 156 ; initialize pressure sensor calibration |
133 call get_calibration_data ; get calibration data from pressure sensor | 157 call get_calibration_data ; get calibration data from pressure sensor |
158 | |
134 call TFT_DisplayOff ; turn off display | 159 call TFT_DisplayOff ; turn off display |
135 | |
136 ; wait for calibration data to take effect | |
137 bsf LEDr ; turn on red LED | 160 bsf LEDr ; turn on red LED |
138 | 161 |
139 ; first pass, will not have valid temperature yet | 162 ; wait for valid temperature and pressure |
140 call wait_1s | 163 WAITS .3 ; wait 3 seconds |
141 call wait_1s | |
142 | |
143 ; second pass - complete sensor initialization | |
144 call wait_1s | |
145 call wait_1s | |
146 | 164 |
147 ; sensor calibration completed, first valid pressure value is available | 165 ; sensor calibration completed, first valid pressure value is available |
148 bcf LEDr ; turn off red LED again | 166 bcf LEDr ; turn off red LED |
149 | 167 |
150 ; load surface pressure into ISR | 168 ; initial loading of the surface pressure into the ISR |
151 ; initially needs to be done twice in order to shift the current absolute pressure through the | 169 ; needs to be done twice in order to shift the current absolute pressure through |
152 ; 15 minutes sampling buffer into the reference buffer from where it is loaded by the ISR | 170 ; the sampling buffer into the reference buffer from where it is loaded by the ISR |
153 rcall sample_surface_pressure ; 1st pass | 171 call sample_surface_pressure ; 1st pass |
154 rcall sample_surface_pressure ; 2nd pass | 172 call sample_surface_pressure ; 2nd pass |
155 | 173 |
156 ; wait until initial surface pressure value has been loaded into the ISR | 174 ; wait until initial surface pressure value has been loaded into the ISR |
157 btfsc update_surface_pressure ; has the ISR confirmed loading of the surface pressure? | 175 btfsc update_surface_pressure ; has the ISR confirmed loading of the surface pressure? |
158 bra $-2 ; NO - not yet, loop until ISR has confirmed loading | 176 bra $-2 ; NO - not yet, loop until ISR has confirmed loading |
159 | 177 |
220 xorlw fw_version_beta ; compare with currently active version, equal? | 238 xorlw fw_version_beta ; compare with currently active version, equal? |
221 bnz start_check_new_firmware_new ; NO - a new firmware was loaded | 239 bnz start_check_new_firmware_new ; NO - a new firmware was loaded |
222 ;bz start_check_new_firmware_old ; YES - same firmware as before | 240 ;bz start_check_new_firmware_old ; YES - same firmware as before |
223 | 241 |
224 start_check_new_firmware_old: | 242 start_check_new_firmware_old: |
225 call show_fw_mesg_kept ; show firmware is kept message | 243 call TFT_message_fw_kept ; show firmware is kept message |
226 bra start_check_new_firmware_common ; continue with common part | 244 bra start_check_new_firmware_common ; continue with common part |
227 | 245 |
228 start_check_new_firmware_new: | 246 start_check_new_firmware_new: |
229 call show_fw_mesg_update ; show firmware update message | 247 call TFT_message_fw_update ; show firmware is updated message |
230 | 248 |
231 ; reset the pressure sensor correction to factory default | 249 ; ; reset the pressure sensor correction to factory default |
232 lfsr FSR0,oPressureAdjust ; address pressure sensor correction | 250 ; lfsr FSR0,oPressureAdjust ; address pressure sensor correction |
233 call option_reset ; set correction to default | 251 ; call option_reset ; set correction to default |
234 | 252 ; |
235 lfsr FSR0,oPressureAdjust ; address pressure sensor correction | 253 ; lfsr FSR0,oPressureAdjust ; address pressure sensor correction |
236 call option_check_and_store ; update correction in EEPROM | 254 ; call option_check_and_store ; update correction in EEPROM |
237 | 255 |
238 start_check_new_firmware_common: | 256 start_check_new_firmware_common: |
239 call TFT_Display_FadeIn ; display resulting screen | 257 call TFT_Display_FadeIn ; display resulting screen |
240 | 258 |
241 call backup_flash_page ; back-up the first 128 bytes from program flash memory to EEPROM | 259 call backup_flash_page ; back-up the first 128 bytes from program flash memory to EEPROM |
242 call option_restore_and_check_all ; restore all option values from EEPROM and check them | 260 call option_restore_and_check_all ; restore all option values from EEPROM and check them |
243 | 261 |
244 ; pause 5 seconds | 262 WAITS .5 ; wait 5 second |
245 movlw .5 ; load loop counter | 263 |
246 start_check_new_firmware_wait: | 264 goto restart ; proceed with restart |
247 call wait_1s ; wait <= 1 second | 265 |
248 decfsz WREG,W ; decrement loop counter, did it became zero? | 266 |
249 bra start_check_new_firmware_wait ; NO - loop | 267 ;============================================================================= |
250 ;bra restart ; YES - proceed with restart | 268 boot2 CODE |
251 | 269 ;============================================================================= |
252 | 270 |
253 ;============================================================================= | 271 |
254 ; Entry point after warm start | 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 | |
255 ; | 310 ; |
256 ; called on leaving sleep mode, surface menu, communication mode, and | 311 ; called on leaving sleep mode, surface menu, communication mode, and |
257 ; when a start of a dive is detected in all modes except surface mode. | 312 ; when a start of a dive is detected in all modes except surface mode |
258 ; | 313 ; |
259 global restart | 314 global restart |
260 restart: | 315 restart: |
316 | |
261 ; for safety purpose only | 317 ; for safety purpose only |
262 banksel common ; select bank common | 318 banksel common ; select bank common |
263 clrf STKPTR ; clear return addresses stack | 319 clrf STKPTR ; clear return addresses stack |
264 call request_speed_normal ; request CPU speed change to normal speed | 320 call request_speed_normal ; request CPU speed change to normal speed |
265 | 321 |
269 bsf tft_is_dimming ; ignore ambient sensor | 325 bsf tft_is_dimming ; ignore ambient sensor |
270 | 326 |
271 ; clear flag groups | 327 ; clear flag groups |
272 clrf HW_descriptor ; hardware - OSTC model descriptor | 328 clrf HW_descriptor ; hardware - OSTC model descriptor |
273 clrf HW_flags_state1 ; hardware - states | 329 clrf HW_flags_state1 ; hardware - states |
274 ; ; do not clear HW_flags_state2 ! | 330 ; ; DO NOT clear HW_flags_state2 ! |
275 clrf DM_flags_sensor ; hardware - O2 sensors | 331 clrf DM_flags_sensor ; hardware - O2 sensors |
276 clrf OS_flags_ISR1 ; operating system - ISR control 1 | 332 clrf OS_flags_ISR1 ; operating system - ISR control 1 |
277 clrf OS_flags_ISR2 ; operating system - ISR control 2 | 333 clrf OS_flags_ISR2 ; operating system - ISR control 2 |
278 clrf eventbase ; event triggers generated by ISR | 334 clrf eventbase ; event triggers generated by ISR |
279 clrf DM_flags_deco ; dive deco modes | 335 clrf DM_flags_deco ; dive deco modes |
280 clrf MS_flags_control ; menu system - control | 336 clrf MS_flags_control ; menu system - control |
281 clrf MS_flags_imprint ; menu system - data imprinting | 337 clrf MS_flags_imprint ; menu system - data imprinting |
282 clrf CVT_flags1 ; convert and display functions | 338 clrf CVT_flags1 ; control of numerical outputs 1 |
283 clrf CVT_flags2 ; convert and display functions | 339 clrf CVT_flags2 ; control of numerical outputs 2 |
284 | 340 |
285 ; configure the OSTC model descriptor (stored in HW_descriptor) | 341 ; configure the OSTC model descriptor (stored in HW_descriptor) |
286 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity | 342 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity |
287 bsf ambient_sensor ; set ambient light sensor as available by default | 343 bsf ambient_sensor ; set ambient light sensor as available by default |
288 bsf optical_input ; set optical input as available by default | 344 bsf ext_input_optical ; set optical input as available by default |
289 | 345 |
290 call lt2942_get_status ; check for gauge IC | 346 call lt2942_get_status ; check for gauge IC |
291 btfss battery_gauge_available ; OSTC 2, cR or TR? | 347 btfss battery_gauge_available ; OSTC 2, cR or TR? |
292 bra restart2 ; NO | 348 bra restart2 ; NO |
293 | 349 |
294 ; OSTC 2, cR or TR | 350 ; OSTC 2, cR or TR |
295 call lt2942_init ; initialize battery gauge IC | 351 call lt2942_init ; initialize battery gauge IC |
296 bcf optical_input ; OSTC 2, cR and TR do not have an optical input | 352 bcf ext_input_optical ; OSTC 2, cR and TR do not have an optical input |
297 | 353 |
298 banksel ANCON0 ; ANCON0 is outside access RAM | 354 banksel ANCON0 ; ANCON0 is outside access RAM |
299 bcf ANCON0,7 ; AN7 digital input | 355 bcf ANCON0,7 ; AN7 digital input |
300 banksel common ; back to bank common | 356 banksel common ; back to bank common |
301 bcf lightsen_power ; power-down ambient light sensor | 357 bcf lightsen_power ; power-down ambient light sensor |
309 bsf lightsen_power ; power-up ambient light sensor again | 365 bsf lightsen_power ; power-up ambient light sensor again |
310 | 366 |
311 restart2: | 367 restart2: |
312 IFNDEF _hwos_sport | 368 IFNDEF _hwos_sport |
313 btfsc vusb_in ; USB power detected? | 369 btfsc vusb_in ; USB power detected? |
314 bra restart3 ; YES - no BLE then | 370 bra restart3 ; YES - no BT then |
315 bcf PORTE,0 ; NO - power up BT chip (if available) | 371 bcf PORTE,0 ; NO - power up BT chip (if available) |
316 WAITMS d'5' ; - wait 5 ms | 372 WAITMS d'5' ; - wait 5 ms |
317 btfss vusb_in ; - BT chip detected? | 373 btfss vusb_in ; - BT chip detected? |
318 bra restart3 ; NO - no BLE then | 374 bra restart3 ; NO - no BT then |
319 ENDIF | 375 ENDIF |
320 bsf ble_available ; YES - BLE available | 376 bsf ble_available ; YES - BT available |
321 | 377 |
322 restart3: | 378 restart3: |
323 bsf PORTE,0 ; power down BLE chip | 379 bsf PORTE,0 ; power down BT chip |
324 btfsc ble_available ; BLE available? | 380 btfsc ble_available ; BT available? |
325 bra restart4 ; YES - can't be a cR then | 381 bra restart4 ; YES - can't be a cR then |
326 btfss battery_gauge_available ; NO - rechargeable? | 382 btfss battery_gauge_available ; NO - rechargeable? |
327 bra restart4 ; NO - can't be a cR | 383 bra restart4 ; NO - can't be a cR |
328 bsf analog_o2_input ; YES - it's a cR, analog input available | 384 bsf ext_input_s8_ana ; YES - it's a cR, S8/analog sensor input available |
329 | 385 |
330 restart4: | 386 restart4: |
331 bsf lv_core ; default to low voltage core | 387 bsf lv_core ; default to low voltage core |
332 movlw 0x80 ; point to 0x1F780 | 388 movlw 0x80 ; point to 0x1F780 |
333 movwf TBLPTRL ; ... | 389 movwf TBLPTRL ; ... |
345 movlw 0x94 ; - coding for low voltage core, part 2 | 401 movlw 0x94 ; - coding for low voltage core, part 2 |
346 cpfseq TABLAT ; - equal? | 402 cpfseq TABLAT ; - equal? |
347 restart4a: | 403 restart4a: |
348 bcf lv_core ; NO - no low voltage core then | 404 bcf lv_core ; NO - no low voltage core then |
349 | 405 |
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 | |
350 | 417 |
351 IFDEF _rx_functions | 418 IFDEF _rx_functions |
352 | 419 |
353 ; set TR functions as deactivated by default | 420 ; set TR functions as deactivated by default |
354 bcf tr_functions_activated ; clear flag | 421 bcf tr_functions_activated ; clear flag |
389 WIN_SMALL .10,.160 ; set next output position | 456 WIN_SMALL .10,.160 ; set next output position |
390 STRCAT "Update " ; common part of result message | 457 STRCAT "Update " ; common part of result message |
391 btfss ostc_rx_present ; data transfer successful and TR module up & running again? | 458 btfss ostc_rx_present ; data transfer successful and TR module up & running again? |
392 bra restart4c ; NO | 459 bra restart4c ; NO |
393 STRCAT "to " ; YES - print success message | 460 STRCAT "to " ; YES - print success message |
394 call TFT_print_firmware_rx ; - print installed version | 461 call dyn_show_firmware_rx ; - print installed version |
395 STRCAT_PRINT " done" ; - complete result message | 462 STRCAT_PRINT " done" ; - complete result message |
396 bra restart4d ; - show message for a while | 463 bra restart4d ; - show message for a while |
397 | 464 |
398 restart4c: | 465 restart4c: |
399 STRCAT_PRINT "failed" ; complete result message - failure | 466 STRCAT_PRINT "failed" ; complete result message - failure |
400 | 467 |
401 restart4d: | 468 restart4d: |
402 call wait_1s ; wait (up to) 1 second | 469 WAITS .3 ; wait 3 seconds |
403 call wait_1s ; wait (another full) 1 second | |
404 call wait_1s ; wait (another full) 1 second | |
405 | 470 |
406 ENDIF ; _rx_update | 471 ENDIF ; _rx_update |
407 | 472 |
408 restart4e: | 473 restart4e: |
409 btfss ostc_rx_present ; TR module up & running? | 474 btfss ostc_rx_present ; TR module up & running? |
415 ENDIF ; _rx_functions | 480 ENDIF ; _rx_functions |
416 | 481 |
417 | 482 |
418 restart5: | 483 restart5: |
419 ; manage hardware | 484 ; manage hardware |
420 btfss analog_o2_input ; OSTC with analog input? | 485 btfss ext_input_s8_ana ; OSTC with S8/analog input? |
421 bsf TRISB,3 ; NO - shut down power supply for S8 bulkhead | 486 bsf TRISB,3 ; NO - shut down power supply for S8 bulkhead |
422 | 487 |
423 btfss battery_gauge_available ; OSTC with gauge IC? | 488 btfss battery_gauge_available ; OSTC with gauge IC? |
424 bsf TRISG,0 ; NO | 489 bsf TRISG,0 ; NO |
425 | 490 |
427 | 492 |
428 btfsc use_old_batt_flag ; shall reload last battery data? | 493 btfsc use_old_batt_flag ; shall reload last battery data? |
429 call get_battery_data ; YES - get last battery data | 494 call get_battery_data ; YES - get last battery data |
430 | 495 |
431 ; check if option values have changed and thus if the EEPROM needs to be updated | 496 ; check if option values have changed and thus if the EEPROM needs to be updated |
432 btfsc options_changed ; do the options need to be stored to EEPROM ? | 497 btfsc option_changed ; do the options need to be stored to EEPROM ? |
433 call option_check_and_store_all ; YES - check and store all option values in EEPROM | 498 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
434 bcf options_changed ; clear flag | |
435 | 499 |
436 ; set screen orientation | 500 ; set screen orientation |
437 bcf flip_screen ; set default screen orientation | 501 bcf flip_screen ; disable upside-down orientation by default |
438 TSTOSC opt_flip_screen ; shall show screen outputs upside down? (=1: flip the screen) | 502 TSTOSC opt_flip_screen ; shall show screen outputs upside down? (=1: flip the screen) |
439 bsf flip_screen ; YES - set upside-down orientation | 503 bsf flip_screen ; YES - enable upside-down orientation |
440 | 504 |
441 ; check if high-altitude mode is applicable | 505 ; check if high-altitude mode is applicable |
442 bcf high_altitude_mode ; disable high altitude mode by default | 506 bcf high_altitude_mode ; disable high altitude mode by default |
443 MOVII pressure_abs_ref, sub_a ; copy last surface pressure to sub_a | 507 MOVII pressure_abs_ref, sub_a ; copy last surface pressure to sub_a |
444 MOVLI high_altitude_threshold+1,sub_b ; copy high-altitude threshold (880 mbar) + 1 to sub_a | 508 MOVLI high_altitude_threshold+1,sub_b ; copy high-altitude threshold (880 mbar) + 1 to sub_a |
453 call deco_calc_dive_interval_1min ; - calculate tissues for 1 minute at surface conditions (C-code) | 517 call deco_calc_dive_interval_1min ; - calculate tissues for 1 minute at surface conditions (C-code) |
454 call deco_calc_desaturation_time ; - calculate desaturation and no-fly/no-altitude time (C-code) | 518 call deco_calc_desaturation_time ; - calculate desaturation and no-fly/no-altitude time (C-code) |
455 banksel common ; - back to bank common | 519 banksel common ; - back to bank common |
456 | 520 |
457 restart6: | 521 restart6: |
458 ; the dive mode flag can not be set right after cold start, must have been in surface mode before | 522 call TFT_load_std_color_pallet ; load standard color pallet |
459 btfsc divemode ; shall enter dive mode? | 523 btfsc divemode ; shall enter dive mode? |
460 goto diveloop ; YES | 524 goto diveloop ; YES - enter dive mode |
461 | 525 btfsc RCON,POR ; NO - was this a power-on reset? |
462 btfsc RCON,POR ; was this a power-on reset? | 526 goto surfloop ; NO - enter surface mode |
463 goto surfloop ; NO - enter surface mode | 527 bsf RCON,POR ; YES - acknowledge detection and re-arm detector |
464 bsf RCON,POR ; YES - acknowledge detection and re-arm detector | 528 goto new_battery_select ; - prompt for battery selection, will proceed to surface mode |
465 goto do_new_battery_select ; - prompt for battery selection, will proceed to surface mode | 529 |
466 | 530 |
467 | 531 ;============================================================================= |
468 ;============================================================================= | 532 boot4 CODE |
469 ; Setup all flags and parameters for dive mode and simulator computations | 533 ;============================================================================= |
534 | |
535 ;----------------------------------------------------------------------------- | |
536 ; Setup of all Flags and Parameters for Dive Mode and Simulator Computations | |
470 ; | 537 ; |
471 ; called from divemode.asm, menu_tree.asm and surfmode.asm | 538 ; called from divemode.asm, menu_tree.asm and surfmode.asm |
472 ; | 539 ; |
473 global restart_set_modes_and_flags | 540 global restart_set_modes_and_flags |
474 restart_set_modes_and_flags: | 541 restart_set_modes_and_flags: |
475 call disable_ir_s8 ; switch off IR/S8 digital interface by default (for all compile versions!) | 542 call disable_ir_s8_analog ; switch off IR/S8/analog interface by default (for all compile versions!) |
476 | 543 |
477 IFDEF _external_sensor | 544 IFDEF _external_sensor |
478 WAITMS d'100' ; some delay to power down S8-HUD properly | 545 WAITMS d'100' ; wait 100 ms to S8-HUD powered down properly |
479 ENDIF | 546 ENDIF |
480 | 547 |
481 ; setup sampling rate | 548 ; setup sampling rate for dice data recording |
482 movlw .2 ; default to 2 seconds | 549 movlw .2 ; default to 2 seconds |
483 movwf sampling_rate ; write setting | 550 TSTOSC opt_sampling_rate ; check option: 0= 2s, 1= 10s |
484 TSTOSS opt_sampling_rate ; check option: 1= 10s, 0= 2s | |
485 bra restart_set_modes_and_flags1 ; 0 - 2 seconds selected, done | |
486 movlw .10 ; 1 - change to 10 seconds | 551 movlw .10 ; 1 - change to 10 seconds |
487 movwf sampling_rate ; - write setting | 552 movwf sampling_rate ; store selection |
488 | 553 |
489 restart_set_modes_and_flags1: | 554 ; clear all deco mode flags |
490 clrf DM_flags_deco ; clear all deco mode flags | 555 clrf DM_flags_deco |
491 | 556 |
492 ; initialize active_gas and active_dil for surface mode pressure display | 557 ; initialize active_gas and active_dil for surface mode pressure display |
493 call get_first_gas_to_WREG | 558 call get_first_gas_to_WREG |
494 movwf active_gas | 559 movwf active_gas |
495 | 560 |
505 bra restart_set_modes_and_flags2 ; YES - keep them | 570 bra restart_set_modes_and_flags2 ; YES - keep them |
506 movff opt_sat_multiplier_non_gf, char_I_saturation_multiplier ; NO - overwrite them with non-GF factors | 571 movff opt_sat_multiplier_non_gf, char_I_saturation_multiplier ; NO - overwrite them with non-GF factors |
507 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier ; - ... | 572 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier ; - ... |
508 | 573 |
509 restart_set_modes_and_flags2: | 574 restart_set_modes_and_flags2: |
575 | |
510 ; configure GF settings, GF high is needed for color-coding the current GF (supersaturation) factor | 576 ; configure GF settings, GF high is needed for color-coding the current GF (supersaturation) factor |
511 movff opt_GF_low, char_I_GF_Low_percentage | 577 movff opt_GF_low, char_I_GF_Low_percentage |
512 movff opt_GF_high,char_I_GF_High_percentage | 578 movff opt_GF_high,char_I_GF_High_percentage |
513 | 579 |
580 ; dive mode specific setup | |
514 movff opt_dive_mode,lo ; get dive mode: 0= OC, 1= CCR, 2= gauge, 3= apnea, 4= pSCR | 581 movff opt_dive_mode,lo ; get dive mode: 0= OC, 1= CCR, 2= gauge, 3= apnea, 4= pSCR |
515 tstfsz lo ; OC? | 582 tstfsz lo ; OC? |
516 bra restart_set_modes_and_flags3 ; NO | 583 bra restart_set_modes_and_flags3 ; NO |
517 bsf FLAG_oc_mode ; YES - set OC flag | 584 bsf FLAG_oc_mode ; YES - set OC flag |
518 IFDEF _rx_functions | 585 IFDEF _rx_functions |
528 call option_cleanup_oCCRMode_CCR ; - revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available | 595 call option_cleanup_oCCRMode_CCR ; - revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available |
529 IFDEF _rx_functions | 596 IFDEF _rx_functions |
530 call option_cleanup_oTrMode_CCR ; - revert TR mode from 'ind.double' to 'on' | 597 call option_cleanup_oTrMode_CCR ; - revert TR mode from 'ind.double' to 'on' |
531 ENDIF ; _rx_functions | 598 ENDIF ; _rx_functions |
532 IFDEF _external_sensor | 599 IFDEF _external_sensor |
533 call enable_ir_s8 ; - enable IR/S8 digital interface | 600 call enable_ir_s8_analog ; - enable IR/S8/analog interface |
534 ENDIF ; _external_sensor | 601 ENDIF ; _external_sensor |
535 ENDIF ; _ccr_pscr | 602 ENDIF ; _ccr_pscr |
536 return ; - done | 603 return ; - done |
537 | 604 |
538 restart_set_modes_and_flags4: | 605 restart_set_modes_and_flags4: |
562 call option_cleanup_oCCRMode_pSCR ; - revert AutoSP to calculated SP, additionally revert Sensor to fixed SP if no sensor interface available | 629 call option_cleanup_oCCRMode_pSCR ; - revert AutoSP to calculated SP, additionally revert Sensor to fixed SP if no sensor interface available |
563 IFDEF _rx_functions | 630 IFDEF _rx_functions |
564 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' | 631 call option_cleanup_oTrMode_no_CCR ; - revert TR mode from 'CCR Dil+O2' to 'on' |
565 ENDIF ; _rx_functions | 632 ENDIF ; _rx_functions |
566 IFDEF _external_sensor | 633 IFDEF _external_sensor |
567 call enable_ir_s8 ; - enable IR/S8 digital interface | 634 call enable_ir_s8_analog ; - enable IR/S8/analog interface |
568 ENDIF ; _external_sensor | 635 ENDIF ; _external_sensor |
569 ENDIF ; _ccr_pscr | 636 ENDIF ; _ccr_pscr |
570 return ; - done | 637 return ; - done |
571 | 638 |
572 | 639 ;----------------------------------------------------------------------------- |
573 ;============================================================================= | |
574 ; Sample and store the current surface pressure, update ISR and deco engine | |
575 ; with the surface pressure sampled on last invocation. | |
576 ; | |
577 global sample_surface_pressure | |
578 sample_surface_pressure: | |
579 ; make sure the ISR does not read the surface pressure reference buffer while it is updated | |
580 bcf update_surface_pressure ; cancel any pending load request | |
581 | |
582 ; propagate the surface pressure sampled on last invocation to the reference pressure buffer | |
583 MOVII pressure_abs_sampled,pressure_abs_ref | |
584 | |
585 ; update surface pressure in the ISR | |
586 bsf update_surface_pressure ; request ISR to update its surface pressure | |
587 | |
588 ; update surface pressure in the deco engine | |
589 MOVII pressure_abs_ref,int_I_pres_surface | |
590 | |
591 ; sample current absolute pressure (ISR-safe 2 byte copy) | |
592 SMOVII pressure_abs,pressure_abs_sampled | |
593 | |
594 ; limit sampled pressure to max allowed surface pressure | |
595 MOVLI max_surfpressure, sub_a ; load upper limit into sub_a | |
596 MOVII pressure_abs_sampled,sub_b ; copy sampled pressure to sub_b | |
597 call cmpU16 ; sub_a - sub_b = max_surfpressure - pressure_abs_sampled | |
598 btfss neg_flag ; sampled pressure > max_surfpressure ? | |
599 return ; NO - below limit, done | |
600 MOVII sub_a,pressure_abs_sampled ; YES - limit to max_surfpressure (still stored in sub_a) | |
601 return ; - done | |
602 | |
603 | 640 |
604 END | 641 END |