summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-10-20 07:02:44 -0400
committerFrans Kaashoek <[email protected]>2020-11-05 06:56:51 -0500
commit329935eca8484d7f1d34c1d43b16c495d861ad75 (patch)
tree6046ab78839b6f4af841d74afd4284d106aac011
parent13dccb0380d3c694083095040fadd03bfe4f598c (diff)
downloadxv6-labs-329935eca8484d7f1d34c1d43b16c495d861ad75.tar.gz
xv6-labs-329935eca8484d7f1d34c1d43b16c495d861ad75.tar.bz2
xv6-labs-329935eca8484d7f1d34c1d43b16c495d861ad75.zip
fix uart.c to work with UART_TX_BUF_SIZE == 1
-rw-r--r--kernel/uart.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/kernel/uart.c b/kernel/uart.c
index d586ea4..3c1dc34 100644
--- a/kernel/uart.c
+++ b/kernel/uart.c
@@ -42,8 +42,8 @@
struct spinlock uart_tx_lock;
#define UART_TX_BUF_SIZE 32
char uart_tx_buf[UART_TX_BUF_SIZE];
-int uart_tx_w; // write next to uart_tx_buf[uart_tx_w++]
-int uart_tx_r; // read next from uart_tx_buf[uar_tx_r++]
+uint64 uart_tx_w; // write next to uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE]
+uint64 uart_tx_r; // read next from uart_tx_buf[uar_tx_r % UART_TX_BUF_SIZE]
extern volatile int panicked; // from printf.c
@@ -94,13 +94,13 @@ uartputc(int c)
}
while(1){
- if(((uart_tx_w + 1) % UART_TX_BUF_SIZE) == uart_tx_r){
+ if(uart_tx_w == uart_tx_r + UART_TX_BUF_SIZE){
// buffer is full.
// wait for uartstart() to open up space in the buffer.
sleep(&uart_tx_r, &uart_tx_lock);
} else {
- uart_tx_buf[uart_tx_w] = c;
- uart_tx_w = (uart_tx_w + 1) % UART_TX_BUF_SIZE;
+ uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE] = c;
+ uart_tx_w += 1;
uartstart();
release(&uart_tx_lock);
return;
@@ -150,8 +150,8 @@ uartstart()
return;
}
- int c = uart_tx_buf[uart_tx_r];
- uart_tx_r = (uart_tx_r + 1) % UART_TX_BUF_SIZE;
+ int c = uart_tx_buf[uart_tx_r % UART_TX_BUF_SIZE];
+ uart_tx_r += 1;
// maybe uartputc() is waiting for space in the buffer.
wakeup(&uart_tx_r);