UART as MMIO device

master
vhaudiquet 1 year ago
parent 58b4bdb1e6
commit 7fbfae1081
  1. 26
      src/devices/uart/uart.c
  2. 6
      src/devices/uart/uart.h
  3. 4
      src/main.c

@ -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;
}

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

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

Loading…
Cancel
Save