Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/isr.asm @ 341:2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
author | JeanDo |
---|---|
date | Fri, 20 May 2011 00:48:30 +0200 |
parents | ecbbbd423e86 |
children | d5240792be51 |
comparison
equal
deleted
inserted
replaced
340:ecbbbd423e86 | 341:2144f19fa1eb |
---|---|
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 ;============================================================================= | 30 ;============================================================================= |
31 | 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 ; NOTE: Destination might be in any bank, so be BANK SAFE on b | |
37 | |
38 SAFE_2BYTE_COPY MACRO a, b | |
39 local retry | |
40 retry: | |
41 movf a+1,W ; High byte in W, (CURRENT BANK ONLY) | |
42 movff WREG,b+1 ; and destination. | |
43 movff a,b ; Copy low byte. | |
44 xorwf a+1,W ; High byte changed ??? (CURRENT BANK ONLY) | |
45 bnz retry | |
46 ENDM | |
47 | |
48 ;============================================================================= | |
32 uartint: | 49 uartint: |
33 btfsc simulatormode_active ; are we in simulatormode? | 50 btfsc simulatormode_active ; are we in simulatormode? |
34 bra simulator_int ; Yes, reading is depth in m! | 51 bra simulator_int ; Yes, reading is depth in m! |
35 | 52 |
36 movff RCREG,uart1_temp | 53 movff RCREG,uart1_temp |
177 ; | 194 ; |
178 ; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet) | 195 ; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet) |
179 ; is done on private variables, to avoid trashing data while reading it | 196 ; is done on private variables, to avoid trashing data while reading it |
180 ; from the main code. | 197 ; from the main code. |
181 ; | 198 ; |
199 ; NOTE: Because there is no atomic 16bits load/stores, we need to check twice | |
200 ; the read data is correct. Ie. SAFE_2BYTE_COPY is mandatory to get | |
201 ; amb_pressure, temperaturen or rel_pressure | |
202 ; | |
182 sensor_int: | 203 sensor_int: |
183 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) | 204 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) |
184 return | 205 return |
185 | 206 |
186 incf timer1int_counter2,F ; counts to eight for state maschine | 207 incf timer1int_counter2,F ; counts to eight for state maschine |