comparison code_part1/OSTC_code_asm_part1/altimeter.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 8a0bbe43df65
children 797e2ac42d24
comparison
equal deleted inserted replaced
340:ecbbbd423e86 341:2144f19fa1eb
53 movlb HIGH(pressureAvg) ; Altimeter data in bank 0. 53 movlb HIGH(pressureAvg) ; Altimeter data in bank 0.
54 clrf pressureSum+0 ; Init averaging area 54 clrf pressureSum+0 ; Init averaging area
55 clrf pressureSum+1 55 clrf pressureSum+1
56 clrf pressureCount 56 clrf pressureCount
57 57
58 movff amb_pressure+0,pressureAvg+0 ; And init first average. 58 SAFE_2BYTE_COPY amb_pressure, pressureAvg ; And init first average.
59 movff amb_pressure+1,pressureAvg+1
60 59
61 movlw 4 ; And multiply AVG by 16 to be coherent. 60 movlw 4 ; And multiply AVG by 16 to be coherent.
62 altimeter_reset_1: 61 altimeter_reset_1:
63 bcf STATUS,C 62 bcf STATUS,C
64 rlcf pressureAvg+0 63 rlcf pressureAvg+0
71 movlb 1 ; Back to normal bank1. 70 movlb 1 ; Back to normal bank1.
72 return 71 return
73 72
74 altimeter_1: 73 altimeter_1:
75 ;---- Do a bank-safe 16bit summing ----------------------------------- 74 ;---- Do a bank-safe 16bit summing -----------------------------------
76 movff amb_pressure+0,WREG 75 SAFE_2BYTE_COPY amb_pressure, lo ; And init first average.
76
77 movff lo,WREG
77 addwf pressureSum+0,F 78 addwf pressureSum+0,F
78 movff amb_pressure+1,WREG 79 movff hi,WREG
79 addwfc pressureSum+1,F 80 addwfc pressureSum+1,F
80 81
81 incf pressureCount ; Increment count too. 82 incf pressureCount ; Increment count too.
82 movlw .32 ; Already 32 done ? 83 movlw .32 ; Already 32 done ?
83 subwf pressureCount,W 84 subwf pressureCount,W