diff 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
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/isr.asm	Fri May 20 00:39:05 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/isr.asm	Fri May 20 00:48:30 2011 +0200
@@ -28,7 +28,24 @@
 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
 
 ;=============================================================================
+; Copy a 16bit value from ISR modified registers to main registers.
+; 
+; Because the ISR can happend at any time, the read should be redone if bytes
+; changed inbetween.
+;
+; NOTE: Destination might be in any bank, so be BANK SAFE on b
 
+SAFE_2BYTE_COPY MACRO  a, b
+        local   retry
+retry:
+        movf    a+1,W                   ; High byte in W, (CURRENT BANK ONLY)
+        movff   WREG,b+1                ; and destination.
+        movff   a,b                     ; Copy low byte.
+        xorwf   a+1,W                   ; High byte changed ??? (CURRENT BANK ONLY)
+        bnz     retry
+        ENDM
+
+;=============================================================================
 uartint:
 		btfsc	simulatormode_active		; are we in simulatormode?
 		bra		simulator_int				; Yes, reading is depth in m!
@@ -179,6 +196,10 @@
 ;       is done on private variables, to avoid trashing data while reading it
 ;       from the main code.
 ;
+; NOTE: Because there is no atomic 16bits load/stores, we need to check twice
+;       the read data is correct. Ie. SAFE_2BYTE_COPY is mandatory to get
+;       amb_pressure, temperaturen or rel_pressure
+;
 sensor_int:
 		btfsc		no_sensor_int			; No sensor interrupt (because it's addressed during sleep)
 		return