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