109 for (
auto spin {0_usize}; spin < 100000_usize; ++spin) {
166 "Serial port 0x%x:\t%d %d%c%d",
170 (parity == PARITY::NONE) ?
'N' :
'?',
188 return serialStatus(port).isSet(SERIAL_LSR::DATA_READY);
220 if ((
'\n' == symbol) && !
serialPut(port,
'\r')) [[unlikely]] {
235 symbol =
static_cast<char>(
serialRegRead(port, SERIAL_REG::DATA));
244 auto written {0_usize};
245 while ((written < text.size()) &&
serialPutSymbol(port, text[written])) {
257 while ((read < buffer.size()) &&
serialGetSymbol(port, buffer[read])) {
282 auto data {std::array<char, 128_usize> {}};
284 const auto read {
serialRead(SERIAL_PORT::COM1, std::span {data}.first(data.size() - 1_usize))};
288 "Read:\t%05zu bytes = %s\n",
301 if (!
serialInit(SERIAL_PORT::COM1, BAUD_RATE::BAUD_115200, DATA_SIZE::CHAR_8, STOP_BITS::STOP_1, PARITY::NONE)) {
static auto readPort8(const port_t addr) noexcept -> igros_byte_t
Read byte from port.
static void writePort8(const port_t addr, const igros_byte_t value) noexcept
Write byte to port.
static void install() noexcept
Install IRQ handler.
static void unmask(const irq_t number) noexcept
Unmask interrupt.
static constexpr auto from(const U value) noexcept -> kFlags
From raw value (hardware register, table entry).
std::uint16_t igros_word_t
16-bit unsigned integer
std::size_t igros_usize_t
Unsigned size.
std::uint8_t igros_byte_t
8-bit unsigned integer
std::uint32_t igros_dword_t
32-bit unsigned integer
Architecture interrupts type deduction.
Bit flags template datatype.
Kernel text print functions.
SERIAL_IER
Interrupt enable register bits.
@ RX_READY
Received data available.
SERIAL_LSR
Line status register bits.
@ TX_IDLE
Holding and shift registers empty.
@ THR_EMPTY
Transmitter holding register empty.
@ DATA_READY
Received byte available.
SERIAL_MCR
Modem control register bits.
@ DTR
Data terminal ready.
@ OUT2
Auxiliary output 2 (IRQ line enable on PC).
@ OUT1
Auxiliary output 1.
@ LOOPBACK
Loopback test mode.
SERIAL_REG
Serial port registers (offsets from port base).
@ IIR
Interrupt identification (read) / FIFO control (write).
@ IER
Interrupt enable (DLAB = 0) / divisor high byte (DLAB = 1).
@ DATA
Data (DLAB = 0) / divisor low byte (DLAB = 1).
Architecture-independent interface: drivers and aliases of current architecture types.
auto serialWrite(const SERIAL_PORT port, const std::string_view text) noexcept -> igros_usize_t
Serial write.
static void serialInterruptHandler1(const register_t *const regs) noexcept
Serial #1 | #3 IRQ handler.
auto serialRead(const SERIAL_PORT port, const std::span< char > buffer) noexcept -> igros_usize_t
Serial read.
auto serialReadyWrite(const SERIAL_PORT port) noexcept -> bool
Is write ready?
static auto serialStatus(const SERIAL_PORT port) noexcept -> klib::kFlags< SERIAL_LSR >
Read line status register.
auto serialInit(const SERIAL_PORT port, const BAUD_RATE baudRate, const DATA_SIZE dataSize, const STOP_BITS stopBits, const PARITY parity) noexcept -> bool
Initialize serial port.
auto serialSetup() noexcept -> bool
Setup COM1 (115200 8N1) with receive interrupt.
static auto serialRegRead(const SERIAL_PORT port, const SERIAL_REG reg) noexcept -> igros_byte_t
Read serial port register.
SERIAL_PORT
Serial ports (standard PC I/O bases).
static constexpr auto serialRegister(const SERIAL_PORT port, const SERIAL_REG reg) noexcept -> port_t
Serial port register address.
auto serialReadyRead(const SERIAL_PORT port) noexcept -> bool
Is read ready?
static auto serialGetSymbol(const SERIAL_PORT port, char &symbol) noexcept -> bool
Receive one symbol (only if available).
static auto serialWaitStatus(const SERIAL_PORT port, const SERIAL_LSR status) noexcept -> bool
Wait until line status bit is set (bounded, so missing UART can't hang the kernel).
static auto serialPutSymbol(const SERIAL_PORT port, const char symbol) noexcept -> bool
Send one symbol (new line is sent as CR LF).
static auto serialWaitWrite(const SERIAL_PORT port) noexcept -> bool
Wait until write ready.
static void serialRegWrite(const SERIAL_PORT port, const SERIAL_REG reg, const igros_byte_t value) noexcept
Write serial port register.
static auto serialPut(const SERIAL_PORT port, const igros_byte_t value) noexcept -> bool
Wait for transmitter and send one byte.
constexpr auto kstrview(const char *const src) noexcept -> std::string_view
View of null-terminated string (null pointer is empty string).
void kprintf(const char *const format,...) noexcept
Kernel printf function (arguments are checked against format at compile time).
constexpr auto make_kflags(const Args... flags) noexcept -> kFlags< T >
Flags creation helper function from set flags.
igros_word_t port_t
Define port data type which is 16bit word.
x86_64 task switch registers save