PL011 串口驱动
More...
#include <pl011.hpp>
|
| static constexpr uint32_t | kRegDR = 0x00 |
| | data register
|
| |
| static constexpr uint32_t | kRegRSRECR = 0x04 |
| | receive status or error clear
|
| |
| static constexpr uint32_t | kRegFR = 0x18 |
| | flag register
|
| |
| static constexpr uint32_t | kRegIBRD = 0x24 |
| | integer baud register
|
| |
| static constexpr uint32_t | kRegFBRD = 0x28 |
| | fractional baud register
|
| |
| static constexpr uint32_t | kRegLCRH = 0x2C |
| | line control register
|
| |
| static constexpr uint32_t | kRegCR = 0x30 |
| | control register
|
| |
| static constexpr uint32_t | kRegIMSC = 0x38 |
| | interrupt mask set/clear
|
| |
| static constexpr uint32_t | kRegRIS = 0x3C |
| | raw interrupt status register
|
| |
| static constexpr uint32_t | kRegMIS = 0x40 |
| | masked interrupt status register
|
| |
| static constexpr uint32_t | kRegICR = 0x44 |
| | interrupt clear register
|
| |
| static constexpr uint32_t | kFRTxFIFO = (1 << 5) |
| | flag register bits
|
| |
| static constexpr uint32_t | kFRRXFE = (1 << 4) |
| |
| static constexpr uint32_t | kLCRHWlen8 = (3 << 5) |
| | line control register bits
|
| |
| static constexpr uint32_t | kCREnable = (1 << 0) |
| | control register bits
|
| |
| static constexpr uint32_t | kCRTxEnable = (1 << 8) |
| |
| static constexpr uint32_t | kCRRxEnable = (1 << 9) |
| |
| static constexpr uint32_t | kIMSCRxim = (1 << 4) |
| | interrupt mask bits
|
| |
PL011 串口驱动
通过 MMIO 访问 PL011 UART 寄存器,提供字符读写功能。 Header-only 实现,使用 MmioAccessor 进行寄存器访问。
- See also
- https://developer.arm.com/documentation/ddi0183/g/
Definition at line 22 of file pl011.hpp.
◆ Pl011() [1/4]
| pl011::Pl011::Pl011 |
( |
uint64_t |
dev_addr, |
|
|
uint64_t |
clock = 0, |
|
|
uint64_t |
baud_rate = 0 |
|
) |
| |
|
inlineexplicit |
构造函数
- Parameters
-
| dev_addr | 设备 MMIO 基地址 |
| clock | 串口时钟(0 表示不设置波特率) |
| baud_rate | 波特率(0 表示不设置波特率) |
Definition at line 124 of file pl011.hpp.
128
133 }
134
138 }
static constexpr uint32_t kRegRSRECR
receive status or error clear
static constexpr uint32_t kRegIBRD
integer baud register
static constexpr uint32_t kLCRHWlen8
line control register bits
static constexpr uint32_t kRegCR
control register
static constexpr uint32_t kRegIMSC
interrupt mask set/clear
static constexpr uint32_t kCREnable
control register bits
static constexpr uint32_t kRegLCRH
line control register
static constexpr uint32_t kRegFBRD
fractional baud register
static constexpr uint32_t kCRTxEnable
static constexpr uint32_t kCRRxEnable
static constexpr uint32_t kIMSCRxim
interrupt mask bits
auto Write(size_t offset, T val) const -> void
Write to MMIO register.
◆ Pl011() [2/4]
◆ Pl011() [3/4]
| pl011::Pl011::Pl011 |
( |
const Pl011 & |
| ) |
|
|
delete |
◆ Pl011() [4/4]
| pl011::Pl011::Pl011 |
( |
Pl011 && |
| ) |
|
|
default |
◆ ~Pl011()
◆ ClearInterrupt()
| auto pl011::Pl011::ClearInterrupt |
( |
uint32_t |
mask | ) |
const -> void |
|
inline |
清除指定中断
向 ICR 寄存器写入位掩码以清除对应的中断。
- Parameters
-
Definition at line 93 of file pl011.hpp.
93 {
95 }
static constexpr uint32_t kRegICR
interrupt clear register
◆ GetChar()
| auto pl011::Pl011::GetChar |
( |
| ) |
const -> uint8_t |
|
inline |
阻塞式读取一个字符
- Returns
- 读取到的字符
Definition at line 38 of file pl011.hpp.
38 {
40 }
42 }
static constexpr uint32_t kFRRXFE
static constexpr uint32_t kRegDR
data register
static constexpr uint32_t kRegFR
flag register
auto Read(size_t offset) const -> T
Read from MMIO register.
◆ GetMaskedInterruptStatus()
| auto pl011::Pl011::GetMaskedInterruptStatus |
( |
| ) |
const -> uint32_t |
|
inline |
读取屏蔽后的中断状态寄存器(MIS)
返回经 IMSC 屏蔽后的中断状态,只包含被使能的中断源。
- Returns
- 中断状态位掩码
- See also
- ARM PL011 Technical Reference Manual
Definition at line 71 of file pl011.hpp.
71 {
73 }
static constexpr uint32_t kRegMIS
masked interrupt status register
◆ GetRawInterruptStatus()
| auto pl011::Pl011::GetRawInterruptStatus |
( |
| ) |
const -> uint32_t |
|
inline |
读取原始中断状态寄存器(RIS)
返回所有中断源的原始状态(不经 IMSC 屏蔽)。
- Returns
- 原始中断状态位掩码
Definition at line 82 of file pl011.hpp.
82 {
84 }
static constexpr uint32_t kRegRIS
raw interrupt status register
◆ HandleInterrupt()
template<typename Callback >
| auto pl011::Pl011::HandleInterrupt |
( |
Callback && |
callback | ) |
-> void |
|
inline |
处理串口接收中断,对每个收到的字符调用回调
- Parameters
-
| callback | 字符接收回调,签名 void(uint8_t ch) |
Definition at line 110 of file pl011.hpp.
110 {
113 }
114 }
auto HasData() const -> bool
检查接收缓冲区是否有数据可读(不消耗数据)
auto GetChar() const -> uint8_t
阻塞式读取一个字符
◆ HasData()
| auto pl011::Pl011::HasData |
( |
| ) |
const -> bool |
|
inline |
检查接收缓冲区是否有数据可读(不消耗数据)
- Returns
- true 如果有数据可读
Definition at line 59 of file pl011.hpp.
◆ IsInterruptPending()
| auto pl011::Pl011::IsInterruptPending |
( |
| ) |
const -> bool |
|
inline |
检查是否有中断挂起
- Returns
- true 如果有屏蔽后的中断挂起
Definition at line 101 of file pl011.hpp.
101 {
103 }
auto GetMaskedInterruptStatus() const -> uint32_t
读取屏蔽后的中断状态寄存器(MIS)
◆ operator=() [1/2]
| auto pl011::Pl011::operator= |
( |
const Pl011 & |
| ) |
-> Pl011 &=delete |
|
delete |
◆ operator=() [2/2]
| auto pl011::Pl011::operator= |
( |
Pl011 && |
| ) |
-> Pl011 &=default |
|
default |
◆ PutChar()
| auto pl011::Pl011::PutChar |
( |
uint8_t |
c | ) |
const -> void |
|
inline |
写入一个字符
- Parameters
-
Definition at line 28 of file pl011.hpp.
28 {
30 }
32 }
static constexpr uint32_t kFRTxFIFO
flag register bits
◆ TryGetChar()
| auto pl011::Pl011::TryGetChar |
( |
| ) |
const -> std::optional<uint8_t> |
|
inline |
非阻塞式尝试读取一个字符
- Returns
- 读取到的字符,如果没有数据则返回 std::nullopt
Definition at line 48 of file pl011.hpp.
48 {
50 return std::nullopt;
51 }
53 }
◆ base_clock_
| uint64_t pl011::Pl011::base_clock_ {0} |
|
private |
◆ baud_rate_
| uint64_t pl011::Pl011::baud_rate_ {0} |
|
private |
◆ kCREnable
| constexpr uint32_t pl011::Pl011::kCREnable = (1 << 0) |
|
staticconstexprprivate |
control register bits
Definition at line 179 of file pl011.hpp.
◆ kCRRxEnable
| constexpr uint32_t pl011::Pl011::kCRRxEnable = (1 << 9) |
|
staticconstexprprivate |
◆ kCRTxEnable
| constexpr uint32_t pl011::Pl011::kCRTxEnable = (1 << 8) |
|
staticconstexprprivate |
◆ kFRRXFE
| constexpr uint32_t pl011::Pl011::kFRRXFE = (1 << 4) |
|
staticconstexprprivate |
◆ kFRTxFIFO
| constexpr uint32_t pl011::Pl011::kFRTxFIFO = (1 << 5) |
|
staticconstexprprivate |
flag register bits
Definition at line 172 of file pl011.hpp.
◆ kIMSCRxim
| constexpr uint32_t pl011::Pl011::kIMSCRxim = (1 << 4) |
|
staticconstexprprivate |
interrupt mask bits
Definition at line 184 of file pl011.hpp.
◆ kLCRHWlen8
| constexpr uint32_t pl011::Pl011::kLCRHWlen8 = (3 << 5) |
|
staticconstexprprivate |
line control register bits
Definition at line 176 of file pl011.hpp.
◆ kRegCR
| constexpr uint32_t pl011::Pl011::kRegCR = 0x30 |
|
staticconstexprprivate |
◆ kRegDR
| constexpr uint32_t pl011::Pl011::kRegDR = 0x00 |
|
staticconstexprprivate |
◆ kRegFBRD
| constexpr uint32_t pl011::Pl011::kRegFBRD = 0x28 |
|
staticconstexprprivate |
fractional baud register
Definition at line 157 of file pl011.hpp.
◆ kRegFR
| constexpr uint32_t pl011::Pl011::kRegFR = 0x18 |
|
staticconstexprprivate |
◆ kRegIBRD
| constexpr uint32_t pl011::Pl011::kRegIBRD = 0x24 |
|
staticconstexprprivate |
integer baud register
Definition at line 155 of file pl011.hpp.
◆ kRegICR
| constexpr uint32_t pl011::Pl011::kRegICR = 0x44 |
|
staticconstexprprivate |
interrupt clear register
Definition at line 169 of file pl011.hpp.
◆ kRegIMSC
| constexpr uint32_t pl011::Pl011::kRegIMSC = 0x38 |
|
staticconstexprprivate |
interrupt mask set/clear
Definition at line 163 of file pl011.hpp.
◆ kRegLCRH
| constexpr uint32_t pl011::Pl011::kRegLCRH = 0x2C |
|
staticconstexprprivate |
line control register
Definition at line 159 of file pl011.hpp.
◆ kRegMIS
| constexpr uint32_t pl011::Pl011::kRegMIS = 0x40 |
|
staticconstexprprivate |
masked interrupt status register
Definition at line 167 of file pl011.hpp.
◆ kRegRIS
| constexpr uint32_t pl011::Pl011::kRegRIS = 0x3C |
|
staticconstexprprivate |
raw interrupt status register
Definition at line 165 of file pl011.hpp.
◆ kRegRSRECR
| constexpr uint32_t pl011::Pl011::kRegRSRECR = 0x04 |
|
staticconstexprprivate |
receive status or error clear
Definition at line 151 of file pl011.hpp.
◆ mmio_
The documentation for this class was generated from the following file:
- /workspaces/SimpleKernel/src/device/pl011/pl011.hpp