annotate src/sleepmode.asm @ 491:66b9b8c082a9

minor new sleepmode fix
author heinrichsweikamp
date Thu, 30 Mar 2017 10:41:43 +0200
parents 8dfb93e80338
children beeac8806b93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File sleepmode.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Sleepmode
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-12 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 235
diff changeset
12 #include "hwos.inc" ; Mandatory header
0
heinrichsweikamp
parents:
diff changeset
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
heinrichsweikamp
parents:
diff changeset
14 #include "surfmode.inc"
heinrichsweikamp
parents:
diff changeset
15 #include "tft.inc"
heinrichsweikamp
parents:
diff changeset
16 #include "isr.inc"
heinrichsweikamp
parents:
diff changeset
17 #include "start.inc"
heinrichsweikamp
parents:
diff changeset
18 #include "adc_lightsensor.inc"
heinrichsweikamp
parents:
diff changeset
19 #include "math.inc"
heinrichsweikamp
parents:
diff changeset
20 #include "ms5541.inc"
heinrichsweikamp
parents:
diff changeset
21 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
22 #include "eeprom_rs232.inc"
heinrichsweikamp
parents:
diff changeset
23 #include "external_flash.inc"
heinrichsweikamp
parents:
diff changeset
24 #include "ghostwriter.inc"
heinrichsweikamp
parents:
diff changeset
25 #include "i2c.inc"
28
heinrichsweikamp
parents: 0
diff changeset
26 #include "mcp.inc"
0
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
31 gui CODE
heinrichsweikamp
parents:
diff changeset
32
heinrichsweikamp
parents:
diff changeset
33 global sleeploop
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents: 0
diff changeset
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
heinrichsweikamp
parents:
diff changeset
40 call TFT_Display_FadeOut
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
45 call ext_flash_enable_protection ; enable write protection for external flash
heinrichsweikamp
parents:
diff changeset
46 call update_battery_registers ; update battery registers into EEPROM
heinrichsweikamp
parents:
diff changeset
47 clrf divemins+0
heinrichsweikamp
parents:
diff changeset
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
heinrichsweikamp
parents:
diff changeset
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
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
61 bsf power_sw1
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
62 bsf power_sw2
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
63 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
64 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
65 bcf onesecupdate
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
66 sleeploop_pre1:
491
66b9b8c082a9 minor new sleepmode fix
heinrichsweikamp
parents: 490
diff changeset
67 rcall sleepmode_sleep
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
68 btfss onesecupdate ; Wait 1 second
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
69 bra sleeploop_pre1
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
70 bcf onesecupdate
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
71 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
72 bra sleeploop_pre1
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
73
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
74 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
75 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
76 sleeploop_pre2:
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
77 call get_analog_switches
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
78 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
79 bra sleeploop_pre2
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
80
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
81 bcf PIR1,TMR1IF
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
82 bcf INTCON,INT0IF
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
83 bcf INTCON3,INT1IF
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
84 bcf PIR5,TMR7IF
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
85 bcf switch_left
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
86 bcf switch_right
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
87 bcf analog_sw2_pressed
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
88 bcf analog_sw1_pressed
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
89 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
90 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
91 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
92 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
93 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
94
0
heinrichsweikamp
parents:
diff changeset
95 sleeploop_loop:
134
4574aed5cd4c Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents: 133
diff changeset
96 btfsc onesecupdate ; one second in sleep?
4574aed5cd4c Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents: 133
diff changeset
97 rcall onesec_sleep ; check switches, check pressure sensor, etc.
0
heinrichsweikamp
parents:
diff changeset
98
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
99 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
100 goto restart ; yes
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
101
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
102 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
103 bra deepsleep ; Yes
491
66b9b8c082a9 minor new sleepmode fix
heinrichsweikamp
parents: 490
diff changeset
104 no_deepsleep:
66b9b8c082a9 minor new sleepmode fix
heinrichsweikamp
parents: 490
diff changeset
105
0
heinrichsweikamp
parents:
diff changeset
106 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
heinrichsweikamp
parents:
diff changeset
107
heinrichsweikamp
parents:
diff changeset
108 ; 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
109 ; btfsc switch_left
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
110 ; rcall onesec_sleep1a
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
111 ; btfsc switch_right
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
112 ; rcall onesec_sleep1a
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
113 ;
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
114 ; 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
115 ; goto restart ; yes
0
heinrichsweikamp
parents:
diff changeset
116
heinrichsweikamp
parents:
diff changeset
117 bra sleeploop_loop ; do loop until someting happens
heinrichsweikamp
parents:
diff changeset
118
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
119 deepsleep:
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
120 btfss analog_switches
491
66b9b8c082a9 minor new sleepmode fix
heinrichsweikamp
parents: 490
diff changeset
121 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
122
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
123 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
124 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
125 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
126 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
127 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
128 bcf power_sw1
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
129 bcf power_sw2
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
130 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
131 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
132
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
133 deepsleep_loop:
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
134 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
135 rcall onesec_deepsleep ; check accelerometer
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 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
138 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
139
491
66b9b8c082a9 minor new sleepmode fix
heinrichsweikamp
parents: 490
diff changeset
140 rcall sleepmode_sleep
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
141
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
142 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
143 bra sleeploop_pre ; Yes
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
144
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
145 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
146
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
147 onesec_deepsleep:
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
148 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
149 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
150 btfsc STATUS,N ; Result negative?
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
151 negf WREG ; Yes, negate it
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
152 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
153 movlw .50 ; Threshold (mg)
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
154 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
155 bcf deep_sleep ; Yes!
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
156
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
157 ; extern piezo_config_tx
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
158 ; 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
159 ; call piezo_config_tx
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
160 ; movff accel_DZ+0,WREG
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
161 ; call 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+1,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 return
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
165
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
166 deepsleep_get_accel:
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
167 call I2C_init_compass
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
168 call I2C_RX_accelerometer ; read Accelerometer
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
169 call I2C_sleep_compass
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
170 movff accel_DZ+0,WREG
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
171 return
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
172
134
4574aed5cd4c Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents: 133
diff changeset
173 onehour_sleep:
4574aed5cd4c Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents: 133
diff changeset
174 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
175 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
176 bcf onehourupdate ; all done
4574aed5cd4c Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents: 133
diff changeset
177 return
0
heinrichsweikamp
parents:
diff changeset
178
heinrichsweikamp
parents:
diff changeset
179 onemin_sleep:
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
180 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
181 rcall onehour_sleep ; Yes
198
c511dc403d7e (Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents: 134
diff changeset
182
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
183 btfsc battery_gauge_available
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
184 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
185
0
heinrichsweikamp
parents:
diff changeset
186 ;---- adjust airpressure compensation any 15 minutes
heinrichsweikamp
parents:
diff changeset
187 incf divemins+1,F ; counts to 14...
heinrichsweikamp
parents:
diff changeset
188 movlw d'14'
heinrichsweikamp
parents:
diff changeset
189 cpfsgt divemins+1
heinrichsweikamp
parents:
diff changeset
190 bra onemin_sleep2 ; 15 minutes not done!
heinrichsweikamp
parents:
diff changeset
191
heinrichsweikamp
parents:
diff changeset
192 ; 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
193 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
194
0
heinrichsweikamp
parents:
diff changeset
195 clrf divemins+1 ; reset counter
heinrichsweikamp
parents:
diff changeset
196
heinrichsweikamp
parents:
diff changeset
197 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only
heinrichsweikamp
parents:
diff changeset
198 banksel common
heinrichsweikamp
parents:
diff changeset
199
heinrichsweikamp
parents:
diff changeset
200 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older airpressure
heinrichsweikamp
parents:
diff changeset
201 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure
heinrichsweikamp
parents:
diff changeset
202
heinrichsweikamp
parents:
diff changeset
203 movlw LOW max_surfpressure
heinrichsweikamp
parents:
diff changeset
204 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar
heinrichsweikamp
parents:
diff changeset
205 movlw HIGH max_surfpressure
heinrichsweikamp
parents:
diff changeset
206 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar
heinrichsweikamp
parents:
diff changeset
207 movff last_surfpressure_15min+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
208 movff last_surfpressure_15min+1,sub_b+1
heinrichsweikamp
parents:
diff changeset
209 call subU16 ; sub_c = sub_a - sub_b
heinrichsweikamp
parents:
diff changeset
210 btfss neg_flag ; Is 1080mbar < amb_pressure ?
heinrichsweikamp
parents:
diff changeset
211 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok!
heinrichsweikamp
parents:
diff changeset
212
heinrichsweikamp
parents:
diff changeset
213 ; not ok! Overwrite with max. "allowed" airpressure
heinrichsweikamp
parents:
diff changeset
214 movlw LOW max_surfpressure
heinrichsweikamp
parents:
diff changeset
215 movff WREG,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar
heinrichsweikamp
parents:
diff changeset
216 movlw HIGH max_surfpressure
heinrichsweikamp
parents:
diff changeset
217 movff WREG,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar
heinrichsweikamp
parents:
diff changeset
218
heinrichsweikamp
parents:
diff changeset
219 onemin_sleep2:
heinrichsweikamp
parents:
diff changeset
220 ; Tasks every minute in sleep
heinrichsweikamp
parents:
diff changeset
221 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine
heinrichsweikamp
parents:
diff changeset
222 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep"
heinrichsweikamp
parents:
diff changeset
223 banksel common
heinrichsweikamp
parents:
diff changeset
224
heinrichsweikamp
parents:
diff changeset
225 bcf oneminupdate ; all done
heinrichsweikamp
parents:
diff changeset
226 return
heinrichsweikamp
parents:
diff changeset
227
heinrichsweikamp
parents:
diff changeset
228 onesec_sleep:
198
c511dc403d7e (Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents: 134
diff changeset
229 btfsc oneminupdate ; one minute in sleep?
c511dc403d7e (Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents: 134
diff changeset
230 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
231
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
232 ; btfsc battery_gauge_available
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
233 ; call get_battery_voltage ; Check for charger
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 50
diff changeset
234
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
235 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
236 movlw d'10'
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
237 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
238 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet
0
heinrichsweikamp
parents:
diff changeset
239
heinrichsweikamp
parents:
diff changeset
240 clrf divemins+0 ; clear counter
heinrichsweikamp
parents:
diff changeset
241 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!)
heinrichsweikamp
parents:
diff changeset
242 ; 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
243 movlw LOW wake_up_from_sleep
0
heinrichsweikamp
parents:
diff changeset
244 movwf sub_a+0 ; power on if ambient pressure is greater threshold
heinrichsweikamp
parents:
diff changeset
245 movlw HIGH wake_up_from_sleep
heinrichsweikamp
parents:
diff changeset
246 movwf sub_a+1 ; power on if ambient pressure is greater threshold
heinrichsweikamp
parents:
diff changeset
247 SAFE_2BYTE_COPY amb_pressure, sub_b
heinrichsweikamp
parents:
diff changeset
248 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ?
heinrichsweikamp
parents:
diff changeset
249 btfsc neg_flag ; Wake up from Sleep?
heinrichsweikamp
parents:
diff changeset
250 bra onesec_sleep1a ; Yes, skip button checks, wake up!
heinrichsweikamp
parents:
diff changeset
251
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
252 btfsc battery_gauge_available
200
dcd513840c6c cleanup
heinrichsweikamp
parents: 198
diff changeset
253 bra onesec_sleep1 ; No wake-up with cR hardware
0
heinrichsweikamp
parents:
diff changeset
254 btfsc vusb_in ; USB plugged in?
123
d076e9c02438 add ceiling display
heinrichsweikamp
parents: 121
diff changeset
255 bra onesec_sleep1a ; Yes, skip button checks, wake up!
0
heinrichsweikamp
parents:
diff changeset
256
heinrichsweikamp
parents:
diff changeset
257 onesec_sleep1:
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
258 bcf onesecupdate ; all done.
0
heinrichsweikamp
parents:
diff changeset
259 ; Check switches
heinrichsweikamp
parents:
diff changeset
260 btfsc switch_left
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
261 bra onesec_sleep1a
0
heinrichsweikamp
parents:
diff changeset
262 btfsc switch_right
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
263 bra onesec_sleep1a
0
heinrichsweikamp
parents:
diff changeset
264 ; No button pressed
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
265 ; bcf INTCON,INT0IF ; Clear flag
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
266 ; bcf INTCON3,INT1IF ; Clear flag
0
heinrichsweikamp
parents:
diff changeset
267 return
heinrichsweikamp
parents:
diff changeset
268
heinrichsweikamp
parents:
diff changeset
269 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
270 ; bcf INTCON,INT0IF ; Clear flag
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
271 ; bcf INTCON3,INT1IF ; Clear flag
0
heinrichsweikamp
parents:
diff changeset
272 bcf sleepmode ; wake up!
heinrichsweikamp
parents:
diff changeset
273 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility
heinrichsweikamp
parents:
diff changeset
274 movlw .0
heinrichsweikamp
parents:
diff changeset
275 movff WREG,sensor_state_counter ; Reset sensor state counter
heinrichsweikamp
parents:
diff changeset
276 bcf no_sensor_int ; normal sensor interrupt mode
heinrichsweikamp
parents:
diff changeset
277 return
heinrichsweikamp
parents:
diff changeset
278
heinrichsweikamp
parents:
diff changeset
279 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode)
heinrichsweikamp
parents:
diff changeset
280 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
281 clrf amb_pressure_avg+0 ; pressure average registers
heinrichsweikamp
parents:
diff changeset
282 clrf amb_pressure_avg+1
heinrichsweikamp
parents:
diff changeset
283 clrf temperature_avg+0
heinrichsweikamp
parents:
diff changeset
284 clrf temperature_avg+1
heinrichsweikamp
parents:
diff changeset
285 call get_temperature_start ; and start temperature integration (73,5us)
heinrichsweikamp
parents:
diff changeset
286 banksel common
heinrichsweikamp
parents:
diff changeset
287 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
heinrichsweikamp
parents:
diff changeset
288 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
heinrichsweikamp
parents:
diff changeset
289 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
290 call get_temperature_value ; State 1: Get temperature
heinrichsweikamp
parents:
diff changeset
291 call get_pressure_start ; Start pressure integration.
heinrichsweikamp
parents:
diff changeset
292 banksel common
heinrichsweikamp
parents:
diff changeset
293 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
heinrichsweikamp
parents:
diff changeset
294 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
50
ec4d8503ec45 NEW: user-selectable color schemes
heinrichsweikamp
parents: 39
diff changeset
295 bsf LEDg ; Show some activity
0
heinrichsweikamp
parents:
diff changeset
296 banksel isr_backup ; Back to Bank0 ISR data
heinrichsweikamp
parents:
diff changeset
297 call get_pressure_value ; State2: Get pressure (51us)
heinrichsweikamp
parents:
diff changeset
298 call calculate_compensation ; calculate temperature compensated pressure (27us)
heinrichsweikamp
parents:
diff changeset
299 banksel common
heinrichsweikamp
parents:
diff changeset
300 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility
50
ec4d8503ec45 NEW: user-selectable color schemes
heinrichsweikamp
parents: 39
diff changeset
301 bcf LEDg
0
heinrichsweikamp
parents:
diff changeset
302 return
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304 sleepmode_sleep:
heinrichsweikamp
parents:
diff changeset
305 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM.
heinrichsweikamp
parents:
diff changeset
306 clrf T7GCON ; Reset Timer7 Gate Control register
heinrichsweikamp
parents:
diff changeset
307 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced
heinrichsweikamp
parents:
diff changeset
308 movwf T7CON
heinrichsweikamp
parents:
diff changeset
309 sleep
198
c511dc403d7e (Slightly) reduce current consumption in Eco and sleep mode
heinrichsweikamp
parents: 134
diff changeset
310 sleep
0
heinrichsweikamp
parents:
diff changeset
311 clrf T7GCON ; Reset Timer7 Gate Control register
heinrichsweikamp
parents:
diff changeset
312 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced
heinrichsweikamp
parents:
diff changeset
313 movwf T7CON
heinrichsweikamp
parents:
diff changeset
314 banksel common ; Bank1
heinrichsweikamp
parents:
diff changeset
315 return
heinrichsweikamp
parents:
diff changeset
316
heinrichsweikamp
parents:
diff changeset
317 END