Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/sleepmode.asm @ 258:abbf9a2c2c48
Small p2_deco optimizations:
Removed pres_tissue_limit[] and sim_pres_tissue_limit[] (Unused).
Separated read_buhlmann_times() and read_buhlmann_coefficients().
| author | JeanDo |
|---|---|
| date | Sun, 10 Apr 2011 14:17:53 +0200 |
| parents | f0cba9cff25c |
| children | a728b4a1b660 |
| rev | line source |
|---|---|
| 0 | 1 ; OSTC - diving computer code |
| 2 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
| 3 ; This program is free software: you can redistribute it and/or modify | |
| 4 ; it under the terms of the GNU General Public License as published by | |
| 5 ; the Free Software Foundation, either version 3 of the License, or | |
| 6 ; (at your option) any later version. | |
| 7 ; This program is distributed in the hope that it will be useful, | |
| 8 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 ; GNU General Public License for more details. | |
| 11 ; You should have received a copy of the GNU General Public License | |
| 12 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 13 ; Routines for sleepmode | |
| 14 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
| 15 ; written: 050520 | |
| 16 ; last updated: 090507 | |
| 17 ; known bugs: | |
| 18 ; ToDo: | |
| 19 sleeploop: ; enter sleepmode! | |
| 20 ; first check if the 16 hash char are=0 | |
| 21 lfsr FSR2, char_O_hash | |
| 22 movlw d'16' | |
| 23 movwf temp1 | |
| 24 sleeploop1: | |
| 25 tstfsz POSTINC2 ; Test hash values | |
| 26 bra sleeploop2 ; At least one char is not zero -> Do not build hash | |
| 27 decfsz temp1,F | |
| 28 bra sleeploop1 | |
| 29 ; build hash (about 90sek @ 16MHz) | |
| 30 call PLED_ClearScreen ; clear | |
| 31 DISPLAYTEXT .1 ; "Building MD2 hash" | |
| 32 DISPLAYTEXT .2 ; "Please wait..." | |
| 116 | 33 call deco_hash ; calculate MD2 hash |
| 0 | 34 movlb b'00000001' ; Back to Bank1 |
| 35 sleeploop2: | |
| 36 call PLED_DisplayOff ; display off | |
| 37 call disable_rs232 ; disable UART module | |
| 38 clrf divemins+0 | |
| 39 clrf divemins+1 | |
| 40 bcf TRISB,6 | |
| 41 bcf TRISB,7 | |
| 42 bcf PORTB,6 | |
| 43 bcf PORTB,7 ; Disable UART | |
| 44 sleeploop_loop: | |
| 45 btfsc oneminupdate ; one minute in sleep? | |
| 46 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation | |
| 47 | |
| 48 btfsc onesecupdate ; one second in sleep? | |
| 49 rcall onesec_sleep ; check switches, check pressure sensor, etc. | |
| 50 | |
| 51 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
| 52 goto restart ; yes | |
| 53 nop | |
| 153 | 54 btfss nsm |
| 0 | 55 sleep ; Sleep until Timer1 will wake up the device |
| 56 nop | |
| 57 bra sleeploop_loop ; do loop until someting happens | |
| 58 | |
| 59 | |
| 60 onemin_sleep: | |
| 61 call get_battery_voltage ; get battery voltage | |
| 62 btfsc enter_error_sleep ; Enter Fatal Error Routine? | |
| 16 | 63 call fatal_error_sleep ; Yes (In Sleepmode_vxx.asm!) |
| 0 | 64 |
| 65 call calc_surface_interval ; Increases Surface-Interval time | |
| 66 call nofly_timeout60 ; check for no fly time | |
| 67 ; adjust airpressure compensation any 15 minutes | |
| 68 incf divemins+1,F ; counts to 14... | |
| 69 movlw d'14' | |
| 70 cpfsgt divemins+1 | |
| 71 bra onemin_sleep2 ; 15 minutes not done! | |
| 72 | |
| 73 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
| 74 | |
| 75 call check_temp_extrema ; Check for temperature extremas | |
| 76 | |
| 116 | 77 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only |
| 0 | 78 movlb b'00000001' |
| 79 movff last_surfpressure_15min+0,last_surfpressure_30min+0 ; save older airpressure | |
| 80 movff last_surfpressure_15min+1,last_surfpressure_30min+1 ; save older airpressure | |
| 81 movff amb_pressure+0,last_surfpressure_15min+0 ; save new airpressure | |
| 82 movff amb_pressure+1,last_surfpressure_15min+1 ; save new airpressure | |
| 83 | |
| 84 clrf divemins+1 ; reset counter | |
| 85 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi | |
| 86 movff lo,sub_a+0 ; max. "allowed" airpressure in mBar | |
| 87 movff hi,sub_a+1 | |
| 88 movff last_surfpressure_15min+0,sub_b+0 | |
| 89 movff last_surfpressure_15min+1,sub_b+1 | |
| 90 call sub16 ; sub_c = sub_a - sub_b | |
| 91 btfsc neg_flag | |
| 92 bra onemin_sleep1 | |
| 93 bra onemin_sleep2 ; current airpressure is lower then "allowed" airpressure, ok! | |
| 94 onemin_sleep1: ; not ok! Overwrite with max. "allowed" airpressure | |
| 95 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi | |
| 96 movff lo,last_surfpressure_15min+0 ; max. "allowed" airpressure in mBar | |
| 97 movff hi,last_surfpressure_15min+1 ; max. "allowed" airpressure in mBar | |
| 98 | |
| 99 onemin_sleep2: | |
| 100 ;calc_deko_sleepmode: | |
| 101 movff amb_pressure+0,int_I_pres_respiration+0 ; LOW copy pressure to deco routine | |
| 102 movff amb_pressure+1,int_I_pres_respiration+1 ; HIGH | |
| 103 GETCUSTOM8 d'11' ; Saturation multiplier % | |
| 251 | 104 movff WREG,char_I_saturation_multiplier |
| 0 | 105 GETCUSTOM8 d'12' ; Desaturation multiplier % |
| 251 | 106 movff WREG,char_I_desaturation_multiplier |
| 116 | 107 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" |
| 0 | 108 movlb b'00000001' ; RAM Bank1 selected |
| 109 | |
| 110 bcf oneminupdate ; all done | |
| 111 return | |
| 112 | |
| 113 onesec_sleep: | |
| 114 call test_charger ; charger on? | |
| 115 | |
| 116 btfss nofly_active | |
| 117 bra onesec_sleep_nonofly | |
| 118 | |
| 21 | 119 bsf LED_blue ; Set nofly LED |
| 0 | 120 |
| 121 nop | |
| 122 sleep | |
| 123 nop | |
| 124 | |
| 125 onesec_sleep_nonofly: | |
| 21 | 126 bcf LED_blue ; Clear nofly LED |
| 0 | 127 incf divemins+0,F ; counts to #test_pressure_in_sleep (5) |
| 128 movlw d'5' | |
| 129 cpfsgt divemins+0 ; here: temp variable | |
| 130 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet | |
| 131 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
| 132 | |
| 133 ; compare current ambient pressure with threshold | |
| 134 GETCUSTOM15 d'6' ; loads pressure threshold into lo,hi | |
| 135 movff lo,sub_a+0 ; power on if ambient pressure is greater threshold | |
| 136 movff hi,sub_a+1 | |
| 137 movff amb_pressure+0,sub_b+0 | |
| 138 movff amb_pressure+1,sub_b+1 | |
| 139 call sub16 ; sub_c = sub_a - sub_b | |
| 140 bsf sleepmode | |
| 141 btfsc neg_flag ; Wake up from Sleep? | |
| 142 bcf sleepmode ; amb_pressure>pressure_offset_divemode: wake up! | |
| 143 clrf divemins+0 | |
| 144 onesec_sleep1: | |
| 145 bcf onesecupdate ; all done. | |
| 146 btfsc switch_left | |
| 147 bra onesec_sleep1a | |
| 148 btfsc switch_right | |
| 149 bra onesec_sleep1a | |
| 150 ; No button pressed | |
| 151 bcf INTCON,INT0IF ; Clear flag | |
| 152 bcf INTCON3,INT1IF ; Clear flag | |
| 153 bcf switch_right_isr | |
| 154 bcf switch_left_isr | |
| 155 bcf switch_right | |
| 156 bcf switch_left | |
| 157 bcf T0CON,TMR0ON ; Stop Timer 0 | |
| 158 return | |
| 159 onesec_sleep1a: ; At least one button pressed.... | |
| 160 bcf INTCON,INT0IF ; Clear flag | |
| 161 bcf INTCON3,INT1IF ; Clear flag | |
| 162 bcf switch_right_isr | |
| 163 bcf switch_left_isr | |
| 164 bcf switch_right | |
| 165 bcf switch_left | |
| 166 bcf T0CON,TMR0ON ; Stop Timer 0 | |
| 167 bcf sleepmode ; wake up! | |
| 125 | 168 bsf show_startup_screen ; |
| 169 | |
|
213
d19445e0cb2f
BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents:
153
diff
changeset
|
170 ; Restart altimeter averaging, so next averaging starts right over... |
|
d19445e0cb2f
BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents:
153
diff
changeset
|
171 call altimeter_restart |
| 125 | 172 |
| 0 | 173 return |
| 174 | |
| 175 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
| 176 call get_temperature_start ; and start temperature integration (73,5us) | |
| 177 sleep | |
| 178 nop | |
| 179 sleep | |
| 180 nop | |
| 181 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup) | |
| 182 call get_temperature_value ; State 1: Get temperature | |
| 183 call get_pressure_start ; Start pressure integration. | |
| 184 sleep | |
| 185 nop | |
| 186 sleep | |
| 187 nop | |
| 188 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup) | |
| 189 call get_pressure_value ; State2: Get pressure (51us) | |
| 190 call calculate_compensation ; calculate temperature compensated pressure (233us) | |
| 191 return | |
| 192 | |
| 193 fatal_error_sleep: | |
| 16 | 194 WAITMS d'250' |
| 195 WAITMS d'250' | |
| 196 WAITMS d'250' | |
| 197 WAITMS d'250' | |
| 198 call get_battery_voltage ; get battery voltage | |
| 199 btfss enter_error_sleep ; REALLY enter Fatal Error Routine? | |
| 200 return ; No! | |
| 0 | 201 clrf INTCON |
| 202 clrf INTCON2 | |
| 203 clrf INTCON3 | |
| 204 bcf ADCON0,0 ; AD converter off | |
| 205 call disable_rs232 ; disable UART module | |
| 206 movlw b'00010000' | |
| 207 movwf TRISA | |
| 208 clrf PORTA ; And pulled to GND | |
| 209 clrf TRISB ; All output | |
| 210 clrf PORTB ; And pulled to GND | |
| 211 movlw b'00011101' ; UART | |
| 212 movwf TRISC | |
| 213 clrf PORTC ; And pulled to GND | |
| 214 clrf TRISD ; All output | |
| 215 clrf PORTD ; And pulled to GND | |
| 216 clrf TRISE ; All output | |
| 217 clrf PORTE ; And pulled to GND | |
| 218 clrf T0CON ; Timer OFF | |
| 219 clrf T1CON ; Timer OFF | |
| 220 clrf T2CON ; Timer OFF | |
| 221 clrf OSCTUNE | |
| 222 movlw b'00000010' ; 31kHz | |
| 223 movwf OSCCON | |
| 224 bsf WDTCON,0 ; Watchdog timer on... | |
| 225 fatal_error_sleep_loop: ; Device will never quit this loop! | |
| 226 movff fatal_error_code,temp4 | |
| 227 movlw d'15' | |
| 228 movwf temp1 | |
| 229 fatal_error_sleep_loop1: | |
| 230 sleep | |
| 231 nop | |
| 232 decfsz temp1,F | |
| 233 bra fatal_error_sleep_loop1 | |
| 234 fatal_error_sleep_loop2: | |
| 21 | 235 bsf LED_red |
| 0 | 236 clrwdt |
| 237 WAIT10US d'5' | |
| 21 | 238 bcf LED_red |
| 0 | 239 sleep |
| 240 nop | |
| 241 decfsz temp4,F | |
| 242 bra fatal_error_sleep_loop2 | |
| 243 bra fatal_error_sleep_loop |
