-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotter_mcu_pipeline_template_v2.sv
149 lines (102 loc) · 3.53 KB
/
otter_mcu_pipeline_template_v2.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: J. Callenes
//
// Create Date: 01/04/2019 04:32:12 PM
// Design Name:
// Module Name: PIPELINED_OTTER_CPU
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
typedef enum logic [6:0] {
LUI = 7'b0110111,
AUIPC = 7'b0010111,
JAL = 7'b1101111,
JALR = 7'b1100111,
BRANCH = 7'b1100011,
LOAD = 7'b0000011,
STORE = 7'b0100011,
OP_IMM = 7'b0010011,
OP = 7'b0110011,
SYSTEM = 7'b1110011
} opcode_t;
typedef struct packed{
opcode_t opcode;
logic [4:0] rs1_addr;
logic [4:0] rs2_addr;
logic [4:0] rd_addr;
logic rs1_used;
logic rs2_used;
logic rd_used;
logic [3:0] alu_fun;
logic memWrite;
logic memRead2;
logic regWrite;
logic [1:0] rf_wr_sel;
logic [2:0] mem_type; //sign, size
logic [31:0] pc;
} instr_t;
module OTTER_MCU(input CLK,
input INTR,
input RESET,
input [31:0] IOBUS_IN,
output [31:0] IOBUS_OUT,
output [31:0] IOBUS_ADDR,
output logic IOBUS_WR
);
wire [6:0] opcode;
wire [31:0] pc, pc_value, next_pc, jalr_pc, branch_pc, jump_pc, int_pc,A,B,
I_immed,S_immed,U_immed,aluBin,aluAin,aluResult,rfIn,csr_reg, mem_data;
wire [31:0] IR;
wire memRead1,memRead2;
wire pcWrite,regWrite,memWrite, op1_sel,mem_op,IorD,pcWriteCond,memRead;
wire [1:0] opB_sel, rf_sel, wb_sel, mSize;
logic [1:0] pc_sel;
wire [3:0]alu_fun;
wire opA_sel;
logic br_lt,br_eq,br_ltu;
//==== Instruction Fetch ===========================================
logic [31:0] if_de_pc;
always_ff @(posedge CLK) begin
if_de_pc <= pc;
end
assign pcWrite = 1'b1; //Hardwired high, assuming now hazards
assign memRead1 = 1'b1; //Fetch new instruction every cycle
//==== Instruction Decode ===========================================
logic [31:0] de_ex_opA;
logic [31:0] de_ex_opB;
logic [31:0] de_ex_rs2;
instr_t de_ex_inst, de_inst;
opcode_t OPCODE;
assign OPCODE_t = opcode_t'(opcode);
assign de_inst.rs1_addr=IR[19:15];
assign de_inst.rs2_addr=IR[24:20];
assign de_inst.rd_addr=IR[11:7];
assign de_inst.opcode=OPCODE;
assign de_inst.rs1_used= de_inst.rs1 != 0
&& de_inst.opcode != LUI
&& de_inst.opcode != AUIPC
&& de_inst.opcode != JAL;
//==== Execute ======================================================
logic [31:0] ex_mem_rs2;
logic ex_mem_aluRes = 0;
instr_t ex_mem_inst;
logic [31:0] opA_forwarded;
logic [31:0] opB_forwarded;
// Creates a RISC-V ALU
OTTER_ALU ALU (de_ex_inst.alu_fun, de_ex_opA, de_ex_opB, aluResult); // the ALU
//==== Memory ======================================================
assign IOBUS_ADDR = ex_mem_aluRes;
assign IOBUS_OUT = ex_mem_rs2;
//==== Write Back ==================================================
endmodule