populate top_level.sv

This commit is contained in:
Arthur Lu 2022-08-13 18:06:19 -07:00
parent ee08d3505c
commit 98fbdc5546
3 changed files with 82 additions and 29 deletions

View File

@ -9,11 +9,11 @@ module Ctrl #(
parameter T = 10 parameter T = 10
) ( ) (
input logic [8:0] Instruction, input logic [8:0] Instruction,
input logic [W-1:0] ALU_Out, // control ALU operation input logic [W-1:0] ALU_Out,
input logic [W-1:0] RegOutA, RegOutB, // select from register inputs or immediate inputs input logic [W-1:0] RegOutA, RegOutB, // select from register inputs or immediate inputs
input logic [T-1:0] ProgCtr_p4, input logic [T-1:0] ProgCtr_p4,
input logic [W-1:0] mem_out, input logic [W-1:0] mem_out,
output op_mne ALU_OP, output op_mne ALU_OP, // control ALU operation
output logic [W-1:0] ALU_A, ALU_B, output logic [W-1:0] ALU_A, ALU_B,
output logic RegWrite, Done_in, output logic RegWrite, Done_in,
output logic [3:0] RaddrA, RaddrB, Waddr, RegInput, output logic [3:0] RaddrA, RaddrB, Waddr, RegInput,

View File

@ -5,8 +5,9 @@
module InstFetch #(parameter T=10, parameter W=8)( // T is PC address size, W is the jump target pointer width, which is less module InstFetch #(parameter T=10, parameter W=8)( // T is PC address size, W is the jump target pointer width, which is less
input logic Clk, Reset, // clock, reset input logic Clk, Reset, // clock, reset
input logic BranchEZ, BranchNZ, BranchAlways, Zero, // branch control signals zero from alu signals; brnahc signals will be one hot encoding input logic BranchEZ, BranchNZ, BranchAlways, Zero, // branch control signals zero from alu signals; brnahc signals will be one hot encoding
input logic done, // Done flag to indicate if the PC should increment at all input logic Done, // Done flag to indicate if the PC should increment at all
input logic [W-1:0] Target, // jump target pointer input logic [W-1:0] Target, // jump target pointer
output logic [T-1:0] ProgCtr,
output logic [T-1:0] ProgCtr_p4 // value of pc+4 for use in JAL instruction itself output logic [T-1:0] ProgCtr_p4 // value of pc+4 for use in JAL instruction itself
); );
@ -17,7 +18,7 @@ module InstFetch #(parameter T=10, parameter W=8)( // T is PC address size, W
else if (BranchAlways) PC <= Target; // if unconditional branch, assign PC to target else if (BranchAlways) PC <= Target; // if unconditional branch, assign PC to target
else if (BranchEZ && Zero) PC <= Target; // if branch on zero and zero is true, then assign PC to target else if (BranchEZ && Zero) PC <= Target; // if branch on zero and zero is true, then assign PC to target
else if (BranchNZ && !Zero) PC <= Target; // if branch on non zero and zero is false, then assign PC to parget else if (BranchNZ && !Zero) PC <= Target; // if branch on non zero and zero is false, then assign PC to parget
else if (!done) PC <= PC + 'b1; // if not a branch but CPU is not done, then else if (!Done) PC <= PC + 'b1; // if not a branch but CPU is not done, then
else PC <= PC; else PC <= PC;
end end

View File

@ -1,35 +1,87 @@
// skeletal starter code top level of your DUT // Module Name: ALU
// Project Name: CSE141L
// Description: top level RTL for processor
import Definitions::*;
module top_level( module top_level(
input clk, init, req, input clk, init, req,
output logic ack); output logic ack
);
logic mem_wen; parameter T=10;
logic[7:0] mem_addr, parameter W=8;
mem_in,
mem_out;
logic[11:0] pctr; // temporary program counter
// populate with program counter, instruction ROM, reg_file (if used), logic [8:0] Instruction;
// accumulator (if used), logic [W-1:0] ALU_Out;
logic [W-1:0] RegOutA, RegOutB; // select from register inputs or immediate inputs
logic [T-1:0] ProgCtr_p4;
logic [W-1:0] mem_out;
op_mne ALU_OP; // control ALU operation
logic [W-1:0] ALU_A, ALU_B;
logic RegWrite, Done_in;
logic [3:0] RaddrA, RaddrB, Waddr, RegInput;
logic BranchEZ, BranchNZ, BranchAlways;
logic write_mem;
logic Zero_in, Zero_out;
logic Done_out;
logic [T-1:0] ProgCtr;
DataMem DM(.Clk (clk), Ctrl #() c (.*);
ALU #() a (
.A(ALU_A),
.B(ALU_B),
.ALU_OP(ALU_OP),
.Out(ALU_Out),
.Zero(Zero_in)
);
InstFetch #() pc (
.Clk(clk),
.Reset(init), .Reset(init),
.WriteEn (mem_wen), .BranchEZ(BranchEZ),
.DataAddress (mem_addr), .BranchNZ(BranchNZ),
.DataIn (mem_in), .BranchAlways(BranchAlways),
.DataOut (mem_out)); .Zero(Zero_out),
.Done(Done_out),
.Target(ALU_A),
.ProgCtr(ProgCtr),
.ProgCtr_p4(ProgCtr_p4)
);
RegFile #() r (
.Clk(clk),
.Reset(init),
.WriteEn(RegWrite),
.RaddrA(RaddrA),
.RaddrB(RaddrB),
.Waddr(Waddr),
.DataIn(RegInput),
.Zero_in(Zero_in),
.Done_in(Done_in),
.start(req),
.DataOutA(RegOutA),
.DataOutB(RegOutB),
.Zero_out(Zero_out),
.Done_out(Done_out)
);
// temporary circuit to provide ack (done) flag to test bench DataMem #() d (
// remove or greatly increase the match value once you get a .Clk(clk),
// proper ack .Reset(init),
always @(posedge clk) .WriteEn(write_mem),
if(init || req) .DataAddress(ALU_Out),
pctr <= 'h0; .DataIn(RegOutB),
else .DataOut(mem_out)
pctr <= pctr+'h1; );
assign ack = pctr=='h256; // pctr needed to trigger ack (arbitary time) InstROM #() i (
.InstAddress(ProgCtr),
.InstOut(Instruction)
);
assign ack = Done_out;
endmodule endmodule