add: dual port imem and uart

This commit is contained in:
Jose
2026-03-03 01:44:27 +01:00
parent 98f948ab18
commit a890b031a7
36 changed files with 97 additions and 50 deletions

View File

@@ -13,19 +13,24 @@
//
// Dependencies:
//
// Revision: 1.0
// Revision 0.01 - File Created
// Revision: 2.0 - Dual port for UART programming
// Revision: 1.0 - Basic structure
// Revision: 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module imem(
input clk,
input [31:0] address,
input we,
input [31:0] write_data,
input [7:0] write_addr,
output [31:0] inst_out
// puerto 1
input [31:0] read_addr,
output [31:0] inst_out,
// puerto 2
input we_ext,
input [31:0] write_addr_ext,
input [31:0] write_data_ext
);
reg [31:0] memory[0:255];
@@ -39,9 +44,11 @@ initial begin
end
always @(posedge clk) begin
if(we)
memory[write_addr] <= write_data;
inst_reg <= memory[address[9:2]];
if(we_ext) begin
memory[write_addr_ext[9:2]] <= write_data_ext;
end
inst_reg <= memory[read_addr[9:2]];
end
assign inst_out = inst_reg;

View File

@@ -1,11 +1,38 @@
`timescale 1ns / 1ps
`default_nettype none
//////////////////////////////////////////////////////////////////////////////////
// Company: nope
// Engineer: Jose
//
// Create Date: 02/20/2026 09:21:52 AM
// Design Name: RISCV AC Processor Implementation
// Module Name: top
// Project Name: riscv-ac
// Target Devices: Artix 7
// Tool Versions: 2025.2
// Description: Top module for interconnection
//
// Dependencies:
//
// Revision: 2.0 - MMIO
// Revision: 1.0 - Basic structure
// Revision: 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module top (
input clk,
input rst,
// Programacion
input [31:0] prog_data,
input [31:0] prog_addr,
input prog_we,
// Debug & UART
output [1:0] leds,
output [31:0] debug
output [31:0] uart_tx_data,
output uart_tx_en
);
// ==========================================
@@ -26,8 +53,14 @@ module top (
);
imem u_imem (
.clk(clk), .address(npc_IF), .we(1'b0),
.write_data(32'b0), .write_addr(8'b0), .inst_out(ir_IF)
.clk(clk),
// por aqui lee la CPU
.read_addr(pc_IF),
.inst_out(ir_IF),
// por aqui meto el programa
.we_ext(prog_we),
.write_addr_ext(prog_addr),
.write_data_ext(prog_data)
);
// ==========================================
@@ -161,9 +194,18 @@ module top (
// ==========================================
// ETAPA ME & WB
// ==========================================
// --- hacemos un apaño pa poder sacar cosas a la UART (MMIO) ---
wire is_uart = (alu_res_ME == 32'hFFFFFFFC);
wire dmem_we = we_mem_ME & ~is_uart; // si va pa la UART no escribimos en memoria
assign uart_tx_en = we_mem_ME & is_uart;
assign uart_tx_data = regB_ME;
// --------------------------------------------------------------
wire [31:0] mem_data_ME;
dmem u_dmem (
.clk(clk), .we(we_mem_ME), .address(alu_res_ME),
.clk(clk), .we(dmem_we), .address(alu_res_ME),
.write_data(regB_ME), .mem_data_out(mem_data_ME)
);
@@ -186,12 +228,5 @@ module top (
// ==========================================
assign leds[0] = Branch_Taken; // se enciende cuando hay salto
assign leds[1] = ID_EX_Clr; // se enciende en bloqueos
assign debug = {
alu_res_EX[15:0],
rd_WB,
rs1_ID,
npc_IF[7:2]
};
endmodule