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;
|
||||
#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);
|
||||
|
|
Loading…
Reference in a new issue