UART as MMIO device

master
vhaudiquet 11 months 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 "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);

Loading…
Cancel
Save