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
|
|
62 bcf pressure_refresh
|
|
63 ; First pass will not have valid temperature!
|
|
64 btfss pressure_refresh ; Air pressure compensation
|
|
65 bra $-2
|
|
66 ; Second pass
|
|
67 bcf pressure_refresh
|
|
68 btfss pressure_refresh ; Air pressure compensation
|
|
69 bra $-2
|
|
70
|
|
71 clrf rel_pressure+0
|
|
72 clrf rel_pressure+1
|
|
73 clrf surface_interval+0
|
|
74 clrf surface_interval+1
|
|
75
|
|
76 SAFE_2BYTE_COPY amb_pressure, last_surfpressure
|
|
77
|
|
78 movlw LOW max_surfpressure
|
|
79 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar
|
|
80 movlw HIGH max_surfpressure
|
|
81 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar
|
|
82 movff last_surfpressure+0,sub_b+0
|
|
83 movff last_surfpressure+1,sub_b+1
|
|
84 call subU16 ; sub_c = sub_a - sub_b
|
|
85 btfss neg_flag ; Is 1080mbar < amb_pressure ?
|
|
86 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok!
|
|
87
|
|
88 ; not ok! Overwrite with max. "allowed" airpressure
|
|
89 movlw LOW max_surfpressure
|
|
90 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar
|
|
91 movlw HIGH max_surfpressure
|
|
92 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar
|
|
93
|
|
94 start_copy_pressure:
|
|
95 movff last_surfpressure+0,last_surfpressure_15min+0
|
|
96 movff last_surfpressure+1,last_surfpressure_15min+1
|
|
97 movff last_surfpressure+0,last_surfpressure_30min+0
|
|
98 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers
|
|
99
|
|
100 ; reset deco data for surface mode
|
|
101 movlw d'79'
|
|
102 movff WREG,char_I_N2_ratio ; 79% N2
|
|
103 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine
|
|
104 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine
|
|
105 movff int_I_pres_respiration+1,int_I_pres_surface+1
|
|
106
|
|
107 extern deco_reset
|
|
108 call deco_reset
|
|
109 call deco_calc_desaturation_time ; calculate desaturation time
|
|
110 banksel common
|
|
111 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode
|
|
112 banksel common
|
|
113 clrf nofly_time+0 ; Reset NoFly
|
|
114 clrf nofly_time+1
|
|
115 clrf desaturation_time+0 ; Reset Desat
|
|
116 clrf desaturation_time+1
|
|
117 bcf menubit ; clear menu flag
|
|
118 ; Check for Power-on reset here
|
|
119 extern new_battery_menu
|
|
120 extern use_old_batteries
|
|
121
|
|
122 btfsc RCON,POR ; Was this a power-on reset?
|
|
123 goto use_old_batteries ; No, load last stored battery values
|
|
124 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return"
|
|
125
|
|
126 ; Yes
|
|
127 call rtc_init ; init clock
|
|
128 goto new_battery_menu ; show "New battery dialog"
|
|
129 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return"
|
|
130
|
|
131 global power_on_return
|
|
132 power_on_return:
|
|
133 bsf RCON,POR ; Set bit for next detection
|
|
134
|
|
135 ; check firmware and reset Custom Functions after an update
|
|
136 movlw d'1'
|
|
137 movwf EEADR
|
|
138 movlw d'1'
|
|
139 movwf EEADRH
|
|
140 call read_eeprom ; read current version x
|
|
141 movff EEDATA,temp1
|
|
142 incf EEADR,F ; set to 0x102
|
|
143 call read_eeprom ; read current version y
|
|
144 movff EEDATA,temp2
|
|
145 clrf EEADRH ; Reset EEADRH
|
|
146
|
|
147 movlw softwareversion_x
|
|
148 cpfseq temp1 ; compare version x
|
|
149 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
150
|
|
151 movlw softwareversion_y
|
|
152 cpfseq temp2 ; compare version y
|
|
153 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
154 bra restart ; x and y are equal -> do not reset cf
|
|
155
|
|
156 check_firmware_new:
|
|
157 call speed_normal
|
|
158 call TFT_boot ; Initialize TFT (includes clear screen)
|
|
159 clrf CCPR1L ; Backlight off
|
|
160 WIN_TOP .50
|
|
161 WIN_LEFT .10
|
|
162 movlw LOW 0x1E000
|
|
163 movwf TBLPTRL
|
|
164 movlw HIGH 0x1E000
|
|
165 movwf TBLPTRH
|
|
166 movlw UPPER 0x1E000
|
|
167 movwf TBLPTRU
|
|
168 extern color_image
|
|
169 call color_image ; Show logo
|
|
170 call TFT_standard_color
|
|
171 WIN_SMALL .10,.100
|
|
172 STRCPY_TEXT_PRINT tNewFirmware1 ; "Update sucessfull!"
|
|
173 WIN_SMALL .10,.140
|
|
174 STRCPY_TEXT tNewFirmware2 ; "New Firmware: "
|
|
175 movlw softwareversion_x
|
|
176 movwf lo
|
|
177 bsf leftbind
|
|
178 output_8
|
|
179 PUTC "."
|
|
180 movlw softwareversion_y
|
|
181 movwf lo
|
|
182 output_8
|
|
183 bcf leftbind
|
|
184 STRCAT_PRINT "" ; Print second row
|
|
185 call TFT_Display_FadeIn ; Display resulting surface screen.
|
|
186
|
|
187 ; place "after-update reset" here...
|
|
188 movlw d'1' ; store current version in EEPROM
|
|
189 movwf EEADR
|
|
190 movlw d'1'
|
|
191 movwf EEADRH
|
|
192 movlw softwareversion_x
|
|
193 movwf EEDATA
|
|
194 call write_eeprom ; write version x
|
|
195 incf EEADR,F ; set to 0x102
|
|
196 movlw softwareversion_y
|
|
197 movwf EEDATA
|
|
198 call write_eeprom ; write version y
|
|
199 clrf EEADRH ; Reset EEADRH
|
|
200
|
|
201 movlw .7
|
|
202 movwf lo
|
|
203 check_firmware_new2:
|
|
204 ; Wait 1 second
|
|
205 bcf onesecupdate
|
|
206 btfss onesecupdate
|
|
207 bra $-2
|
|
208 decfsz lo,F ; Wait 10 seconds...
|
|
209 bra check_firmware_new2
|
|
210
|
|
211 global restart
|
|
212 restart:
|
|
213 clrf STKPTR ; Never return from here
|
|
214 extern option_save_all
|
|
215 btfsc menubit ; Return from Menu/COMM mode or timeout?
|
|
216 call option_save_all ; Yes, save all settings into EEPROM
|
|
217
|
|
218 clrf flag1 ; clear all flags
|
|
219 clrf flag2
|
|
220 clrf flag3
|
|
221 clrf flag4
|
|
222 clrf flag5
|
|
223 clrf flag6
|
|
224 clrf flag7
|
|
225 clrf flag8
|
|
226 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor!
|
|
227 ; Select high altitude (Fly) mode?
|
|
228 movff last_surfpressure_30min+0,sub_b+0
|
|
229 movff last_surfpressure_30min+1,sub_b+1
|
|
230 movlw HIGH high_altitude_threshold
|
|
231 movwf sub_a+1
|
|
232 movlw LOW high_altitude_threshold ; Hard-wired 880mbar
|
|
233 movwf sub_a+0
|
|
234 call subU16 ; sub_c = sub_a - sub_b
|
|
235 btfss neg_flag ; Result negative (Ambient>880mbar)?
|
|
236 bsf high_altitude_mode ; No, Set Flag!
|
|
237
|
|
238 call ext_flash_disable_protection ; Disable write protection for external flash
|
|
239
|
|
240 extern testloop
|
|
241 ; goto testloop
|
|
242
|
|
243 goto surfloop ; Jump to Surfaceloop!
|
|
244
|
|
245 ;=============================================================================
|
|
246 ; Setup all flags and parameters for divemode and simulator computations.
|
|
247 ;
|
|
248 global restart_set_modes_and_flags
|
|
249 restart_set_modes_and_flags: ; "Call"ed from divemode, as well!
|
|
250 call option_restore_all ; Restore everything from EEPROM
|
|
251 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea
|
|
252
|
|
253 bcf FLAG_apnoe_mode
|
|
254 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
|
255 bcf FLAG_gauge_mode ; =1: In Gauge mode
|
|
256 call disable_ir ; IR off
|
|
257
|
|
258 tstfsz lo
|
|
259 bra restart_set_modes_and_flags2
|
|
260 ; OC Mode
|
|
261 return
|
|
262
|
|
263 restart_set_modes_and_flags2:
|
|
264 decfsz lo,F
|
|
265 bra restart_set_modes_and_flags3
|
|
266 ; CC Mode
|
|
267 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
|
268 call enable_ir ; Enable IR-Port
|
|
269 return
|
|
270
|
|
271 restart_set_modes_and_flags3:
|
|
272 decfsz lo,F
|
|
273 bra restart_set_modes_and_flags4
|
|
274 ; Gauge Mode
|
|
275 bsf FLAG_gauge_mode ; =1: In Gauge mode
|
|
276 return
|
|
277
|
|
278 restart_set_modes_and_flags4:
|
|
279 ; Apnea Mode
|
|
280 bsf FLAG_apnoe_mode
|
|
281 return ; start in Surfacemode
|
|
282
|
|
283 END |