comparison code_part1/OSTC_code_asm_part1/isr.asm @ 344:797e2ac42d24 ScreenDump

MERGE with 1.91 main trunk.
author JeanDo
date Sat, 21 May 2011 14:48:07 +0200
parents 447390289f47 d5240792be51
children 8bb7c901743d
comparison
equal deleted inserted replaced
337:6bdf80d7276c 344:797e2ac42d24
25 ; the timer1 module interrupts every 62.5ms (16x/second) 25 ; the timer1 module interrupts every 62.5ms (16x/second)
26 ; temperature and pressure is averaged over 4 measurements 26 ; temperature and pressure is averaged over 4 measurements
27 ; flag pressure_refresh is set every 500ms 27 ; flag pressure_refresh is set every 500ms
28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable) 28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
29 29
30 ;=============================================================================
31 ; Copy a 16bit value from ISR modified registers to main registers.
32 ;
33 ; Because the ISR can happend at any time, the read should be redone if bytes
34 ; changed inbetween.
35 ;
36 ; Trashes: WREG and TABLAT
37 ; NOTE: Destination might be in any bank, so be BANK SAFE.
38 ;
39 SAFE_2BYTE_COPY MACRO from, to
40 local retry
41 retry:
42 movff from+1,WREG ; High byte in W.
43 movff WREG,to+1 ; and destination.
44 movff from+0,to+0 ; Copy low byte.
45 movff from+1,TABLAT ; another bank-safe read.
46 xorwf TABLAT,W ; High byte changed ?
47 bnz retry
48 ENDM
49
50 ;=============================================================================
30 uartint: 51 uartint:
31 btfsc simulatormode_active ; are we in simulatormode? 52 btfsc simulatormode_active ; are we in simulatormode?
32 bra simulator_int ; Yes, reading is depth in m! 53 bra simulator_int ; Yes, reading is depth in m!
33 54
34 movff RCREG,uart1_temp 55 movff RCREG,uart1_temp
62 movlw 0xC1 83 movlw 0xC1
63 cpfseq RCREG ; 115200Baud Bootloader request? 84 cpfseq RCREG ; 115200Baud Bootloader request?
64 bra uartint1 ; No 85 bra uartint1 ; No
65 bsf uart_115200_bootloader ; Yes, set Flag 86 bsf uart_115200_bootloader ; Yes, set Flag
66 87
67
68 uartint1: 88 uartint1:
69 movf RCREG,w ; unload RCREG in stand-alone simulator mode 89 movf RCREG,w ; unload RCREG in stand-alone simulator mode
70 bcf PIR1,RCIF ; Clear flag 90 bcf PIR1,RCIF ; Clear flag
71 bcf RCSTA,CREN ; Clear receiver status 91 bcf RCSTA,CREN ; Clear receiver status
72 bsf RCSTA,CREN 92 bsf RCSTA,CREN
86 mullw d'100' ; result will be mbar 106 mullw d'100' ; result will be mbar
87 movff PRODL,sim_pressure+0 ; stored for pressure overwrite 107 movff PRODL,sim_pressure+0 ; stored for pressure overwrite
88 movff PRODH,sim_pressure+1 108 movff PRODH,sim_pressure+1
89 bra uartint1 ; exit uart int 109 bra uartint1 ; exit uart int
90 110
111 ;=============================================================================
112
91 switch_left_int: 113 switch_left_int:
92 bcf INTCON,INT0IF ; Clear flag 114 bcf INTCON,INT0IF ; Clear flag
93 115
94 btfsc T0CON,TMR0ON ; Timer0 running? 116 btfsc T0CON,TMR0ON ; Timer0 running?
95 bra timer0_restart ; Yes, restart 117 bra timer0_restart ; Yes, restart
133 bcf INTCON,TMR0IF ; Clear flag 155 bcf INTCON,TMR0IF ; Clear flag
134 bcf T0CON,TMR0ON ; Stop Timer 0 156 bcf T0CON,TMR0ON ; Stop Timer 0
135 clrf TMR0H 157 clrf TMR0H
136 clrf TMR0L 158 clrf TMR0L
137 return 159 return
138 160
161 ;=============================================================================
162 ;
163
139 timer1int: 164 timer1int:
140 bcf PIR1,TMR1IF ; Clear flag 165 bcf PIR1,TMR1IF ; Clear flag
141 166
142 timer1int_debug: 167 timer1int_debug:
143 bcf LED_red ; LEDr off (For charge indicator) 168 bcf LED_red ; LEDr off (For charge indicator)
158 183
159 sensor_int_pre: 184 sensor_int_pre:
160 btfsc sleepmode ; In sleepmode? 185 btfsc sleepmode ; In sleepmode?
161 return ; Yes 186 return ; Yes
162 187
188 ; Sensor interput do poll the presure/temperature sensor, download results,
189 ; compute compensations, and store results in various shared variables.
190 ;
191 ; Input: interupt (every 62.5msec == 16Hz), sensor,
192 ; last_surfpressure:2.
193 ;
194 ; Output: amb_pressure:2,
195 ; temperature:2,
196 ; rel_pressure:2,
197 ; and the pressure_refresh flag.
198 ;
199 ; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet)
200 ; is done on private variables, to avoid trashing data while reading it
201 ; from the main code.
202 ;
203 ; NOTE: Because there is no atomic 16bits load/stores, we need to check twice
204 ; the read data is correct. Ie. SAFE_2BYTE_COPY is mandatory to get
205 ; amb_pressure, temperature or rel_pressure
206 ;
163 sensor_int: 207 sensor_int:
164 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) 208 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
165 return 209 return
166 210
167 incf timer1int_counter2,F ; counts to eight for state maschine 211 incf timer1int_counter2,F ; counts to eight for state maschine
193 ; bra sensor_int2_plus_average ; Do State 8 237 ; bra sensor_int2_plus_average ; Do State 8
194 238
195 ;sensor_int2_plus_average: 239 ;sensor_int2_plus_average:
196 rcall sensor_int_state2 240 rcall sensor_int_state2
197 sensor_int2_plus_average2: 241 sensor_int2_plus_average2:
198 bcf STATUS,C 242 bcf STATUS,C ; clear carry bit.
199 rrcf isr3_temp+1 ; isr3_temp / 2 243 rrcf amb_pressure_avg+1 ; amb_pressure sum / 2
200 rrcf isr3_temp+0 244 rrcf amb_pressure_avg+0
201 bcf STATUS,C 245 bcf STATUS,C ; clear carry bit, twice.
202 rrcf temperature_temp+1 ; temperature_temp /2 246 rrcf amb_pressure_avg+1 ; amb_pressure sum / 4
203 rrcf temperature_temp+0 247 rrcf amb_pressure_avg+0
204 248
205 bcf STATUS,C 249 movff amb_pressure_avg+1,amb_pressure+1 ; copy into actual register
206 rrcf isr3_temp+1 ; isr3_temp / 4 250 movff amb_pressure_avg+0,amb_pressure+0
207 rrcf isr3_temp+0 251
208 bcf STATUS,C 252 bcf STATUS,C
209 rrcf temperature_temp+1 ; temperature_temp /4 253 btfsc temperature_avg+1,7 ; Copy sign bit to carry
210 rrcf temperature_temp+0 254 bsf STATUS,C
211 255 rrcf temperature_avg+1 ; Signed temperature /2
212 movff isr3_temp+1,amb_pressure+1 ; copy into actual register 256 rrcf temperature_avg+0
213 movff isr3_temp+0,amb_pressure+0 257
214 258 bcf STATUS,C
215 movff temperature_temp+1,temperature+1 259 btfsc temperature_avg+1,7 ; Copy sign bit to carry
216 movff temperature_temp+0,temperature+0 260 bsf STATUS,C
261 rrcf temperature_avg+1 ; Signed temperature /4
262 rrcf temperature_avg+0
263
264 movff temperature_avg+1,temperature+1
265 movff temperature_avg+0,temperature+0
217 266
218 bsf pressure_refresh ; Set flag! Temp and pressure were updated! 267 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
219 clrf timer1int_counter2 ; Then reset State counter 268 clrf timer1int_counter2 ; Then reset State counter
220 269
221 btfss simulatormode_active ; are we in simulator mode? 270 btfss simulatormode_active ; are we in simulator mode?
226 movwf last_surfpressure+0 275 movwf last_surfpressure+0
227 movlw HIGH d'1000' 276 movlw HIGH d'1000'
228 movwf last_surfpressure+1 277 movwf last_surfpressure+1
229 278
230 comp_air_pressure: 279 comp_air_pressure:
231 bcf neg_flag
232 movf last_surfpressure+0,W ; compensate airpressure 280 movf last_surfpressure+0,W ; compensate airpressure
233 subwf amb_pressure+0,W 281 subwf amb_pressure+0,W
234 movwf rel_pressure+0 ; rel_pressure stores depth! 282 movwf rel_pressure+0 ; rel_pressure stores depth!
235 283
236 movf last_surfpressure+1,W 284 movf last_surfpressure+1,W
240 return 288 return
241 clrf rel_pressure+0 ; Yes, do not display negative depths 289 clrf rel_pressure+0 ; Yes, do not display negative depths
242 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive 290 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
243 return 291 return
244 292
245
246 sensor_int_state1_plus_restart: 293 sensor_int_state1_plus_restart:
247 bcf pressure_refresh ; clear flags 294 ;;; bcf pressure_refresh ; clear flags
248 clrf isr3_temp+0 ; pressure average registers 295 clrf amb_pressure_avg+0 ; pressure average registers
249 clrf isr3_temp+1 296 clrf amb_pressure_avg+1
250 clrf temperature_temp+0 297 clrf temperature_avg+0
251 clrf temperature_temp+1 298 clrf temperature_avg+1
252 299
253 sensor_int_state1: 300 sensor_int_state1:
254 call get_temperature_value ; State 1: Get temperature 301 call get_temperature_value ; State 1: Get temperature
255 call get_pressure_start ; and start pressure integration. 302 call get_pressure_start ; and start pressure integration.
256 return ; Done. 303 return ; Done.
257 304
258 sensor_int_state2: 305 sensor_int_state2:
259 call get_pressure_value ; State2: Get pressure (51us) 306 call get_pressure_value ; State2: Get pressure (51us)
260 call get_temperature_start ; and start temperature integration (73,5us) 307 call get_temperature_start ; and start temperature integration (73,5us)
261 call calculate_compensation ; calculate temperature compensated pressure (233us) 308 goto calculate_compensation ; calculate temperature compensated pressure (233us)
262 movf amb_pressure+0,W 309
263 addwf isr3_temp+0 ; average pressure 310 ;=============================================================================
264 movf amb_pressure+1,W
265 addwfc isr3_temp+1
266 movf temperature+0,W
267 addwf temperature_temp+0 ; average temperature
268 movf temperature+1,W
269 addwfc temperature_temp+1
270 return
271
272 311
273 RTCisr: 312 RTCisr:
274 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms) 313 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
275 bsf onesecupdate ; we have a new second! 314 bsf onesecupdate ; we have a new second!
276 315