annotate src/start.asm @ 9:150d07db6048

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