Mercurial > public > hwos_code
annotate src/sleepmode.asm @ 654:75e90cd0c2c3
hwOS sport 10.77 release
| author | heinrichsweikamp |
|---|---|
| date | Thu, 14 Mar 2024 16:56:46 +0100 |
| parents | bc214815deb2 |
| children | 8af5aefbcdaf |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 634 | 3 ; File sleepmode.asm * combined next generation V3.09.4n |
| 0 | 4 ; |
| 623 | 5 ; Sleep Mode |
| 0 | 6 ; |
| 654 | 7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
| 582 | 8 ;============================================================================== |
| 0 | 9 ; HISTORY |
| 10 ; 2011-08-12 : [mH] moving from OSTC code | |
| 11 | |
| 582 | 12 #include "hwos.inc" ; Mandatory header |
| 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
| 14 #include "surfmode.inc" | |
| 15 #include "tft.inc" | |
| 16 #include "start.inc" | |
| 17 #include "adc_lightsensor.inc" | |
| 18 #include "math.inc" | |
| 19 #include "ms5541.inc" | |
| 20 #include "eeprom_rs232.inc" | |
| 21 #include "external_flash.inc" | |
| 22 #include "ghostwriter.inc" | |
| 23 #include "i2c.inc" | |
| 24 #include "mcp.inc" | |
| 623 | 25 #include "wait.inc" |
| 629 | 26 #include "tft_outputs.inc" |
| 0 | 27 |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
123
diff
changeset
|
28 |
| 631 | 29 extern eeprom_deco_data_write |
| 30 extern option_check_and_store_all | |
| 582 | 31 |
| 32 | |
| 623 | 33 ;---- Private local Variables ------------------------------------------------- |
|
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
123
diff
changeset
|
34 |
| 582 | 35 CBLOCK local1 ; max size is 16 Byte !!! |
| 623 | 36 accel_reference ; acceleration reference value for detecting movement / terminating deep sleep |
| 37 sm_timer_10sec ; timer for 10 seconds tasks (pressure check) | |
| 38 sm_timer_10min ; timer for 10 minutes tasks (tissue updating) | |
| 628 | 39 ;sm_timer_15min ; timer for 15 minutes tasks (entering deep sleep) |
| 40 sm_10min_counter ; count #of 10 minutes | |
| 623 | 41 loop_counter ; loop counter, used in init_avg_switches routine |
| 42 sm_flags ; local flags | |
| 43 ENDC ; used: 6 byte, remaining: 10 byte | |
| 582 | 44 |
| 45 | |
| 623 | 46 ;---- Private local Flags ----------------------------------------------------- |
| 47 | |
| 48 #DEFINE deep_sleep sm_flags,0 ; =1: in deep sleep mode, =0: normal sleep | |
| 49 #DEFINE desat_on_10_mins sm_flags,1 ; =1: calculate desaturation every 10 minutes, =0: every minute | |
| 628 | 50 #DEFINE charge_in_sleep sm_flags,2 ; =1: show charging screen |
| 623 | 51 ; sm_flags,3 ; unused |
| 52 ; sm_flags,4 ; unused | |
| 53 ; sm_flags,5 ; unused | |
| 54 ; sm_flags,6 ; unused | |
| 55 ; sm_flags,7 ; unused | |
| 56 | |
| 57 | |
| 634 | 58 ;============================================================================= |
| 623 | 59 slmode CODE |
| 582 | 60 ;============================================================================== |
| 0 | 61 |
| 634 | 62 |
| 63 ;----------------------------------------------------------------------------- | |
| 64 ; Entry Point for Sleep Mode | |
| 65 ; | |
| 0 | 66 global sleeploop |
| 623 | 67 sleeploop: |
| 68 clrf STKPTR ; clear return addresses stack | |
| 69 call request_speed_normal ; request CPU speed switch to normal speed | |
| 70 | |
| 71 bcf LEDg ; turn off green LED / release reset to RX circuitry | |
| 72 bcf LEDr ; turn off red LED | |
| 604 | 73 |
| 74 IFDEF _screendump | |
| 623 | 75 bcf screen_dump_avail ; disable screen dump function |
| 76 ENDIF | |
| 77 | |
| 78 bsf sleepmode ; flag being in sleep mode | |
| 79 bsf block_sensor_interrupt ; suspend ISR from executing sensor interrupts | |
| 80 | |
| 643 | 81 bcf i2c_error_flag ; clear any I2C errors |
| 82 | |
| 634 | 83 call disable_ir_s8_analog ; power-down IR/S8/analog interface |
| 623 | 84 call mcp_sleep ; power-down RX power supply |
| 604 | 85 |
| 86 clrf ADCON0 ; power-down ADC module | |
| 623 | 87 call disable_rs232 ; power-down USB |
| 88 call I2C_sleep_compass ; power-down compass | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
89 |
| 631 | 90 call eeprom_deco_data_write ; update deco data in EEPROM |
| 91 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | |
| 92 | |
| 634 | 93 btfsc option_changed ; do the options need to be stored to EEPROM ? |
| 631 | 94 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
| 95 | |
| 623 | 96 call ext_flash_enable_protection ; enable write protection on external flash |
| 582 | 97 |
| 623 | 98 clrf sm_timer_10sec ; clear 10 seconds timer |
| 99 clrf sm_timer_10min ; clear 10 minutes timer | |
| 628 | 100 clrf sm_10min_counter ; clear 10mins counter |
| 623 | 101 clrf sm_flags ; clear all local flags |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
102 |
| 628 | 103 call TFT_Display_FadeOut ; power-down backlight |
| 104 call TFT_DisplayOff ; power-down display | |
| 631 | 105 |
| 0 | 106 sleeploop_loop: |
| 623 | 107 btfsc trigger_full_second ; one second in sleep? |
| 108 rcall one_sec_sleep ; YES - check switches, pressure sensor, etc. | |
| 582 | 109 |
| 623 | 110 btfss sleepmode ; shall terminate sleep mode? |
| 111 bra sleeploop_exit ; YES | |
| 0 | 112 |
| 634 | 113 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 582 | 114 |
| 623 | 115 btfss deep_sleep ; shall enter deep sleep? |
| 116 bra sleeploop_loop ; NO - remain in normal sleep loop | |
| 117 ;bra deepsleep_pre ; YES - enter deep sleep loop | |
| 0 | 118 |
| 623 | 119 deepsleep_pre: |
| 634 | 120 bcf PIE1,TMR1IE ; disable timer 1 interrupt |
| 121 bcf PIE2,TMR3IE ; disable timer 2 interrupt | |
| 122 bcf PIE5,TMR7IE ; disable timer 7 interrupt | |
| 640 | 123 bcf PIE5,TMR4IE ; disable timer 4 interrupt |
| 634 | 124 bcf INTCON, INT0IE ; disable INT0 interrupt |
| 125 bcf INTCON3,INT1IE ; disable INT1 interrupt | |
| 0 | 126 |
| 623 | 127 bcf power_sw1 ; power-down switch 1 |
| 128 bcf power_sw2 ; power-down switch 2 | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
129 |
| 604 | 130 rcall deepsleep_get_accel ; read accelerometer into WREG |
| 623 | 131 movwf accel_reference ; store as reference value |
| 628 | 132 tstfsz accel_reference ; = 0 ? |
| 133 bra deepsleep_loop ; NO - continue | |
| 134 bra deepsleep_loop_exit ; YES - no deep sleep (fail-safe) | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
135 |
| 582 | 136 deepsleep_loop: |
| 623 | 137 btfsc trigger_full_second ; one second in deep sleep? |
| 138 rcall check_accelerometer ; YES - check accelerometer | |
| 139 | |
| 140 btfsc trigger_full_second ; one second in deep sleep? | |
| 141 rcall one_sec_sleep ; YES - check switches, check pressure sensor, etc. | |
| 142 | |
| 634 | 143 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 623 | 144 |
| 145 btfss sleepmode ; shall leave sleep mode? | |
| 146 bcf deep_sleep ; YES - leave deep sleep mode then, too | |
| 147 | |
| 148 btfsc deep_sleep ; shall leave deep sleep mode? | |
| 149 bra deepsleep_loop ; NO - loop in deep sleep loop | |
| 150 | |
| 628 | 151 deepsleep_loop_exit: |
| 152 bcf deep_sleep ; clear flag (again) | |
| 153 clrf sm_10min_counter ; clear 10mins counter | |
| 650 | 154 bsf power_sw1 ; switch on power supply for switch 1 |
| 155 nop | |
| 156 bsf power_sw2 ; switch on power supply for switch 2 | |
| 623 | 157 rcall init_avg_switches ; initialize the averaging system |
| 158 | |
| 634 | 159 bsf PIE1,TMR1IE ; enable timer 1 interrupt |
| 160 bsf PIE2,TMR3IE ; enable timer 2 interrupt | |
| 161 bsf PIE5,TMR7IE ; enable timer 7 interrupt | |
| 640 | 162 bsf PIE5,TMR4IE ; enable timer 4 interrupt |
| 634 | 163 bsf INTCON, INT0IE ; enable INT0 interrupt |
| 164 bsf INTCON3,INT1IE ; enable INT1 interrupt | |
| 623 | 165 |
| 166 bra sleeploop_loop ; enter normal sleep loop | |
| 167 | |
| 168 sleeploop_exit: | |
| 169 bcf switch_left ; eventually clear left button event | |
| 170 bcf switch_right ; eventually clear right button event | |
| 171 movlw .0 ; reset ISR sensor state machine | |
| 172 movff WREG,sensor_state_counter ; ... | |
| 173 bcf PIR5,TMR7IF ; clear timer 7, driving the ISR sensor interrupts | |
| 174 bcf block_sensor_interrupt ; re-enable execution of the ISR sensor interrupts | |
| 175 goto restart ; restart | |
| 176 | |
| 177 | |
| 634 | 178 ;----------------------------------------------------------------------------- |
| 179 ; Helper Function - Tasks every Second in Sleep Mode | |
| 180 ; | |
| 623 | 181 one_sec_sleep: |
| 182 bcf trigger_full_second ; clear trigger flag | |
| 650 | 183 |
| 184 btfss button_hold_down_allowed ; mechanical push buttons? | |
| 185 bra one_sec_sleep_piezo_buttons ; No | |
| 186 | |
| 187 btfss switch_left ; left switch pressed? | |
| 188 bra one_sec_sleep_buttons_done ; no, done | |
| 189 btfss switch_right ; right switch pressed? | |
| 190 bra one_sec_sleep_buttons_done ; no, done | |
| 191 bcf sleepmode ; Both pressed, wake up | |
| 192 bra one_sec_sleep_buttons_done ; Done. | |
| 623 | 193 |
| 650 | 194 one_sec_sleep_piezo_buttons: |
| 195 btfsc switch_left ; left switch pressed? | |
| 196 bcf sleepmode ; YES - terminate sleep mode | |
| 197 btfsc switch_right ; right switch pressed? | |
| 198 bcf sleepmode ; YES - terminate sleep mode | |
| 623 | 199 |
| 650 | 200 one_sec_sleep_buttons_done: |
| 201 bcf switch_right ; clear right button event | |
| 202 bcf switch_left ; clear left button event | |
| 582 | 203 |
| 623 | 204 btfsc battery_gauge_available ; is a battery gauge IC available? |
| 205 bra one_sec_sleep_1 ; YES - check for charger | |
| 629 | 206 btfsc ble_available ; Skip "USB" check in all Bluetooth models (Required for very old OSTC sport) |
| 207 bra one_sec_sleep_2 ; - continue | |
| 623 | 208 btfsc vusb_in ; NO - USB plugged in? |
| 209 bcf sleepmode ; YES - terminate sleep mode | |
| 210 bra one_sec_sleep_2 ; - continue | |
| 211 | |
| 212 one_sec_sleep_1: | |
| 213 call get_battery_voltage ; check for charger | |
| 214 | |
| 628 | 215 ; Test if charging |
| 216 btfss cc_active ; charging? | |
| 217 bra one_sec_sleep_1a ; NO | |
| 218 btfsc charge_in_sleep ; YES - already showing charge screen? | |
| 219 bra one_sec_sleep_1b ; YES - only update data | |
| 220 | |
| 634 | 221 bsf charge_in_sleep |
| 222 bcf deep_sleep ; wake-up from deepsleep | |
| 628 | 223 call TFT_boot ; initialize TFT (includes clear screen) |
| 224 movlw .32 | |
| 225 movff WREG,max_CCPR1L ; bank safe | |
| 226 call TFT_Display_FadeIn ; dim up the display | |
| 227 one_sec_sleep_1b: | |
| 634 | 228 call TFT_surfmode_batt ; show battery type, voltage and color-coded percentage |
| 628 | 229 bra one_sec_sleep_2 ; continue |
| 230 | |
| 231 one_sec_sleep_1a: | |
| 232 btfss charge_in_sleep ; was showing charge screen? | |
| 233 bra one_sec_sleep_2 ; NO | |
| 234 | |
| 235 ; yes, power-down screen | |
| 236 call TFT_Display_FadeOut ; power-down backlight | |
| 237 call TFT_DisplayOff ; power-down display | |
| 238 bcf charge_in_sleep | |
| 239 | |
| 240 | |
| 623 | 241 one_sec_sleep_2: |
| 242 incf sm_timer_10sec,F ; increment 10 seconds timer | |
| 243 movlw .10 ; load a 10 into WREG | |
| 244 cpfslt sm_timer_10sec ; timer < 10 yet? | |
| 245 rcall ten_sec_sleep ; NO - do the every 10 second tasks | |
| 246 | |
| 247 btfsc trigger_full_minute ; one minute in sleep? | |
| 248 rcall one_min_sleep ; YES - do the every minute tasks | |
| 249 | |
| 250 btfsc trigger_full_hour ; one hour in sleep? | |
| 251 rcall one_hour_sleep ; YES - do the every hour tasks | |
| 252 | |
| 643 | 253 ; sleepmode pressure sampling for new sensor is done here |
| 254 btfss press_sensor_type ; New sensor found? | |
| 255 return ; No, done. | |
| 256 | |
| 257 btfsc ms5837_state ; =0: result of temperature is in the ADC | |
| 650 | 258 goto I2C_get_press_val_MS5837 ; (Will clear ms5837_state) (And return!) |
| 259 goto I2C_get_temp_val_MS5837 ; (Will set ms5837_state) (And return!) | |
| 260 ; done. | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
261 |
| 623 | 262 |
| 650 | 263 |
| 634 | 264 ;----------------------------------------------------------------------------- |
| 265 ; Helper Function - Tasks every 10 Seconds in Sleep Mode | |
| 266 ; | |
| 623 | 267 ten_sec_sleep: |
| 268 ; tasks every 10 seconds in sleep mode | |
| 269 clrf sm_timer_10sec ; clear timer | |
| 270 rcall pressuretest_sleep_fast ; get pressure without averaging (faster) | |
| 271 MOVLI wake_up_from_sleep,sub_a ; load wake-up pressure (1160 mbar) into sub_a | |
| 272 MOVII pressure_abs, sub_b ; load current absolute pressure into sub_b | |
| 273 call cmpU16 ; sub_a - sub_b = wake-up pressure - current absolute pressure | |
| 274 btfsc neg_flag ; is the current absolute pressure > 1160 mbar ? | |
| 275 bcf sleepmode ; YES - terminate sleep mode | |
| 276 return ; done | |
| 277 | |
| 278 | |
| 634 | 279 ;----------------------------------------------------------------------------- |
| 280 ; Helper Function - Tasks every Minute in Sleep Mode | |
| 281 ; | |
| 623 | 282 one_min_sleep: |
| 283 ; tasks every minute in sleep mode | |
| 284 bcf trigger_full_minute ; clear flag | |
| 285 | |
| 286 ; tick the 10 minutes timer | |
| 287 incf sm_timer_10min,F ; increment 10 minutes timer | |
| 288 movlw .10 ; load a 10 into WREG | |
| 289 cpfslt sm_timer_10min ; timer < 10 yet? | |
| 290 rcall ten_min_sleep ; NO - do the every 10 minutes tasks | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
291 |
| 623 | 292 one_min_sleep_1: |
| 293 ; continue tasks every minute | |
| 294 btfsc desat_on_10_mins ; shall do desaturation calculation on 10 minute intervals? | |
| 295 return ; YES - that's not here then, so done | |
| 296 call deco_calc_dive_interval_1min ; NO - calculate 1 minute at surface conditions (C-code) | |
| 297 banksel common ; - back to bank common | |
| 298 return ; - done | |
| 299 | |
| 300 | |
| 634 | 301 ;----------------------------------------------------------------------------- |
| 302 ; Helper Function - Tasks every 10 Minutes in Sleep Mode | |
| 303 ; | |
| 623 | 304 ten_min_sleep: |
| 305 ; tasks every 10 minutes in sleep mode | |
| 306 clrf sm_timer_10min ; reset timer to 0 | |
| 307 | |
| 308 call sample_surface_pressure ; sample surface pressure and update ISR and deco engine | |
| 309 | |
| 628 | 310 btfss analog_switches ; OSTC with analog switches? |
| 311 bra ten_min_sleep_0 ; NO - no analog switches, no deep sleep required | |
| 312 | |
| 313 ; check if we need to enter deep sleep | |
| 314 incf sm_10min_counter,F ; count | |
| 315 movlw deep_sleep_10mins ; threshold | |
| 316 cpfseq sm_10min_counter ; threshold reached? | |
| 317 bra ten_min_sleep_0 ; NO - threshold not reached yet | |
| 318 | |
| 319 decf sm_10min_counter,F ; -1 to re-trigger every 10mins (in case of charging) | |
| 320 | |
| 321 btfss cc_active ; charging? | |
| 322 bsf deep_sleep ; NO - activate deep-sleep mode | |
| 323 | |
| 324 ten_min_sleep_0: | |
| 623 | 325 btfss desat_on_10_mins ; shall do desaturation calculation on 10 minute intervals? |
| 326 bra ten_min_sleep_1 ; NO - continue checking if schedule can be switched to 10 minutes | |
| 327 call deco_calc_dive_interval_10min ; YES - calculate 10 minutes at surface conditions (C-code) | |
| 328 banksel common ; - back to bank common | |
| 329 return ; - done | |
| 330 | |
| 331 ten_min_sleep_1: | |
| 332 movff int_O_lead_supersat+0,WREG ; get leading tissue's supersaturation (only the lower byte is used for the value) | |
| 333 bsf desat_on_10_mins ; switch to 10 minute intervals by default | |
| 334 tstfsz WREG ; gradient factor = 0 ? | |
| 335 bcf desat_on_10_mins ; NO - stay on 1 minute intervals | |
| 336 return ; done | |
| 337 | |
| 582 | 338 |
| 634 | 339 ;----------------------------------------------------------------------------- |
| 340 ; Helper Function - Tasks every Hour in Sleep Mode | |
| 341 ; | |
| 623 | 342 one_hour_sleep: |
| 343 ; tasks every hour in sleep mode mode | |
| 344 bcf trigger_full_hour ; clear one hour flag | |
| 631 | 345 call eeprom_deco_data_write ; update deco data into EEPROM |
| 346 call eeprom_battery_gauge_write ; update battery gauge into EEPROM | |
| 628 | 347 return ; done |
| 623 | 348 |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
349 |
| 634 | 350 ;----------------------------------------------------------------------------- |
| 351 ; Helper Function - Initialization of the Button Event Averaging System | |
| 352 ; | |
| 623 | 353 init_avg_switches: |
| 354 ; pause 4 seconds using CPU sleep mode to conserve on battery | |
| 355 movlw .4 ; time to pause | |
| 356 movwf loop_counter ; initialize loop counter | |
| 357 bcf trigger_full_second ; clear 'one second elapsed' flag | |
| 358 activate_switches_1: | |
| 634 | 359 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 623 | 360 btfss trigger_full_second ; did 1 second elapsed meanwhile? |
| 361 bra activate_switches_1 ; NO - loop | |
| 362 bcf trigger_full_second ; YES - clear flag | |
| 363 decfsz loop_counter,F ; - decrement loop counter, done? | |
| 364 bra activate_switches_1 ; NO - loop | |
| 365 | |
| 366 ; initialize the averaging system | |
| 367 movlw .32 ; number of readout cycles | |
| 368 movwf loop_counter ; initialize loop counter | |
| 369 activate_switches_2: | |
| 370 call get_analog_switches ; do a analog switch readout | |
| 371 decfsz loop_counter,F ; decrement loop counter, done? | |
| 372 bra activate_switches_2 ; NO - loop | |
| 373 | |
| 374 ; clear all button events that may have intermediately occurred | |
| 375 bcf PIR1,TMR1IF ; clear button-hold-down timer | |
| 634 | 376 bcf INTCON, INT0IF ; clear right button activity |
| 623 | 377 bcf INTCON3,INT1IF ; clear left button activity |
| 378 bcf analog_sw1_pressed ; clear analog switch 1 activity | |
| 379 bcf analog_sw2_pressed ; clear analog switch 2 activity | |
| 380 bcf switch_right ; clear right button event | |
| 381 bcf switch_left ; clear left button event | |
| 382 | |
| 634 | 383 return ; done |
| 623 | 384 |
| 385 | |
| 634 | 386 ;----------------------------------------------------------------------------- |
| 387 ; Helper Function - Check for Change in Accelerometer Z-Axis | |
| 388 ; | |
| 623 | 389 check_accelerometer: |
| 604 | 390 rcall deepsleep_get_accel ; read accelerometer into WREG |
| 623 | 391 subwf accel_reference,W ; reference value - accel_DZ+0 -> WREG |
| 604 | 392 btfsc STATUS,N ; result negative? |
| 393 negf WREG ; YES - negate it | |
| 623 | 394 movwf lo ; save as change of acceleration in Z-axis |
| 628 | 395 movlw .100 ; load threshold (mg) |
| 623 | 396 cpfslt lo ; change of acceleration > threshold ? |
| 397 bcf deep_sleep ; YES - terminate deep sleep mode | |
| 398 return ; done | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
399 |
| 582 | 400 |
| 634 | 401 ;----------------------------------------------------------------------------- |
| 402 ; Helper Function - read Accelerometer Z-Axis | |
| 403 ; | |
|
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
404 deepsleep_get_accel: |
| 628 | 405 call I2C_init_compass ; start compass |
| 634 | 406 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 604 | 407 call I2C_RX_accelerometer ; read accelerometer |
| 628 | 408 call I2C_RX_accelerometer ; read accelerometer |
| 409 call I2C_sleep_compass ; shut down compass | |
| 623 | 410 movff accel_DZ+0,WREG ; transfer result to WREG |
| 411 return ; done | |
| 412 | |
| 413 | |
| 634 | 414 ;----------------------------------------------------------------------------- |
| 415 ; Helper Function - read Pressure without Averaging | |
| 416 ; | |
| 417 ; faster method to save some power in sleep mode | |
| 418 ; | |
| 419 pressuretest_sleep_fast: | |
| 623 | 420 banksel isr_backup ; select bank ISR data |
| 421 | |
| 643 | 422 clrf pressure_abs_avg+0 ; clear pressure average register |
| 423 clrf pressure_abs_avg+1 | |
| 424 clrf pressure_abs_avg+2 | |
| 425 | |
| 623 | 426 CLRI temperature_avg ; clear temperature average register |
| 427 | |
| 428 call get_temperature_start ; start temperature integration (73.5 us) | |
| 582 | 429 |
| 634 | 430 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 431 rcall sleepmode_sleep ; sleep for 62.5...125 ms | |
| 623 | 432 |
| 643 | 433 call get_temperature_value ; get temperature... (May return in bank common) |
| 434 banksel isr_backup ; select bank ISR data | |
| 623 | 435 call get_pressure_start ; start pressure integration |
| 436 | |
| 634 | 437 rcall sleepmode_sleep ; sleep for 62.5...125 ms |
| 438 rcall sleepmode_sleep ; sleep for 62.5...125 ms | |
| 623 | 439 |
| 643 | 440 call get_pressure_value ; state2: get pressure (51 us)(May return in bank common) |
| 441 banksel isr_backup ; select bank ISR data | |
| 623 | 442 call calculate_compensation ; calculate temperature compensated pressure (27 us) |
| 443 | |
| 444 MOVII pressure_abs_avg,pressure_abs ; get result, bypassing the averaging | |
| 445 | |
| 446 banksel common ; back to bank common | |
| 582 | 447 return |
| 0 | 448 |
| 449 | |
| 634 | 450 ;----------------------------------------------------------------------------- |
| 451 ; Helper Function - sleep for 62.5...125 ms | |
| 452 ; | |
| 0 | 453 sleepmode_sleep: |
| 634 | 454 movff BSR,BSR_backup ; backup current bank selection |
| 455 banksel common ; switch to bank common | |
| 628 | 456 btfsc charge_in_sleep ; already showing charge screen? |
| 634 | 457 bra sleepmode_sleepwalk ; YES - skip the actual sleep (but wait) |
| 458 sleep ; NO - put CPU into sleep (wakes up by timer 7 IRQ) | |
| 459 sleep ; - put CPU into sleep again | |
| 628 | 460 sleepmode_sleep_1: |
| 634 | 461 movff BSR_backup,BSR ; restore bank selection |
| 462 return ; done | |
| 628 | 463 |
| 464 sleepmode_sleepwalk: | |
| 634 | 465 WAITMS d'65' ; wait 65 ms |
| 466 bra sleepmode_sleep_1 ; continue with common part | |
| 628 | 467 |
| 634 | 468 ;----------------------------------------------------------------------------- |
| 469 | |
| 470 END |
