浏览代码

uart1: don't enable interrupts when called from interrupt context

k4be 2 年之前
父节点
当前提交
2c467fc09c
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      soft/uart1.c

+ 10 - 4
soft/uart1.c

@@ -78,16 +78,19 @@ uint8_t uart1_get (void)
 {
 	uint8_t d;
 	idx_t i;
+	unsigned char SREG_buf = SREG;
 
 
 	do {
-		cli(); i = RxFifo.ct; sei();
+		cli();
+		i = RxFifo.ct;
+		SREG = SREG_buf;
 	} while (i == 0) ;
 	i = RxFifo.ri;
 	d = RxFifo.buff[i];
 	cli();
 	RxFifo.ct--;
-	sei();
+	SREG = SREG_buf;
 	RxFifo.ri = (i + 1) % sizeof RxFifo.buff;
 
 	return d;
@@ -101,9 +104,12 @@ void uart1_put (uint8_t d)
 {
 #if USE_TXINT
 	idx_t i;
+	unsigned char SREG_buf = SREG;
 
 	do {
-		cli(); i = TxFifo.ct; sei();
+		cli();
+		i = TxFifo.ct;
+		SREG = SREG_buf;
 	} while (i >= sizeof TxFifo.buff);
 	i = TxFifo.wi;
 	TxFifo.buff[i] = d;
@@ -111,7 +117,7 @@ void uart1_put (uint8_t d)
 	cli();
 	TxFifo.ct++;
 	UCSR1B |= _BV(UDRIE1);
-	sei();
+	SREG = SREG_buf;
 #else
 	loop_until_bit_is_set(UCSR1A, UDRE1);
 	UDR1 = d;