-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.sv
98 lines (63 loc) · 2.84 KB
/
Controller.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
//controller module which contains a instruction memory, instruction register, state machine, and program counter module.
//it takes clock and reset inputs from outside of the proccessor top level module.
//PC_out is out put for the top level module from the program counter module
//State outputs, the opcode, current state, and next state, are for the top level module which show the state info from the state machine module.
//the outputs for datapath module connection are D_addr,D_wr,RF_s,RF_W_addr,RF_W_en,RF_Ra_addr,RF_Rb_addr,Alu_s0 from the state machine module.
module Controller(Clk,Rst,PC_out,IR_out,OutState,NextState,D_addr,D_wr,RF_s,RF_W_addr,RF_W_en,RF_Ra_addr,RF_Rb_addr,Alu_s0);
input Clk, Rst;
//current instruction memory address output
output [6:0]PC_out; //what address of Inst Mem
//state output
output logic [15:0] IR_out; //value of current instruction
output logic [3:0] NextState; //opcode of next operation state
output logic [3:0] OutState; //opcode of current operation state
//for datapath module
output logic [7:0] D_addr;
output logic D_wr,RF_s,RF_W_en;
output logic [3:0] RF_W_addr,RF_Ra_addr,RF_Rb_addr;
output logic [2:0] Alu_s0;
//internal wires
wire [6:0]PCaddress; //since PC_out is output, we need a wire.
wire [15:0]Inst;
wire [15:0]IRdata;
wire Id;
wire PC_up;
wire PC_clr;
assign PC_out = PCaddress;
assign IR_out = IRdata;
//module myROM1 (address,clock,q);
myROM1 IMrom (PCaddress,Clk,Inst);
//IR(Inst,Clk,Id,IRout);
IR InstrReg(Inst,Clk,Id,IRdata);
//module SM(IRdata,Reset,Clk,Id,PC_up,PC_clr,outNextState,OutState,D_addr,D_wr,RF_s,RF_W_addr,RF_W_en,RF_Ra_addr,RF_Rb_addr,Alu_s0);
SM FSM(IRdata, Rst, Clk, Id, PC_up, PC_clr,NextState,OutState, D_addr , D_wr , RF_s, RF_W_addr, RF_W_en, RF_Ra_addr, RF_Rb_addr, Alu_s0);
//module PC(PC_up,PC_clr,Clk,PCout);
PC CTR( PC_up, PC_clr, Clk, PCaddress);
endmodule
`timescale 1ns/1ns
module Controller_tb();
reg Clk, Rst;
//current instruction memory address output
reg [6:0]PC_out; //what address of Inst Mem
//state output
reg [15:0] IR_out; //value of current instruction
reg [3:0] NextState; //opcode of next operation state
reg [3:0] OutState; //opcode of current operation state
//for datapath module
reg [7:0] D_addr;
reg D_wr,RF_s,RF_W_en;
reg [3:0] RF_W_addr,RF_Ra_addr,RF_Rb_addr;
reg [2:0] Alu_s0;
always begin // 50 MHz Clock
Clk = 0; #10;
Clk = 1'b1; #10;
end
//module Controller(Clk,Rst,PC_out,IR_out,OutState,NextState,D_addr,D_wr,RF_s,RF_W_addr,RF_W_en,RF_Ra_addr,RF_Rb_addr,Alu_s0);
Controller DUT(Clk,Rst,PC_out,IR_out,OutState,NextState,D_addr,D_wr,RF_s,RF_W_addr,RF_W_en,RF_Ra_addr,RF_Rb_addr,Alu_s0);
initial begin
#3;Rst =0; #20
Rst =1; #1000;
Rst = 0; #60;
$stop;
end
endmodule