Mercurial > public > hwos_code
annotate src/sleepmode.asm @ 569:fea63a20c1c5
language updates
author | heinrichsweikamp |
---|---|
date | Fri, 09 Feb 2018 11:22:42 +0100 |
parents | b7eb98dbd800 |
children | b455b31ce022 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File sleepmode.asm | |
4 ; | |
5 ; Sleepmode | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-12 : [mH] moving from OSTC code | |
11 | |
275 | 12 #include "hwos.inc" ; Mandatory header |
0 | 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
14 #include "surfmode.inc" | |
15 #include "tft.inc" | |
16 #include "isr.inc" | |
17 #include "start.inc" | |
18 #include "adc_lightsensor.inc" | |
19 #include "math.inc" | |
20 #include "ms5541.inc" | |
21 #include "wait.inc" | |
22 #include "eeprom_rs232.inc" | |
23 #include "external_flash.inc" | |
24 #include "ghostwriter.inc" | |
25 #include "i2c.inc" | |
28 | 26 #include "mcp.inc" |
0 | 27 |
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
123
diff
changeset
|
28 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
123
diff
changeset
|
29 extern vault_decodata_into_eeprom |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
123
diff
changeset
|
30 |
0 | 31 gui CODE |
32 | |
33 global sleeploop | |
34 sleeploop: ; enter sleepmode! | |
224
5a4801918be9
temporally disable "Copy disable flags from digital input" routine
heinrichsweikamp
parents:
205
diff
changeset
|
35 call disable_ir_s8 ; IR/S8 off |
28 | 36 call mcp_sleep |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
37 bcf LEDg |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
38 bcf LEDr |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
275
diff
changeset
|
39 movff menupos3,customview_surfmode; save last customview |
0 | 40 call TFT_Display_FadeOut |
41 call TFT_DisplayOff ; display off | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
42 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) |
0 | 43 call disable_rs232 ; USB off |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
44 call vault_decodata_into_eeprom ; store deco data |
0 | 45 call ext_flash_enable_protection ; enable write protection for external flash |
46 call update_battery_registers ; update battery registers into EEPROM | |
47 clrf divemins+0 | |
48 clrf divemins+1 | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
49 clrf apnoe_max_pressure+0 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
50 clrf apnoe_max_pressure+1 |
0 | 51 call speed_normal |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
52 bsf no_sensor_int ; No sensor interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
53 clrf ADCON0 ; Power-Down ADC Module |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
54 sleeploop_pre: |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
55 bcf deep_sleep ; Normal sleepmode |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
56 call I2C_sleep_accelerometer |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
57 call I2C_sleep_compass |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
58 btfss analog_switches |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
59 bra sleeploop_loop ; no analog switches |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
60 |
501 | 61 bsf power_sw1 |
62 btfss power_sw1 | |
63 bra $-4 | |
64 bsf power_sw2 | |
65 btfss power_sw2 | |
66 bra $-4 | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
67 movlw .4 ; Wait for button circuity |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
68 movwf apnoe_max_pressure+0 ; Used as temp |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
69 bcf onesecupdate |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
70 sleeploop_pre1: |
491 | 71 rcall sleepmode_sleep |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
72 btfss onesecupdate ; Wait 1 second |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
73 bra sleeploop_pre1 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
74 bcf onesecupdate |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
75 decfsz apnoe_max_pressure+0,F |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
76 bra sleeploop_pre1 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
77 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
78 movlw .32 ; Wait for button circuity |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
79 movwf apnoe_max_pressure+0 ; Used as temp |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
80 sleeploop_pre2: |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
81 call get_analog_switches |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
82 decfsz apnoe_max_pressure+0,F |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
83 bra sleeploop_pre2 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
84 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
85 bcf PIR1,TMR1IF |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
86 bcf INTCON,INT0IF |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
87 bcf INTCON3,INT1IF |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
88 bcf PIR5,TMR7IF |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
89 bcf switch_left |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
90 bcf switch_right |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
91 bcf analog_sw2_pressed |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
92 bcf analog_sw1_pressed |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
93 bsf PIE1,0 ; (Re)Start Timer 1 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
94 bsf PIE2,1 ; (Re)Start Timer 2 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
95 bsf PIE5,3 ; (Re)Start Timer 7 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
96 bsf INTCON,4 ; (Re)Start INT0 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
97 bsf INTCON3,3 ; (Re)Start INT1 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
98 |
0 | 99 sleeploop_loop: |
134
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
100 btfsc onesecupdate ; one second in sleep? |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
101 rcall onesec_sleep ; check switches, check pressure sensor, etc. |
0 | 102 |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
103 btfss sleepmode ; wake up? (This bit will be set in other routines) |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
104 goto restart ; yes |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
105 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
106 btfsc deep_sleep ; Enter deep sleep? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
107 bra deepsleep ; Yes |
491 | 108 no_deepsleep: |
109 | |
0 | 110 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
111 | |
112 ; Any button pressed in sleep? | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
113 ; btfsc switch_left |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
114 ; rcall onesec_sleep1a |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
115 ; btfsc switch_right |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
116 ; rcall onesec_sleep1a |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
117 ; |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
118 ; btfss sleepmode ; wake up? (This bit will be set in other routines) |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
119 ; goto restart ; yes |
0 | 120 |
121 bra sleeploop_loop ; do loop until someting happens | |
122 | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
123 deepsleep: |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
124 btfss analog_switches |
491 | 125 bra no_deepsleep ; no analog switches, no deep sleep required |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
126 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
127 bcf PIE1,0 ; Stop Timer 1 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
128 bcf PIE2,1 ; Stop Timer 2 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
129 bcf PIE5,3 ; Stop Timer 7 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
130 bcf INTCON,4 ; Stop INT0 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
131 bcf INTCON3,3 ; Stop INT1 Interrupt |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
132 bcf power_sw1 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
133 bcf power_sw2 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
134 rcall deepsleep_get_accel ; Read accelerometer into WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
135 movwf apnoe_max_pressure+0 ; Store init value |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
136 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
137 deepsleep_loop: |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
138 btfsc onesecupdate ; one second in sleep? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
139 rcall onesec_deepsleep ; check accelerometer |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
140 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
141 btfsc onesecupdate ; one second in sleep? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
142 rcall onesec_sleep ; check switches, check pressure sensor, etc. |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
143 |
491 | 144 rcall sleepmode_sleep |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
145 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
146 btfss deep_sleep ; Enter normal sleepmode? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
147 bra sleeploop_pre ; Yes |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
148 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
149 bra deepsleep_loop ; do loop until someting happens |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
150 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
151 onesec_deepsleep: |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
152 rcall deepsleep_get_accel ; Read accelerometer into WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
153 subwf apnoe_max_pressure+0,W ; apnoe_max_pressure+0 - accel_DZ+0 -> WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
154 btfsc STATUS,N ; Result negative? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
155 negf WREG ; Yes, negate it |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
156 movwf apnoe_max_pressure+1 ; change of acceleration in Z-axis |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
157 movlw .50 ; Threshold (mg) |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
158 cpfslt apnoe_max_pressure+1 ; bigger then the threshold? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
159 bcf deep_sleep ; Yes! |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
160 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
161 ; extern piezo_config_tx |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
162 ; movff apnoe_max_pressure+0,WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
163 ; call piezo_config_tx |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
164 ; movff accel_DZ+0,WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
165 ; call piezo_config_tx |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
166 ; movff apnoe_max_pressure+1,WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
167 ; call piezo_config_tx |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
168 return |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
169 |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
170 deepsleep_get_accel: |
560 | 171 call I2C_init_compass ; required for compass1 |
172 call I2C_init_accelerometer ; required for compass2 | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
173 call I2C_RX_accelerometer ; read Accelerometer |
560 | 174 call I2C_sleep_compass ; required for compass1 |
175 call I2C_sleep_accelerometer ; required for compass2 | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
176 movff accel_DZ+0,WREG |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
177 return |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
178 |
134
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
179 onehour_sleep: |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
180 call update_battery_registers ; update battery registers into EEPROM |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
181 call vault_decodata_into_eeprom ; update deco data |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
182 bcf onehourupdate ; all done |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
183 return |
0 | 184 |
185 onemin_sleep: | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
186 btfsc onehourupdate ; one hour in sleep? |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
187 rcall onehour_sleep ; Yes |
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
134
diff
changeset
|
188 |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
189 btfsc battery_gauge_available |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
190 call get_battery_voltage ; Check for charger |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
191 |
0 | 192 ;---- adjust airpressure compensation any 15 minutes |
193 incf divemins+1,F ; counts to 14... | |
194 movlw d'14' | |
195 cpfsgt divemins+1 | |
196 bra onemin_sleep2 ; 15 minutes not done! | |
197 | |
198 ; Tasks every 15 minutes in sleep | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
199 bsf deep_sleep ; enter deep-sleep mode |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
200 |
0 | 201 clrf divemins+1 ; reset counter |
202 | |
203 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only | |
204 banksel common | |
205 | |
206 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older airpressure | |
207 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure | |
208 | |
209 movlw LOW max_surfpressure | |
210 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
211 movlw HIGH max_surfpressure | |
212 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
213 movff last_surfpressure_15min+0,sub_b+0 | |
214 movff last_surfpressure_15min+1,sub_b+1 | |
215 call subU16 ; sub_c = sub_a - sub_b | |
216 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
217 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
218 | |
219 ; not ok! Overwrite with max. "allowed" airpressure | |
220 movlw LOW max_surfpressure | |
221 movff WREG,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar | |
222 movlw HIGH max_surfpressure | |
223 movff WREG,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar | |
224 | |
225 onemin_sleep2: | |
226 ; Tasks every minute in sleep | |
227 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine | |
228 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" | |
229 banksel common | |
230 | |
231 bcf oneminupdate ; all done | |
232 return | |
233 | |
234 onesec_sleep: | |
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
134
diff
changeset
|
235 btfsc oneminupdate ; one minute in sleep? |
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
134
diff
changeset
|
236 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation |
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
134
diff
changeset
|
237 |
494 | 238 btfsc battery_gauge_available |
239 call get_battery_voltage ; Check for charger | |
120 | 240 |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
241 incf divemins+0,F ; counts to #test_pressure_in_sleep (10) |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
242 movlw d'10' |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
243 cpfsgt divemins+0 ; here: temp variable |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
244 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet |
0 | 245 |
246 clrf divemins+0 ; clear counter | |
247 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
248 ; compare current ambient pressure with wake_up_from_sleep | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
249 movlw LOW wake_up_from_sleep |
0 | 250 movwf sub_a+0 ; power on if ambient pressure is greater threshold |
251 movlw HIGH wake_up_from_sleep | |
252 movwf sub_a+1 ; power on if ambient pressure is greater threshold | |
253 SAFE_2BYTE_COPY amb_pressure, sub_b | |
254 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? | |
255 btfsc neg_flag ; Wake up from Sleep? | |
256 bra onesec_sleep1a ; Yes, skip button checks, wake up! | |
257 | |
448 | 258 btfsc battery_gauge_available |
200 | 259 bra onesec_sleep1 ; No wake-up with cR hardware |
0 | 260 btfsc vusb_in ; USB plugged in? |
123 | 261 bra onesec_sleep1a ; Yes, skip button checks, wake up! |
0 | 262 |
263 onesec_sleep1: | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
264 bcf onesecupdate ; all done. |
0 | 265 ; Check switches |
266 btfsc switch_left | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
267 bra onesec_sleep1a |
0 | 268 btfsc switch_right |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
269 bra onesec_sleep1a |
0 | 270 ; No button pressed |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
271 ; bcf INTCON,INT0IF ; Clear flag |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
272 ; bcf INTCON3,INT1IF ; Clear flag |
0 | 273 return |
274 | |
275 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep | |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
276 ; bcf INTCON,INT0IF ; Clear flag |
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
448
diff
changeset
|
277 ; bcf INTCON3,INT1IF ; Clear flag |
0 | 278 bcf sleepmode ; wake up! |
279 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | |
280 movlw .0 | |
281 movff WREG,sensor_state_counter ; Reset sensor state counter | |
282 bcf no_sensor_int ; normal sensor interrupt mode | |
283 return | |
284 | |
285 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
286 banksel isr_backup ; Back to Bank0 ISR data | |
287 clrf amb_pressure_avg+0 ; pressure average registers | |
288 clrf amb_pressure_avg+1 | |
289 clrf temperature_avg+0 | |
290 clrf temperature_avg+1 | |
291 call get_temperature_start ; and start temperature integration (73,5us) | |
292 banksel common | |
293 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
294 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
295 banksel isr_backup ; Back to Bank0 ISR data | |
296 call get_temperature_value ; State 1: Get temperature | |
297 call get_pressure_start ; Start pressure integration. | |
298 banksel common | |
299 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
300 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
301 banksel isr_backup ; Back to Bank0 ISR data | |
302 call get_pressure_value ; State2: Get pressure (51us) | |
303 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
304 banksel common | |
305 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | |
306 return | |
307 | |
308 sleepmode_sleep: | |
309 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
310 clrf T7GCON ; Reset Timer7 Gate Control register | |
311 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
312 movwf T7CON | |
313 sleep | |
198
c511dc403d7e
(Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents:
134
diff
changeset
|
314 sleep |
0 | 315 clrf T7GCON ; Reset Timer7 Gate Control register |
316 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
317 movwf T7CON | |
318 banksel common ; Bank1 | |
319 return | |
320 | |
321 END |