mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 14:20:21 +00:00
Kernel: Add UART class for aarch64
This commit is contained in:
parent
44c787e88b
commit
54aabb07f9
Notes:
sideshowbarker
2024-07-18 03:25:23 +09:00
Author: https://github.com/nico
Commit: 54aabb07f9
Pull-request: https://github.com/SerenityOS/serenity/pull/10223
4 changed files with 224 additions and 6 deletions
51
Kernel/Prekernel/Arch/aarch64/UART.h
Normal file
51
Kernel/Prekernel/Arch/aarch64/UART.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Prekernel {
|
||||
|
||||
struct UARTRegisters;
|
||||
|
||||
// Abstracts the PL011 UART on a Raspberry Pi.
|
||||
// (The BCM2711 on a Raspberry Pi 4 has five PL011 UARTs; this is always the first of those.)
|
||||
class UART {
|
||||
public:
|
||||
static UART& the();
|
||||
|
||||
void send(u32 c);
|
||||
u32 receive();
|
||||
|
||||
void print_str(const char* s)
|
||||
{
|
||||
while (*s)
|
||||
send(*s++);
|
||||
}
|
||||
void print_num(u32 n)
|
||||
{
|
||||
char buf[11];
|
||||
int i = 0;
|
||||
while (n) {
|
||||
buf[i++] = (n % 10) + '0';
|
||||
n /= 10;
|
||||
}
|
||||
for (i--; i >= 0; i--)
|
||||
send(buf[i]);
|
||||
}
|
||||
|
||||
private:
|
||||
UART();
|
||||
|
||||
void set_baud_rate(int baud_rate, int uart_frequency_in_hz);
|
||||
void wait_until_we_can_send();
|
||||
void wait_until_we_can_receive();
|
||||
|
||||
UARTRegisters volatile* m_registers;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue