Explorar el Código

fmrx: more careful handling of the receive timeout interrupt

H. Peter Anvin hace 3 años
padre
commit
e83a79270f
Se han modificado 1 ficheros con 6 adiciones y 4 borrados
  1. 6 4
      USBCAS/fmrx.c

+ 6 - 4
USBCAS/fmrx.c

@@ -33,7 +33,7 @@ void fmrx_init(void)
 	TCCR1A = 0;
 
 	/* Enable interrupts on input capture */
-	TIFR1 = TIMSK1 = (1 << ICIE1);
+	TIFR1 = TIMSK1 = 1 << ICIE1;
 
 	/* Clear timer counter */
 	TCNT1 = 0;
@@ -61,12 +61,12 @@ static bool started;
 static inline void enable_timeout(uint16_t when)
 {
 	OCR1A = when;
-	TIFR1 = TIMSK1 = (1 << ICIE1) | (1 << OCIE1A);
+	TIMSK1 = TIFR1 = (1 << ICIE1) | (1 << OCIE1A);
 }
 
 static inline void disable_timeout(void)
 {
-	TIMSK1 = (1 << ICIE1);
+	TIFR1 = TIMSK1 = (1 << ICIE1);
 }
 
 void fmrx_set_speed(uint32_t baudrate)
@@ -79,6 +79,8 @@ void fmrx_set_speed(uint32_t baudrate)
 		prescale++;	/* Prescale by 8 */
 	}
 
+	TCCR1B &= ~7;		/* Stop timer */
+
 	one_bit_lo      = F_CPU / (4 * baudrate);
 	one_bit_hi      =  3 * one_bit_lo;
 	one_bit_timeout = 16 * one_bit_lo; /* 4 total bit times... */
@@ -88,7 +90,7 @@ void fmrx_set_speed(uint32_t baudrate)
 	bits = bytes = 0;
 	last_edge = TCNT1;
 
-	TCCR1B = (TCCR1B & ~7) | prescale;
+	TCCR1B |= prescale;	/* Start timer */
 }
 
 /* We "hunt" for a block until we find this bit pattern; same as ABC800 */