UART as MMIO device

This commit is contained in:
vhaudiquet 2023-10-11 21:30:57 +02:00
parent 58b4bdb1e6
commit 7fbfae1081
3 changed files with 36 additions and 0 deletions

26
src/devices/uart/uart.c Normal file
View File

@ -0,0 +1,26 @@
#include "uart.h"
#include "memory/memory.h"
#include <stdio.h>
#define UART_ADDRESS 0x3000000
#define UART_REGISTER_SIZE 4
#define UART_REGISTER_COUNT 1
#define UART_REG_TXFIFO 0x0
void uart_handle_mmio_write(uint32_t address, uint8_t value);
uint32_t uart_handle_mmio_read(uint32_t address);
void uart_init()
{
mem_register_mmio(UART_ADDRESS, UART_REGISTER_SIZE, UART_REGISTER_COUNT, uart_handle_mmio_write, uart_handle_mmio_read);
}
void uart_handle_mmio_write(uint32_t address, uint8_t value)
{
printf("%c", value);
}
uint32_t uart_handle_mmio_read(uint32_t address)
{
return 0;
}

6
src/devices/uart/uart.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef UART_H
#define UART_H
void uart_init();
#endif

View File

@ -3,6 +3,7 @@
#include "bootloader/bootloader.h"
#include "cpu/rv32cpu.h"
#include "gdbstub/gdbstub.h"
#include "devices/uart/uart.h"
char* CURRENT_NAME;
@ -14,6 +15,9 @@ int main(int argc, char** argv)
// Initialize the memory
mem_init();
// Initialize UART (memory-mapped)
uart_init();
// Bootload the file passed as argument
uint32_t entry_point = bootload(file_path);