fix uart.c to work with UART_TX_BUF_SIZE == 1
This commit is contained in:
parent
13dccb0380
commit
329935eca8
|
@ -42,8 +42,8 @@
|
||||||
struct spinlock uart_tx_lock;
|
struct spinlock uart_tx_lock;
|
||||||
#define UART_TX_BUF_SIZE 32
|
#define UART_TX_BUF_SIZE 32
|
||||||
char uart_tx_buf[UART_TX_BUF_SIZE];
|
char uart_tx_buf[UART_TX_BUF_SIZE];
|
||||||
int uart_tx_w; // write next to uart_tx_buf[uart_tx_w++]
|
uint64 uart_tx_w; // write next to uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE]
|
||||||
int uart_tx_r; // read next from uart_tx_buf[uar_tx_r++]
|
uint64 uart_tx_r; // read next from uart_tx_buf[uar_tx_r % UART_TX_BUF_SIZE]
|
||||||
|
|
||||||
extern volatile int panicked; // from printf.c
|
extern volatile int panicked; // from printf.c
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ uartputc(int c)
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1){
|
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.
|
// buffer is full.
|
||||||
// wait for uartstart() to open up space in the buffer.
|
// wait for uartstart() to open up space in the buffer.
|
||||||
sleep(&uart_tx_r, &uart_tx_lock);
|
sleep(&uart_tx_r, &uart_tx_lock);
|
||||||
} else {
|
} else {
|
||||||
uart_tx_buf[uart_tx_w] = c;
|
uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE] = c;
|
||||||
uart_tx_w = (uart_tx_w + 1) % UART_TX_BUF_SIZE;
|
uart_tx_w += 1;
|
||||||
uartstart();
|
uartstart();
|
||||||
release(&uart_tx_lock);
|
release(&uart_tx_lock);
|
||||||
return;
|
return;
|
||||||
|
@ -150,8 +150,8 @@ uartstart()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = uart_tx_buf[uart_tx_r];
|
int c = uart_tx_buf[uart_tx_r % UART_TX_BUF_SIZE];
|
||||||
uart_tx_r = (uart_tx_r + 1) % UART_TX_BUF_SIZE;
|
uart_tx_r += 1;
|
||||||
|
|
||||||
// maybe uartputc() is waiting for space in the buffer.
|
// maybe uartputc() is waiting for space in the buffer.
|
||||||
wakeup(&uart_tx_r);
|
wakeup(&uart_tx_r);
|
||||||
|
|
Loading…
Reference in a new issue