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
|
275
|
12 #include "hwos.inc" ; Mandatory header
|
0
|
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
|
275
|
29 extern init_ostc
|
0
|
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
|
275
|
53 call init_ostc
|
0
|
54 bsf no_sensor_int ; disable sensor interrupt
|
|
55
|
|
56 ; Air pressure compensation after reset
|
|
57 call get_calibration_data ; Get calibration data from pressure sensor
|
|
58 banksel common ; get_calibration_data uses isr_backup
|
|
59 bcf no_sensor_int ; normal sensor interrupt mode
|
|
60
|
10
|
61 call TFT_DisplayOff ; display off
|
|
62 bsf LEDr ; Status LED
|
0
|
63 bcf pressure_refresh
|
|
64 ; First pass will not have valid temperature!
|
|
65 btfss pressure_refresh ; Air pressure compensation
|
|
66 bra $-2
|
50
|
67 bcf LEDr
|
0
|
68 ; Second pass
|
|
69 bcf pressure_refresh
|
|
70 btfss pressure_refresh ; Air pressure compensation
|
|
71 bra $-2
|
|
72
|
|
73 clrf rel_pressure+0
|
|
74 clrf rel_pressure+1
|
|
75 clrf surface_interval+0
|
|
76 clrf surface_interval+1
|
|
77
|
|
78 SAFE_2BYTE_COPY amb_pressure, last_surfpressure
|
|
79
|
|
80 movlw LOW max_surfpressure
|
|
81 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar
|
|
82 movlw HIGH max_surfpressure
|
|
83 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar
|
|
84 movff last_surfpressure+0,sub_b+0
|
|
85 movff last_surfpressure+1,sub_b+1
|
|
86 call subU16 ; sub_c = sub_a - sub_b
|
|
87 btfss neg_flag ; Is 1080mbar < amb_pressure ?
|
|
88 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok!
|
|
89
|
|
90 ; not ok! Overwrite with max. "allowed" airpressure
|
|
91 movlw LOW max_surfpressure
|
|
92 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar
|
|
93 movlw HIGH max_surfpressure
|
|
94 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar
|
|
95
|
|
96 start_copy_pressure:
|
|
97 movff last_surfpressure+0,last_surfpressure_15min+0
|
|
98 movff last_surfpressure+1,last_surfpressure_15min+1
|
|
99 movff last_surfpressure+0,last_surfpressure_30min+0
|
|
100 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers
|
|
101
|
|
102 ; reset deco data for surface mode
|
|
103 movlw d'79'
|
|
104 movff WREG,char_I_N2_ratio ; 79% N2
|
|
105 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine
|
|
106 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine
|
|
107 movff int_I_pres_respiration+1,int_I_pres_surface+1
|
|
108
|
|
109 extern deco_reset
|
|
110 call deco_reset
|
133
|
111
|
|
112 call rtc_init ; init clock
|
|
113
|
|
114 movlw HIGH .512 ; =2
|
|
115 movwf EEADRH
|
|
116 read_int_eeprom .0
|
|
117 clrf EEADRH
|
|
118 movlw 0xAA
|
|
119 cpfseq EEDATA ; =0xAA
|
|
120 bra no_deco_restore ; No
|
|
121
|
|
122 extern restore_decodata_from_eeprom
|
|
123 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom
|
|
124
|
|
125 no_deco_restore:
|
|
126 call deco_calc_desaturation_time ; calculate desaturation time
|
|
127 banksel common
|
|
128 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode
|
|
129 banksel common
|
0
|
130 bcf menubit ; clear menu flag
|
215
|
131
|
0
|
132 ; Check for Power-on reset here
|
215
|
133 extern new_battery_menu,use_old_batteries
|
|
134 ; *****************************************************************************
|
|
135 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return"
|
|
136 ; *****************************************************************************
|
0
|
137
|
|
138 btfsc RCON,POR ; Was this a power-on reset?
|
|
139 goto use_old_batteries ; No, load last stored battery values
|
|
140
|
215
|
141 call lt2942_get_status ; Check for gauge IC
|
235
|
142 btfsc rechargeable ; cR hardware?
|
215
|
143 goto use_old_batteries ; Yes, load last stored battery values
|
|
144
|
|
145 ; No, cR and we have a power-on reset
|
0
|
146 goto new_battery_menu ; show "New battery dialog"
|
|
147
|
|
148 global power_on_return
|
|
149 power_on_return:
|
|
150 bsf RCON,POR ; Set bit for next detection
|
|
151
|
|
152 ; check firmware and reset Custom Functions after an update
|
|
153 movlw d'1'
|
281
|
154 movwf EEADR ; =1
|
|
155 movwf EEADRH ; =1
|
0
|
156 call read_eeprom ; read current version x
|
|
157 movff EEDATA,temp1
|
|
158 incf EEADR,F ; set to 0x102
|
|
159 call read_eeprom ; read current version y
|
|
160 movff EEDATA,temp2
|
|
161 clrf EEADRH ; Reset EEADRH
|
|
162
|
|
163 movlw softwareversion_x
|
|
164 cpfseq temp1 ; compare version x
|
|
165 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
166
|
|
167 movlw softwareversion_y
|
|
168 cpfseq temp2 ; compare version y
|
|
169 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
|
|
170 bra restart ; x and y are equal -> do not reset cf
|
|
171
|
|
172 check_firmware_new:
|
|
173 call TFT_boot ; Initialize TFT (includes clear screen)
|
|
174 clrf CCPR1L ; Backlight off
|
|
175 WIN_TOP .50
|
|
176 WIN_LEFT .10
|
|
177 movlw LOW 0x1E000
|
|
178 movwf TBLPTRL
|
|
179 movlw HIGH 0x1E000
|
|
180 movwf TBLPTRH
|
|
181 movlw UPPER 0x1E000
|
|
182 movwf TBLPTRU
|
|
183 extern color_image
|
|
184 call color_image ; Show logo
|
|
185 call TFT_standard_color
|
|
186 WIN_SMALL .10,.100
|
52
|
187 STRCPY_TEXT_PRINT tNewFirmware1 ; "Update successfull!"
|
0
|
188 WIN_SMALL .10,.140
|
|
189 STRCPY_TEXT tNewFirmware2 ; "New Firmware: "
|
|
190 movlw softwareversion_x
|
|
191 movwf lo
|
|
192 bsf leftbind
|
|
193 output_8
|
|
194 PUTC "."
|
|
195 movlw softwareversion_y
|
|
196 movwf lo
|
45
|
197 output_99x
|
0
|
198 bcf leftbind
|
|
199 STRCAT_PRINT "" ; Print second row
|
|
200 call TFT_Display_FadeIn ; Display resulting surface screen.
|
|
201
|
|
202 ; place "after-update reset" here...
|
93
|
203
|
|
204 extern oPressureAdjust, option_reset, option_save
|
|
205 lfsr FSR0,oPressureAdjust
|
|
206 call option_reset ; Reset FSR0 option to factory default.
|
|
207 lfsr FSR0,oPressureAdjust
|
|
208 call option_save ; Save in EEPROM
|
|
209
|
281
|
210 call fix_180_dives ; fix dives made with the 1.80
|
|
211
|
0
|
212 movlw d'1' ; store current version in EEPROM
|
281
|
213 movwf EEADR ; =1
|
|
214 movwf EEADRH ; =1
|
0
|
215 movlw softwareversion_x
|
|
216 movwf EEDATA
|
|
217 call write_eeprom ; write version x
|
|
218 incf EEADR,F ; set to 0x102
|
|
219 movlw softwareversion_y
|
|
220 movwf EEDATA
|
|
221 call write_eeprom ; write version y
|
|
222 clrf EEADRH ; Reset EEADRH
|
|
223
|
|
224 movlw .7
|
|
225 movwf lo
|
|
226 check_firmware_new2:
|
|
227 ; Wait 1 second
|
|
228 bcf onesecupdate
|
|
229 btfss onesecupdate
|
|
230 bra $-2
|
|
231 decfsz lo,F ; Wait 10 seconds...
|
|
232 bra check_firmware_new2
|
|
233
|
|
234 global restart
|
|
235 restart:
|
|
236 clrf STKPTR ; Never return from here
|
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
diff
changeset
|
237 clrf CCP1CON ; stop PWM
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
diff
changeset
|
238 bcf PORTC,2 ; Pull PWM out to GND
|
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
diff
changeset
|
239
|
21
|
240 extern option_save_all, option_check_all
|
|
241
|
0
|
242 btfsc menubit ; Return from Menu/COMM mode or timeout?
|
|
243 call option_save_all ; Yes, save all settings into EEPROM
|
|
244
|
220
|
245 call option_restore_all ; Restore everything from EEPROM
|
23
|
246 call option_check_all ; Check all options (and reset if not within their min/max boundaries)
|
220
|
247 call option_save_all ; Save all settings into EEPROM after they have been checked
|
23
|
248
|
0
|
249 clrf flag1 ; clear all flags
|
|
250 clrf flag2
|
|
251 clrf flag3
|
|
252 clrf flag4
|
|
253 clrf flag5
|
|
254 clrf flag6
|
|
255 clrf flag7
|
|
256 clrf flag8
|
16
|
257 clrf flag9
|
113
|
258 clrf flag10
|
267
|
259 ; Do not clear flag11 (Sensor calibration and charger status)
|
255
|
260 clrf flag12
|
235
|
261 clrf hardware_flag ; hardware descriptor flag
|
|
262 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor!
|
23
|
263
|
236
|
264 ; configure hardware_flag byte
|
|
265
|
|
266 bsf ambient_sensor ; Clear flag
|
|
267 bsf optical_input ; Clear flag
|
|
268
|
113
|
269 call lt2942_get_status ; Check for gauge IC
|
236
|
270 btfss rechargeable ; cR hardware?
|
|
271 bra restart2 ; No
|
|
272
|
113
|
273 call lt2942_init ; Yes, init battery gauge IC
|
236
|
274 bcf ambient_sensor ; Clear flag
|
|
275 bcf optical_input ; Clear flag
|
248
|
276
|
243
|
277 restart2:
|
|
278 btfsc vusb_in
|
|
279 bra restart3 ; USB (and powered on)
|
|
280 bcf PORTE,0 ; Start comms
|
|
281 WAITMS d'1'
|
|
282 btfss vusb_in
|
|
283 bra restart3 ; USB (and powered off)
|
|
284 bsf ble_available ; ble available
|
|
285 restart3:
|
|
286 bsf PORTE,0 ; Stop comms
|
248
|
287 btfsc ble_available ; ble available?
|
|
288 bra restart4 ; Yes, can't be a cR
|
|
289 btfss rechargeable ; Rechargeable
|
|
290 bra restart4 ; No, can't be a cR
|
|
291 bsf analog_o2_input ; Set flag for analog
|
249
|
292 restart4:
|
|
293 ; The hardware_flag is now:
|
|
294 ; 3: 0x0A
|
|
295 ; cR: 0x05
|
|
296 ; 2 with BLE: 0x11
|
|
297 ; 3 with BLE: 0x1A
|
113
|
298
|
0
|
299 ; Select high altitude (Fly) mode?
|
|
300 movff last_surfpressure_30min+0,sub_b+0
|
|
301 movff last_surfpressure_30min+1,sub_b+1
|
|
302 movlw HIGH high_altitude_threshold
|
|
303 movwf sub_a+1
|
|
304 movlw LOW high_altitude_threshold ; Hard-wired 880mbar
|
|
305 movwf sub_a+0
|
|
306 call subU16 ; sub_c = sub_a - sub_b
|
|
307 btfss neg_flag ; Result negative (Ambient>880mbar)?
|
|
308 bsf high_altitude_mode ; No, Set Flag!
|
|
309
|
236
|
310 btfss analog_o2_input
|
165
|
311 bsf TRISB,3
|
235
|
312 btfss rechargeable
|
165
|
313 bsf TRISG,0
|
0
|
314 call ext_flash_disable_protection ; Disable write protection for external flash
|
|
315
|
155
|
316 bsf flip_screen ; Flip 180°
|
|
317 TSTOSS opt_flip_screen ; =1: Flip the screen
|
|
318 bcf flip_screen ; Normal orientation
|
151
|
319
|
0
|
320 goto surfloop ; Jump to Surfaceloop!
|
|
321
|
|
322 ;=============================================================================
|
|
323 ; Setup all flags and parameters for divemode and simulator computations.
|
|
324 ;
|
|
325 global restart_set_modes_and_flags
|
|
326 restart_set_modes_and_flags: ; "Call"ed from divemode, as well!
|
|
327 call option_restore_all ; Restore everything from EEPROM
|
24
|
328
|
|
329 ; Setup sampling rate
|
|
330 movlw .2
|
|
331 movwf samplingrate
|
|
332 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s
|
|
333 bra restart_set_modes_and_flags1
|
|
334 movlw .10
|
|
335 movwf samplingrate
|
|
336 restart_set_modes_and_flags1:
|
0
|
337 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea
|
|
338
|
|
339 bcf FLAG_apnoe_mode
|
|
340 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
|
341 bcf FLAG_gauge_mode ; =1: In Gauge mode
|
224
|
342 call disable_ir_s8 ; IR off
|
0
|
343
|
|
344 tstfsz lo
|
|
345 bra restart_set_modes_and_flags2
|
|
346 ; OC Mode
|
|
347 return
|
|
348
|
|
349 restart_set_modes_and_flags2:
|
|
350 decfsz lo,F
|
|
351 bra restart_set_modes_and_flags3
|
|
352 ; CC Mode
|
|
353 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
|
187
|
354 call enable_ir_s8 ; Enable IR/S8-Port
|
0
|
355 return
|
|
356
|
|
357 restart_set_modes_and_flags3:
|
|
358 decfsz lo,F
|
|
359 bra restart_set_modes_and_flags4
|
|
360 ; Gauge Mode
|
|
361 bsf FLAG_gauge_mode ; =1: In Gauge mode
|
|
362 return
|
|
363
|
|
364 restart_set_modes_and_flags4:
|
|
365 ; Apnea Mode
|
|
366 bsf FLAG_apnoe_mode
|
|
367 return ; start in Surfacemode
|
|
368
|
|
369 END |