Mercurial > public > hwos_code
annotate src/start.asm @ 93:5e1ef9bf32ec
clear pressure sensor compensation upon update
author | heinrichsweikamp |
---|---|
date | Thu, 17 Apr 2014 10:28:04 +0200 |
parents | 0fae975af741 |
children | f3062a611eef |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File start.asm | |
4 ; | |
5 ; Startup subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-06 : [mH] moving from OSTC code | |
11 | |
12 #include "ostc3.inc" ; Mandatory header | |
13 #include "ms5541.inc" | |
14 #include "isr.inc" | |
15 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
16 #include "eeprom_rs232.inc" | |
17 #include "math.inc" | |
18 #include "tft.inc" | |
19 #include "surfmode.inc" | |
20 #include "wait.inc" | |
21 #include "rtc.inc" | |
22 #include "external_flash.inc" | |
23 #include "convert.inc" | |
24 #include "strings.inc" | |
25 #include "tft_outputs.inc" | |
26 | |
27 extern init_ostc3 | |
28 extern option_restore_all | |
29 | |
30 ;============================================================================= | |
31 ; Reset vector: What to do on device wake-up and hard reset. | |
32 ; | |
33 reset_v code 0x00000 | |
34 ; goto start | |
35 goto 0x1FF00 ; Bootloader | |
36 | |
37 ORG 0x00004 ; Needed for second-level bootloader | |
38 goto start | |
39 ;============================================================================= | |
40 boot CODE | |
41 global start | |
42 | |
43 start: | |
44 lfsr FSR0,0x000 ; Clear rambank 0-14 | |
45 clear_rambank: | |
46 clrf POSTINC0 | |
47 movlw 0x0F | |
48 cpfseq FSR0H ; Bank 14 done? | |
49 bra clear_rambank ; clear... | |
50 | |
51 call init_ostc3 | |
52 call speed_normal | |
53 | |
54 bsf no_sensor_int ; disable sensor interrupt | |
55 | |
56 call disable_rs232 ; disable UART module | |
57 ; Air pressure compensation after reset | |
58 call get_calibration_data ; Get calibration data from pressure sensor | |
59 banksel common ; get_calibration_data uses isr_backup | |
60 bcf no_sensor_int ; normal sensor interrupt mode | |
61 | |
10 | 62 call TFT_DisplayOff ; display off |
63 bsf LEDr ; Status LED | |
0 | 64 bcf pressure_refresh |
65 ; First pass will not have valid temperature! | |
66 btfss pressure_refresh ; Air pressure compensation | |
67 bra $-2 | |
50 | 68 bcf LEDr |
0 | 69 ; Second pass |
70 bcf pressure_refresh | |
71 btfss pressure_refresh ; Air pressure compensation | |
72 bra $-2 | |
73 | |
74 clrf rel_pressure+0 | |
75 clrf rel_pressure+1 | |
76 clrf surface_interval+0 | |
77 clrf surface_interval+1 | |
78 | |
79 SAFE_2BYTE_COPY amb_pressure, last_surfpressure | |
80 | |
81 movlw LOW max_surfpressure | |
82 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
83 movlw HIGH max_surfpressure | |
84 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
85 movff last_surfpressure+0,sub_b+0 | |
86 movff last_surfpressure+1,sub_b+1 | |
87 call subU16 ; sub_c = sub_a - sub_b | |
88 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
89 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
90 | |
91 ; not ok! Overwrite with max. "allowed" airpressure | |
92 movlw LOW max_surfpressure | |
93 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar | |
94 movlw HIGH max_surfpressure | |
95 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar | |
96 | |
97 start_copy_pressure: | |
98 movff last_surfpressure+0,last_surfpressure_15min+0 | |
99 movff last_surfpressure+1,last_surfpressure_15min+1 | |
100 movff last_surfpressure+0,last_surfpressure_30min+0 | |
101 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers | |
102 | |
103 ; reset deco data for surface mode | |
104 movlw d'79' | |
105 movff WREG,char_I_N2_ratio ; 79% N2 | |
106 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine | |
107 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine | |
108 movff int_I_pres_respiration+1,int_I_pres_surface+1 | |
109 | |
110 extern deco_reset | |
111 call deco_reset | |
112 call deco_calc_desaturation_time ; calculate desaturation time | |
113 banksel common | |
114 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode | |
115 banksel common | |
116 clrf nofly_time+0 ; Reset NoFly | |
117 clrf nofly_time+1 | |
118 clrf desaturation_time+0 ; Reset Desat | |
119 clrf desaturation_time+1 | |
120 bcf menubit ; clear menu flag | |
121 ; Check for Power-on reset here | |
122 extern new_battery_menu | |
123 extern use_old_batteries | |
124 | |
125 btfsc RCON,POR ; Was this a power-on reset? | |
126 goto use_old_batteries ; No, load last stored battery values | |
127 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
128 | |
129 ; Yes | |
130 call rtc_init ; init clock | |
131 goto new_battery_menu ; show "New battery dialog" | |
132 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
133 | |
134 global power_on_return | |
135 power_on_return: | |
136 bsf RCON,POR ; Set bit for next detection | |
137 | |
138 ; check firmware and reset Custom Functions after an update | |
139 movlw d'1' | |
140 movwf EEADR | |
141 movlw d'1' | |
142 movwf EEADRH | |
143 call read_eeprom ; read current version x | |
144 movff EEDATA,temp1 | |
145 incf EEADR,F ; set to 0x102 | |
146 call read_eeprom ; read current version y | |
147 movff EEDATA,temp2 | |
148 clrf EEADRH ; Reset EEADRH | |
149 | |
150 movlw softwareversion_x | |
151 cpfseq temp1 ; compare version x | |
152 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
153 | |
154 movlw softwareversion_y | |
155 cpfseq temp2 ; compare version y | |
156 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
157 bra restart ; x and y are equal -> do not reset cf | |
158 | |
159 check_firmware_new: | |
160 call speed_normal | |
161 call TFT_boot ; Initialize TFT (includes clear screen) | |
162 clrf CCPR1L ; Backlight off | |
163 WIN_TOP .50 | |
164 WIN_LEFT .10 | |
165 movlw LOW 0x1E000 | |
166 movwf TBLPTRL | |
167 movlw HIGH 0x1E000 | |
168 movwf TBLPTRH | |
169 movlw UPPER 0x1E000 | |
170 movwf TBLPTRU | |
171 extern color_image | |
172 call color_image ; Show logo | |
173 call TFT_standard_color | |
174 WIN_SMALL .10,.100 | |
52 | 175 STRCPY_TEXT_PRINT tNewFirmware1 ; "Update successfull!" |
0 | 176 WIN_SMALL .10,.140 |
177 STRCPY_TEXT tNewFirmware2 ; "New Firmware: " | |
178 movlw softwareversion_x | |
179 movwf lo | |
180 bsf leftbind | |
181 output_8 | |
182 PUTC "." | |
183 movlw softwareversion_y | |
184 movwf lo | |
45 | 185 output_99x |
0 | 186 bcf leftbind |
187 STRCAT_PRINT "" ; Print second row | |
188 call TFT_Display_FadeIn ; Display resulting surface screen. | |
189 | |
190 ; place "after-update reset" here... | |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
191 |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
192 extern oPressureAdjust, option_reset, option_save |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
193 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
194 call option_reset ; Reset FSR0 option to factory default. |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
195 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
196 call option_save ; Save in EEPROM |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
197 |
0 | 198 movlw d'1' ; store current version in EEPROM |
199 movwf EEADR | |
200 movlw d'1' | |
201 movwf EEADRH | |
202 movlw softwareversion_x | |
203 movwf EEDATA | |
204 call write_eeprom ; write version x | |
205 incf EEADR,F ; set to 0x102 | |
206 movlw softwareversion_y | |
207 movwf EEDATA | |
208 call write_eeprom ; write version y | |
209 clrf EEADRH ; Reset EEADRH | |
210 | |
211 movlw .7 | |
212 movwf lo | |
213 check_firmware_new2: | |
214 ; Wait 1 second | |
215 bcf onesecupdate | |
216 btfss onesecupdate | |
217 bra $-2 | |
218 decfsz lo,F ; Wait 10 seconds... | |
219 bra check_firmware_new2 | |
220 | |
221 global restart | |
222 restart: | |
223 clrf STKPTR ; Never return from here | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
224 extern option_save_all, option_check_all |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
225 |
0 | 226 btfsc menubit ; Return from Menu/COMM mode or timeout? |
227 call option_save_all ; Yes, save all settings into EEPROM | |
228 | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
229 call option_check_all ; Check all options (and reset if not within their min/max boundaries) |
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
230 |
0 | 231 clrf flag1 ; clear all flags |
232 clrf flag2 | |
233 clrf flag3 | |
234 clrf flag4 | |
235 clrf flag5 | |
236 clrf flag6 | |
237 clrf flag7 | |
238 clrf flag8 | |
16
7b06f20881be
calm compass reading for minor heading changes
heinrichsweikamp
parents:
10
diff
changeset
|
239 clrf flag9 |
0 | 240 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
241 |
0 | 242 ; Select high altitude (Fly) mode? |
243 movff last_surfpressure_30min+0,sub_b+0 | |
244 movff last_surfpressure_30min+1,sub_b+1 | |
245 movlw HIGH high_altitude_threshold | |
246 movwf sub_a+1 | |
247 movlw LOW high_altitude_threshold ; Hard-wired 880mbar | |
248 movwf sub_a+0 | |
249 call subU16 ; sub_c = sub_a - sub_b | |
250 btfss neg_flag ; Result negative (Ambient>880mbar)? | |
251 bsf high_altitude_mode ; No, Set Flag! | |
252 | |
253 call ext_flash_disable_protection ; Disable write protection for external flash | |
254 | |
255 extern testloop | |
256 ; goto testloop | |
257 | |
258 goto surfloop ; Jump to Surfaceloop! | |
259 | |
260 ;============================================================================= | |
261 ; Setup all flags and parameters for divemode and simulator computations. | |
262 ; | |
263 global restart_set_modes_and_flags | |
264 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
265 call option_restore_all ; Restore everything from EEPROM | |
24 | 266 |
267 ; Setup sampling rate | |
268 movlw .2 | |
269 movwf samplingrate | |
270 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
271 bra restart_set_modes_and_flags1 | |
272 movlw .10 | |
273 movwf samplingrate | |
274 restart_set_modes_and_flags1: | |
0 | 275 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea |
276 | |
277 bcf FLAG_apnoe_mode | |
278 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
279 bcf FLAG_gauge_mode ; =1: In Gauge mode | |
280 call disable_ir ; IR off | |
281 | |
282 tstfsz lo | |
283 bra restart_set_modes_and_flags2 | |
284 ; OC Mode | |
285 return | |
286 | |
287 restart_set_modes_and_flags2: | |
288 decfsz lo,F | |
289 bra restart_set_modes_and_flags3 | |
290 ; CC Mode | |
291 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
292 call enable_ir ; Enable IR-Port | |
293 return | |
294 | |
295 restart_set_modes_and_flags3: | |
296 decfsz lo,F | |
297 bra restart_set_modes_and_flags4 | |
298 ; Gauge Mode | |
299 bsf FLAG_gauge_mode ; =1: In Gauge mode | |
300 return | |
301 | |
302 restart_set_modes_and_flags4: | |
303 ; Apnea Mode | |
304 bsf FLAG_apnoe_mode | |
305 return ; start in Surfacemode | |
306 | |
307 END |