Mercurial > public > hwos_code
annotate src/start.asm @ 567:4ce70e3f00be
minor
| author | heinrichsweikamp |
|---|---|
| date | Thu, 08 Feb 2018 13:23:53 +0100 |
| parents | 8b7ea27ea1fa |
| children | b455b31ce022 |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 560 | 3 ; File start.asm REFACTORED VERSION V2.95a1 |
| 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 | |
| 275 | 12 #include "hwos.inc" ; Mandatory header |
| 0 | 13 #include "ms5541.inc" |
| 14 #include "isr.inc" | |
| 15 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
| 16 #include "eeprom_rs232.inc" | |
| 17 #include "math.inc" | |
| 18 #include "tft.inc" | |
| 19 #include "surfmode.inc" | |
| 20 #include "wait.inc" | |
| 21 #include "rtc.inc" | |
| 22 #include "external_flash.inc" | |
| 23 #include "convert.inc" | |
| 24 #include "strings.inc" | |
| 25 #include "tft_outputs.inc" | |
| 113 | 26 #include "adc_lightsensor.inc" |
| 27 #include "i2c.inc" | |
| 0 | 28 |
| 275 | 29 extern init_ostc |
| 0 | 30 extern option_restore_all |
| 31 | |
| 32 ;============================================================================= | |
| 33 ; Reset vector: What to do on device wake-up and hard reset. | |
| 34 ; | |
| 35 reset_v code 0x00000 | |
| 36 ; goto start | |
| 560 | 37 goto 0x1FF00 ; Bootloader |
| 0 | 38 |
| 39 ORG 0x00004 ; Needed for second-level bootloader | |
| 40 goto start | |
| 41 ;============================================================================= | |
| 42 boot CODE | |
| 43 global start | |
| 44 | |
| 45 start: | |
| 46 lfsr FSR0,0x000 ; Clear rambank 0-14 | |
| 47 clear_rambank: | |
| 48 clrf POSTINC0 | |
| 49 movlw 0x0F | |
| 50 cpfseq FSR0H ; Bank 14 done? | |
| 51 bra clear_rambank ; clear... | |
| 52 | |
| 275 | 53 call init_ostc |
| 0 | 54 |
| 449 | 55 ; Get button type from Bootloader-Info |
| 560 | 56 movlw .16 |
| 474 | 57 movff WREG,analog_counter ; init averaging |
| 449 | 58 bsf analog_switches |
| 59 movlw 0x7C | |
| 60 movwf TBLPTRL | |
| 61 movlw 0xF7 | |
| 62 movwf TBLPTRH | |
| 63 movlw 0x01 | |
| 64 movwf TBLPTRU | |
| 560 | 65 TBLRD*+ ; Reads 0x07 for analog buttons |
| 449 | 66 movlw 0x07 |
| 67 cpfseq TABLAT | |
| 68 bcf analog_switches | |
| 475 | 69 |
| 70 ; read button polarity | |
| 71 movlw LOW .897 | |
| 72 movwf EEADR | |
| 73 movlw HIGH .897 | |
| 74 movwf EEADRH | |
| 560 | 75 call read_eeprom ; EEDATA into EEPROM@EEADR |
| 76 clrf EEADRH ; Reset EEADRH | |
| 77 movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only) | |
| 475 | 78 |
| 0 | 79 ; Air pressure compensation after reset |
| 80 call get_calibration_data ; Get calibration data from pressure sensor | |
| 81 banksel common ; get_calibration_data uses isr_backup | |
| 82 | |
| 560 | 83 call TFT_DisplayOff ; display off |
| 84 bsf LEDr ; Status LED | |
| 463 | 85 bcf pressure_refresh |
| 0 | 86 ; First pass will not have valid temperature! |
| 87 btfss pressure_refresh ; Air pressure compensation | |
| 88 bra $-2 | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
89 ; Second pass |
| 0 | 90 bcf pressure_refresh |
| 91 btfss pressure_refresh ; Air pressure compensation | |
| 92 bra $-2 | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
93 bcf LEDr |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
94 |
| 0 | 95 clrf rel_pressure+0 |
| 96 clrf rel_pressure+1 | |
| 97 clrf surface_interval+0 | |
| 98 clrf surface_interval+1 | |
| 99 | |
| 100 SAFE_2BYTE_COPY amb_pressure, last_surfpressure | |
| 101 | |
| 102 movlw LOW max_surfpressure | |
| 103 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
| 104 movlw HIGH max_surfpressure | |
| 105 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
| 106 movff last_surfpressure+0,sub_b+0 | |
| 107 movff last_surfpressure+1,sub_b+1 | |
| 560 | 108 call subU16 ; sub_c = sub_a - sub_b |
| 109 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
| 110 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
| 0 | 111 |
| 112 ; not ok! Overwrite with max. "allowed" airpressure | |
| 113 movlw LOW max_surfpressure | |
| 114 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar | |
| 115 movlw HIGH max_surfpressure | |
| 116 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar | |
| 117 | |
| 118 start_copy_pressure: | |
| 119 movff last_surfpressure+0,last_surfpressure_15min+0 | |
| 120 movff last_surfpressure+1,last_surfpressure_15min+1 | |
| 121 movff last_surfpressure+0,last_surfpressure_30min+0 | |
| 560 | 122 movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all airpressure registers |
| 0 | 123 |
| 124 ; reset deco data for surface mode | |
| 560 | 125 movlw .21 ; 21% |
| 126 movff WREG,char_I_O2_ratio ; ... oxygen | |
| 127 movlw .0 ; 0% | |
| 128 movff WREG,char_I_He_ratio ; ... helium | |
| 129 | |
| 130 ; initialize GF high (needed by deco engine for color-coding the GF value) | |
| 131 movff opt_GF_high,char_I_GF_High_percentage | |
| 132 | |
| 133 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface | |
| 134 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressue | |
| 0 | 135 movff int_I_pres_respiration+1,int_I_pres_surface+1 |
| 136 | |
| 560 | 137 extern deco_setup |
| 138 call deco_setup ; set up all model parameters. | |
| 139 call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio (C-Code) | |
| 140 banksel common ; back to bank 1, needed after every return from C code | |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
141 |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
142 call rtc_init ; init clock |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
143 |
| 560 | 144 movlw HIGH .512 ; =2 |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
145 movwf EEADRH |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
146 read_int_eeprom .0 |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
147 clrf EEADRH |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
148 movlw 0xAA |
| 560 | 149 cpfseq EEDATA ; =0xAA |
| 150 bra no_deco_restore ; No | |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
151 |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
152 extern restore_decodata_from_eeprom |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
153 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
154 |
|
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
155 no_deco_restore: |
| 560 | 156 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode |
| 157 call deco_calc_desaturation_time ; calculate desaturation and no-fly time | |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
158 banksel common |
| 560 | 159 |
| 0 | 160 bcf menubit ; clear menu flag |
| 215 | 161 |
| 0 | 162 ; Check for Power-on reset here |
|
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
163 extern use_old_prior_209 |
| 215 | 164 ; ***************************************************************************** |
| 165 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
| 166 ; ***************************************************************************** | |
| 0 | 167 |
| 457 | 168 ; Try to migrate the old battery status from firmware 2.09 or earlier.. |
| 560 | 169 btfsc RCON,POR ; Was this a power-on reset? |
|
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
464
diff
changeset
|
170 call use_old_prior_209 ; No |
|
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
171 |
|
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
172 bcf use_old_batt_flag |
| 560 | 173 btfsc RCON,POR ; Was this a power-on reset? |
|
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
174 bsf use_old_batt_flag ; No |
|
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
175 |
| 215 | 176 call lt2942_get_status ; Check for gauge IC |
| 449 | 177 btfss battery_gauge_available ; cR or 2 hardware? |
| 560 | 178 bra power_on_return2 ; no |
| 215 | 179 |
|
375
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
180 movlw .30 |
|
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
181 movff WREG,opt_cR_button_right |
|
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
182 movff WREG,opt_cR_button_left ; Reset on power-on reset |
|
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
183 call piezo_config ; Yes, configure buttons |
|
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
184 call piezo_config ; Yes, configure buttons (2 times) |
| 0 | 185 |
|
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
186 power_on_return2: |
| 0 | 187 ; check firmware and reset Custom Functions after an update |
| 188 movlw d'1' | |
|
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
189 movwf EEADR ; =1 |
|
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
190 movwf EEADRH ; =1 |
| 0 | 191 call read_eeprom ; read current version x |
| 192 movff EEDATA,temp1 | |
| 193 incf EEADR,F ; set to 0x102 | |
| 194 call read_eeprom ; read current version y | |
| 195 movff EEDATA,temp2 | |
| 196 clrf EEADRH ; Reset EEADRH | |
| 197 | |
| 443 | 198 movlw softwareversion_x |
| 199 cpfseq temp1 ; compare version x | |
| 0 | 200 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM |
| 201 | |
| 202 movlw softwareversion_y | |
| 203 cpfseq temp2 ; compare version y | |
| 204 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
| 205 bra restart ; x and y are equal -> do not reset cf | |
| 206 | |
| 207 check_firmware_new: | |
| 208 call TFT_boot ; Initialize TFT (includes clear screen) | |
| 209 clrf CCPR1L ; Backlight off | |
| 210 WIN_TOP .50 | |
| 211 WIN_LEFT .10 | |
| 212 movlw LOW 0x1E000 | |
| 213 movwf TBLPTRL | |
| 214 movlw HIGH 0x1E000 | |
| 215 movwf TBLPTRH | |
| 216 movlw UPPER 0x1E000 | |
| 217 movwf TBLPTRU | |
| 218 extern color_image | |
| 219 call color_image ; Show logo | |
| 220 call TFT_standard_color | |
| 221 WIN_SMALL .10,.100 | |
| 427 | 222 STRCPY_PRINT "Update successful!" ; Hard coded since language switch does not work here |
| 0 | 223 WIN_SMALL .10,.140 |
| 427 | 224 STRCPY "New Firmware: " |
| 0 | 225 movlw softwareversion_x |
| 226 movwf lo | |
| 227 bsf leftbind | |
| 228 output_8 | |
| 229 PUTC "." | |
| 230 movlw softwareversion_y | |
| 231 movwf lo | |
| 45 | 232 output_99x |
| 0 | 233 bcf leftbind |
| 560 | 234 STRCAT_PRINT "" ; Print second row |
| 235 call TFT_Display_FadeIn ; Display resulting surface screen. | |
| 0 | 236 |
| 237 ; place "after-update reset" here... | |
|
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
238 |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
239 extern oPressureAdjust, option_reset, option_save |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
240 lfsr FSR0,oPressureAdjust |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
241 call option_reset ; Reset FSR0 option to factory default. |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
242 lfsr FSR0,oPressureAdjust |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
243 call option_save ; Save in EEPROM |
|
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
244 |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
245 rcall backup_flash_page ; backup the first 128bytes from flash to EEPROM |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
246 |
| 0 | 247 movlw d'1' ; store current version in EEPROM |
|
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
248 movwf EEADR ; =1 |
|
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
249 movwf EEADRH ; =1 |
| 0 | 250 movlw softwareversion_x |
| 251 movwf EEDATA | |
| 252 call write_eeprom ; write version x | |
| 253 incf EEADR,F ; set to 0x102 | |
| 254 movlw softwareversion_y | |
| 255 movwf EEDATA | |
| 256 call write_eeprom ; write version y | |
| 257 clrf EEADRH ; Reset EEADRH | |
| 258 | |
| 259 movlw .7 | |
| 260 movwf lo | |
| 261 check_firmware_new2: | |
| 262 ; Wait 1 second | |
| 263 bcf onesecupdate | |
| 264 btfss onesecupdate | |
| 265 bra $-2 | |
| 266 decfsz lo,F ; Wait 10 seconds... | |
| 267 bra check_firmware_new2 | |
| 268 | |
| 269 global restart | |
| 270 restart: | |
| 271 clrf STKPTR ; Never return from here | |
|
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
272 clrf CCP1CON ; stop PWM |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
273 bcf PORTC,2 ; Pull PWM out to GND |
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
274 |
|
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
275 extern option_save_all, option_check_all |
|
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
276 |
| 0 | 277 btfsc menubit ; Return from Menu/COMM mode or timeout? |
| 278 call option_save_all ; Yes, save all settings into EEPROM | |
| 279 | |
| 429 | 280 call option_restore_all ; Restore everything from EEPROM into RAM |
|
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
281 call option_check_all ; Check all options (and reset if not within their min/max boundaries) |
| 560 | 282 call option_save_all ; Save all settings into EEPROM after they have been checked |
|
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
283 |
| 429 | 284 clrf flag1 ; clear all flags |
| 285 clrf flag2 | |
| 286 clrf flag3 | |
| 287 clrf flag4 | |
| 288 clrf flag5 | |
| 289 clrf flag6 | |
| 0 | 290 clrf flag7 |
| 291 clrf flag8 | |
| 429 | 292 clrf flag9 |
| 293 clrf flag10 | |
|
267
f64afa14ef07
BUGFIX: Analog sensors were ignored in 1.76
heinrichsweikamp
parents:
255
diff
changeset
|
294 ; Do not clear flag11 (Sensor calibration and charger status) |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
295 clrf flag12 |
| 560 | 296 ; Do not clear flag13 (Important hardware flags) |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
297 clrf flag14 |
|
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
298 clrf hardware_flag ; hardware descriptor flag |
| 449 | 299 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! |
|
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
300 |
| 236 | 301 ; configure hardware_flag byte |
| 302 | |
| 429 | 303 bsf ambient_sensor ; Set flag |
| 304 bsf optical_input ; Set flag | |
| 236 | 305 |
| 113 | 306 call lt2942_get_status ; Check for gauge IC |
| 560 | 307 btfss battery_gauge_available ; cR/2 hardware? |
| 236 | 308 bra restart2 ; No |
| 309 | |
| 113 | 310 call lt2942_init ; Yes, init battery gauge IC |
| 429 | 311 bcf optical_input ; Clear flag |
| 312 | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
313 banksel 0xF16 |
| 560 | 314 bcf ANCON0,7 ; AN7 Digital input |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
315 banksel common |
| 560 | 316 bcf lightsen_power ; Power-down ambient light sensor |
| 236 | 317 bcf ambient_sensor ; Clear flag |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
318 nop |
| 560 | 319 btfss PORTF,2 ; Light sensor available? |
| 429 | 320 bsf ambient_sensor ; Yes. |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
321 banksel 0xF16 |
| 560 | 322 bsf ANCON0,7 ; AN7 Analog again |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
323 banksel common |
| 560 | 324 bsf lightsen_power ; Power-up ambient light sensor again |
| 429 | 325 |
| 243 | 326 restart2: |
| 327 btfsc vusb_in | |
| 328 bra restart3 ; USB (and powered on) | |
| 329 bcf PORTE,0 ; Start comms | |
| 330 WAITMS d'1' | |
| 331 btfss vusb_in | |
| 332 bra restart3 ; USB (and powered off) | |
| 333 bsf ble_available ; ble available | |
| 334 restart3: | |
| 335 bsf PORTE,0 ; Stop comms | |
|
248
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
336 btfsc ble_available ; ble available? |
|
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
337 bra restart4 ; Yes, can't be a cR |
| 449 | 338 btfss battery_gauge_available ; Rechargeable |
|
248
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
339 bra restart4 ; No, can't be a cR |
|
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
340 bsf analog_o2_input ; Set flag for analog |
| 249 | 341 restart4: |
| 342 ; The hardware_flag is now: | |
| 343 ; 3: 0x0A | |
| 344 ; cR: 0x05 | |
| 345 ; 2 with BLE: 0x11 | |
| 346 ; 3 with BLE: 0x1A | |
| 429 | 347 ; 2 with ambient: 0x13 |
| 113 | 348 |
| 0 | 349 ; Select high altitude (Fly) mode? |
| 350 movff last_surfpressure_30min+0,sub_b+0 | |
| 351 movff last_surfpressure_30min+1,sub_b+1 | |
| 352 movlw HIGH high_altitude_threshold | |
| 353 movwf sub_a+1 | |
| 354 movlw LOW high_altitude_threshold ; Hard-wired 880mbar | |
| 355 movwf sub_a+0 | |
| 356 call subU16 ; sub_c = sub_a - sub_b | |
| 357 btfss neg_flag ; Result negative (Ambient>880mbar)? | |
| 358 bsf high_altitude_mode ; No, Set Flag! | |
| 359 | |
| 236 | 360 btfss analog_o2_input |
| 165 | 361 bsf TRISB,3 |
| 449 | 362 btfss battery_gauge_available |
| 165 | 363 bsf TRISG,0 |
| 0 | 364 call ext_flash_disable_protection ; Disable write protection for external flash |
| 365 | |
|
155
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
366 bsf flip_screen ; Flip 180° |
|
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
367 TSTOSS opt_flip_screen ; =1: Flip the screen |
|
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
368 bcf flip_screen ; Normal orientation |
| 151 | 369 |
| 560 | 370 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset |
| 371 goto use_old_batteries ; Returns to "surfloop"! | |
|
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
372 |
| 560 | 373 btfsc RCON,POR ; Was this a power-on reset? |
| 374 goto surfloop ; Jump to Surfaceloop! | |
| 375 bsf RCON,POR ; Set bit for next detection | |
|
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
376 ; Things to do after a power-on reset |
|
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
377 extern new_battery_menu,use_old_batteries |
| 560 | 378 goto new_battery_menu ; Returns to "surfloop"! |
| 0 | 379 |
| 380 ;============================================================================= | |
| 381 ; Setup all flags and parameters for divemode and simulator computations. | |
| 382 ; | |
| 383 global restart_set_modes_and_flags | |
| 384 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
| 385 call option_restore_all ; Restore everything from EEPROM | |
| 24 | 386 |
| 387 ; Setup sampling rate | |
| 388 movlw .2 | |
| 389 movwf samplingrate | |
| 390 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
| 391 bra restart_set_modes_and_flags1 | |
| 392 movlw .10 | |
| 393 movwf samplingrate | |
| 394 restart_set_modes_and_flags1: | |
| 560 | 395 bcf twosecupdate ; to have divemode routines in sync |
|
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
396 |
| 545 | 397 bcf FLAG_apnoe_mode |
| 560 | 398 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active |
| 399 bcf FLAG_gauge_mode ; =1: In Gauge mode | |
| 545 | 400 bcf FLAG_pscr_mode |
| 560 | 401 call disable_ir_s8 ; IR off |
| 0 | 402 |
|
562
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
403 ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
404 movff opt_sat_multiplier_gf,char_I_saturation_multiplier |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
405 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
406 movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
407 tstfsz lo |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
408 bra restart_set_modes_and_flags1b |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
409 movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
410 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
411 |
|
8b7ea27ea1fa
seperate desat and sat multipliers for GF and Non-GF modes. Set to 100/100 as default in GF mode
heinrichsweikamp
parents:
561
diff
changeset
|
412 restart_set_modes_and_flags1b: |
| 545 | 413 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR |
| 0 | 414 tstfsz lo |
| 415 bra restart_set_modes_and_flags2 | |
| 416 ; OC Mode | |
| 560 | 417 |
| 0 | 418 return |
| 419 | |
| 420 restart_set_modes_and_flags2: | |
| 421 decfsz lo,F | |
| 422 bra restart_set_modes_and_flags3 | |
| 423 ; CC Mode | |
| 359 | 424 btfsc analog_o2_input ; cR? |
| 425 bra restart_set_modes_and_flags2b ; Yes, skip mode check | |
| 426 btfsc optical_input ; 3 | |
| 427 bra restart_set_modes_and_flags2b ; Yes, skip mode check | |
| 428 ; Make sure Sensor is not selected | |
| 429 ; opt_ccr_mode must be <> 1 (=0: Fixed SP, =1: Sensor, =2: Auto SP) | |
| 430 banksel opt_ccr_mode | |
| 431 movlw .1 | |
| 432 cpfseq opt_ccr_mode ; = Sensor? | |
| 433 bra restart_set_modes_and_flags2b ; No | |
| 434 clrf opt_ccr_mode ; Yes, reset to Fixed SP | |
| 435 restart_set_modes_and_flags2b: | |
| 436 banksel common | |
| 560 | 437 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active |
| 438 call enable_ir_s8 ; Enable IR/S8-Port | |
| 0 | 439 return |
| 440 | |
| 441 restart_set_modes_and_flags3: | |
| 442 decfsz lo,F | |
| 443 bra restart_set_modes_and_flags4 | |
| 444 ; Gauge Mode | |
| 560 | 445 bsf FLAG_gauge_mode ; =1: In Gauge mode |
| 0 | 446 return |
| 447 | |
| 448 restart_set_modes_and_flags4: | |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
449 decfsz lo,F |
|
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
450 bra restart_set_modes_and_flags5 |
| 0 | 451 ; Apnea Mode |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
452 bsf FLAG_apnoe_mode |
| 560 | 453 return ; start in Surfacemode |
| 0 | 454 |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
455 restart_set_modes_and_flags5: |
| 560 | 456 ; PSCR Mode |
| 457 btfsc analog_o2_input ; cR? | |
| 458 bra restart_set_modes_and_flags5b ; Yes, skip mode check | |
| 459 btfsc optical_input ; 3 | |
| 460 bra restart_set_modes_and_flags5b ; Yes, skip mode check | |
| 461 | |
| 462 ; Make sure Sensor is not selected | |
| 463 ; opt_ccr_mode must be <> 1 (=0: calculated ppO2, =1: Sensor, =2: Auto SP - not valid in pSCR, too) | |
| 464 banksel opt_ccr_mode | |
| 465 movlw .1 | |
| 466 cpfseq opt_ccr_mode ; = Sensor? | |
| 467 bra restart_set_modes_and_flags5b ; No | |
| 468 clrf opt_ccr_mode ; Yes, reset to calculated ppO2 | |
| 469 | |
| 470 restart_set_modes_and_flags5b: | |
| 471 banksel opt_ccr_mode | |
| 472 bcf opt_ccr_mode,1 ; in pSCR mode only calculated or Sensor, not 2 = Auto SP allowed | |
| 473 banksel common | |
| 474 bsf FLAG_pscr_mode | |
| 475 return ; start in Surfacemode | |
| 476 | |
|
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
477 |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
478 backup_flash_page: ; backup the first 128bytes from flash to EEPROM |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
479 ; Start address in internal flash |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
480 movlw 0x00 |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
481 movwf TBLPTRL |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
482 movwf TBLPTRH |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
483 movwf TBLPTRU |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
484 |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
485 movlw .128 |
| 560 | 486 movwf lo ; Byte counter |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
487 clrf EEADR |
|
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
488 movlw .3 |
| 560 | 489 movwf EEADRH ; Setup backup address |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
490 |
| 560 | 491 TBLRD*- ; Dummy read to be in 128 byte block |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
492 backup_flash_loop: |
| 560 | 493 tblrd+* ; Table Read with Pre-Increment |
| 494 movff TABLAT,EEDATA ; put 1 byte | |
| 495 call write_eeprom ; save it in EEPROM | |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
496 incf EEADR,F |
| 560 | 497 decfsz lo,F ; 128byte done? |
| 498 bra backup_flash_loop ; No | |
| 499 clrf EEADRH ; Reset EEADRH | |
| 500 return ; Done. | |
|
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
501 |
| 0 | 502 END |
