xv6-simplified 0.1
简化版xv6
Loading...
Searching...
No Matches
Macros | Functions | Variables
uart.c File Reference

uart相关寄存器操作 More...

#include "include/types.h"
#include "include/param.h"
#include "include/memlayout.h"
#include "include/riscv.h"
#include "include/proc.h"
#include "include/defs.h"
Include dependency graph for uart.c:

Macros

#define Reg(reg)   ((volatile unsigned char *)(UART0 + reg))
 
#define RHR   0
 
#define THR   0
 
#define IER   1
 
#define IER_RX_ENABLE   (1<<0)
 
#define IER_TX_ENABLE   (1<<1)
 
#define FCR   2
 
#define FCR_FIFO_ENABLE   (1<<0)
 
#define FCR_FIFO_CLEAR   (3<<1)
 
#define ISR   2
 
#define LCR   3
 
#define LCR_EIGHT_BITS   (3<<0)
 
#define LCR_BAUD_LATCH   (1<<7)
 
#define LSR   5
 
#define LSR_RX_READY   (1<<0)
 
#define LSR_TX_IDLE   (1<<5)
 
#define ReadReg(reg)   (*(Reg(reg)))
 
#define WriteReg(reg, v)   (*(Reg(reg)) = (v))
 
#define UART_TX_BUF_SIZE   32
 

Functions

void uartstart ()
 如果UART空闲且传输缓冲区中有字符等待,将字符输出。
 
void uartinit (void)
 初始化uart各个寄存器
 
void uartputc (int c)
 将字符写入输出缓冲区,通知UART开始发送字符。
 
void uartputc_sync (int c)
 uartputc()的变体,不需要使用中断。
 
int uartgetc (void)
 从UART读入一个输入字符
 
void uartintr (void)
 uart中断处理,当输入数据抵达或uart准备好更多输出时调用,被devintr函数调用。
 

Variables

char uart_tx_buf [UART_TX_BUF_SIZE]
 
uint64 uart_tx_w
 
uint64 uart_tx_r
 
volatile int panicked
 

Detailed Description

uart相关寄存器操作

Date
23.5.3
Author
yrz
Version
0.1 @status Stable

Macro Definition Documentation

◆ FCR

#define FCR   2

◆ FCR_FIFO_CLEAR

#define FCR_FIFO_CLEAR   (3<<1)

◆ FCR_FIFO_ENABLE

#define FCR_FIFO_ENABLE   (1<<0)

◆ IER

#define IER   1

◆ IER_RX_ENABLE

#define IER_RX_ENABLE   (1<<0)

◆ IER_TX_ENABLE

#define IER_TX_ENABLE   (1<<1)

◆ ISR

#define ISR   2

◆ LCR

#define LCR   3

◆ LCR_BAUD_LATCH

#define LCR_BAUD_LATCH   (1<<7)

◆ LCR_EIGHT_BITS

#define LCR_EIGHT_BITS   (3<<0)

◆ LSR

#define LSR   5

◆ LSR_RX_READY

#define LSR_RX_READY   (1<<0)

◆ LSR_TX_IDLE

#define LSR_TX_IDLE   (1<<5)

◆ ReadReg

#define ReadReg (   reg)    (*(Reg(reg)))

◆ Reg

#define Reg (   reg)    ((volatile unsigned char *)(UART0 + reg))

◆ RHR

#define RHR   0

◆ THR

#define THR   0

◆ UART_TX_BUF_SIZE

#define UART_TX_BUF_SIZE   32

◆ WriteReg

#define WriteReg (   reg,
 
)    (*(Reg(reg)) = (v))

Function Documentation

◆ uartgetc()

int uartgetc ( void  )

从UART读入一个输入字符

Returns
若LSR(line status register)最低位为1,输出RHR寄存器中的值,否则输出-1。
最低位表示receive data ready。
Here is the caller graph for this function:

◆ uartinit()

void uartinit ( void  )

初始化uart各个寄存器

Here is the caller graph for this function:

◆ uartintr()

void uartintr ( void  )

uart中断处理,当输入数据抵达或uart准备好更多输出时调用,被devintr函数调用。

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartputc()

void uartputc ( int  c)

将字符写入输出缓冲区,通知UART开始发送字符。

若输出缓冲区满则阻塞。只适合在write调用中使用。

Parameters
c输入字符
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartputc_sync()

void uartputc_sync ( int  c)

uartputc()的变体,不需要使用中断。

内核的printf使用该函数输入字符,它会忙等uart的输出寄存器变为空。

Parameters
c输入字符
Here is the caller graph for this function:

◆ uartstart()

void uartstart ( )

如果UART空闲且传输缓冲区中有字符等待,将字符输出。

调用该函数的进程必须持有uart_tx_lock互斥锁。可以通过top-half和bottom-half中断调用

top-half:在关中断的条件下执行的,具有"原子"性,而且是中断发生以后一般要立即执行的。

bottom-half:在开中断的条件下执行,可以延迟一段时间执行,可能将多个中断的bottom half合并起来一起执行

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ panicked

volatile int panicked
extern

◆ uart_tx_buf

char uart_tx_buf[UART_TX_BUF_SIZE]

◆ uart_tx_r

uint64 uart_tx_r

◆ uart_tx_w

uint64 uart_tx_w