Changed formatting and added new UART divsor calculation from OpenSBI.

This commit is contained in:
Jacob Pease 2024-07-25 13:04:27 -05:00
parent 336a413f31
commit a36e846b02

View File

@ -31,7 +31,9 @@ void write_serial(char a)
void init_uart(uint32_t freq, uint32_t baud)
{
uint32_t divisor = freq / (baud << 4);
// Alternative divisor calculation. From OpenSBI code.
// Reduces error for every possible frequency.
uint32_t divisor = (freq + 8 * baud) /(baud << 4);
write_reg_u8(UART_IER, 0x00); // Disable all interrupts
write_reg_u8(UART_LCR, 0x80); // Enable DLAB (set baud rate divisor)
@ -44,8 +46,7 @@ void init_uart(uint32_t freq, uint32_t baud)
void print_uart(const char *str)
{
const char *cur = &str[0];
while (*cur != '\0')
{
while (*cur != '\0') {
write_serial((uint8_t)*cur);
++cur;
}
@ -64,8 +65,7 @@ void bin_to_hex(uint8_t inp, uint8_t res[2])
void print_uart_int(uint32_t addr)
{
int i;
for (i = 3; i > -1; i--)
{
for (i = 3; i > -1; i--) {
uint8_t cur = (addr >> (i * 8)) & 0xff;
uint8_t hex[2];
bin_to_hex(cur, hex);
@ -77,8 +77,7 @@ void print_uart_int(uint32_t addr)
void print_uart_addr(uint64_t addr)
{
int i;
for (i = 7; i > -1; i--)
{
for (i = 7; i > -1; i--) {
uint8_t cur = (addr >> (i * 8)) & 0xff;
uint8_t hex[2];
bin_to_hex(cur, hex);