-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessor.v
More file actions
172 lines (153 loc) · 3.71 KB
/
Processor.v
File metadata and controls
172 lines (153 loc) · 3.71 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
MY-P0 Processor: RISC ISA, 32-bit, Interrupts Enabled, Word Addressable, 3-stage Processor
*/
`include "micro_control_unit.v"
`include "arithmetic_logic_unit.v"
`include "memory_unit.v"
`include "register_file.v"
`include "timer_device.v"
`include "distance_tracker_device.v"
module Processor (input clk, rst );
reg [31:0] PC, IR, MAR, A, B, DAR;
reg [1:0] Cmp;
reg IE;
wire DrREG, DrMEM, DrALU, DrPC, DrOFF, LdPC, LdIR, LdMAR, LdA, LdB, LdCmp, WrREG,
WrMEM, OPTest, ChkCmp, LdEnInt, IntAck, DrData, LdDAR, OnInt;
wire [1:0] RegSel;
wire [2:0] ALUFunc;
wire [3:0] RegNo;
wire [5:0] Opcode;
wire [3:0] IR_to_Rx, IR_to_Ry, IR_to_Rz;
wire [19:0] IR_to_OFF;
assign Opcode = IR[31:28];
assign IR_to_Rx = IR[27:24];
assign IR_to_Ry = IR[23:20];
assign IR_to_Rz = IR_to_OFF[3:0];
assign IR_to_OFF = IR[19:0];
wire [31:0] device_data;
wire inta_from_timer, timer_int, inta_from_distance_tracker, distance_tracker_int;
timer_device timer_device1(
.clk(clk),
.rst(rst),
.inta_in(IntAck),
.timer_int(timer_int),
.inta_out(inta_from_timer),
.data(device_data)
);
distance_tracker_device distance_tracker_device(
.clk(clk),
.rst(rst),
.inta_in(IntAck),
.addr(DAR),
.tracker_int(distance_tracker_int),
.inta_out(inta_from_distance_tracker),
.data(device_data)
);
micro_controller micro_controller1(
.clk(clk),
.rst(rst),
.OnInt(OnInt), // Interrupts Disabled for now, will be enabled later with devices
.CmpOut(Cmp),
.Rx(IR_to_Rx),
.Ry(IR_to_Ry),
.Rz(IR_to_Rz),
.Opcode(Opcode),
.DrREG(DrREG),
.DrMEM(DrMEM),
.DrALU(DrALU),
.DrPC(DrPC),
.DrOFF(DrOFF),
.LdPC(LdPC),
.LdIR(LdIR),
.LdMAR(LdMAR),
.LdA(LdA),
.LdB(LdB),
.LdCmp(LdCmp),
.WrREG(WrREG),
.WrMEM(WrMEM),
.OPTest(OPTest),
.ChkCmp(ChkCmp),
.LdEnInt(LdEnInt),
.IntAck(IntAck),
.DrData(DrData),
.LdDAR(LdDAR),
.RegSel(RegSel),
.ALUFunc(ALUFunc),
.RegNo(RegNo)
);
wire [31:0] FromREG;
regfile regfile1(
.clk(clk),
.rst(rst),
.WrReg(WrREG),
.RegSel(RegNo),
.Din(Bus),
.Dout(FromREG)
);
wire [31:0] FromMEM;
ram ram1(
.MAR(MAR[15:0]),
.clk(clk),
.Din(Bus),
.WrMem(WrMEM),
.Dout(FromMEM)
);
wire [31:0] FromALU;
wire [31:0] FromA , FromB;
assign FromA = A;
assign FromB = B;
alu alu1(
.A(FromA),
.B(FromB),
.func(ALUFunc),
.out(FromALU)
);
initial begin
PC = 32'h00000000;
IR = 32'h00000000;
MAR = 32'h00000000;
A = 32'h00000000;
B = 32'h00000000;
Cmp = 2'h0;
DAR = 32'h00000000;
IE = 1'h0;
end
wire [31:0] Bus;
always @(posedge clk or posedge rst) begin
if (rst) begin
PC <= 'b0;
IR <= 'b0;
MAR <= 'b0;
A <= 'b0;
B <= 'b0;
Cmp <= 'b0;
DAR <= 'b0;
IE <= 'b0;
end else begin
if (LdPC) PC <= Bus;
if (LdIR) IR <= Bus;
if (LdMAR) MAR <= Bus;
if (LdA) A <= Bus;
if (LdB) B <= Bus;
if (LdCmp) begin
case (Opcode[1:0])
2'b00: Cmp <= Bus > 'h0 ? {Opcode[1:1], 1'b1} : {Opcode[1:1], 1'b0};
2'b01: Cmp <= Bus == 'h0 ? {Opcode[1:1], 1'b1} : {Opcode[1:1], 1'b0};
2'b10: Cmp <= Bus == 'h0 ? {Opcode[1:1], 1'b1} : {Opcode[1:1], 1'b0};
2'b11: Cmp <= Bus == 'h0 ? {Opcode[1:1], 1'b1} : {Opcode[1:1], 1'b0};
endcase
end
if (LdDAR) DAR <= Bus;
if (LdEnInt) IE <= IntAck ? 0 : ~(IR_to_Ry[0]);
end
end
assign OnInt = IE & (( timer_int ? 1 : distance_tracker_int ? 1 : 1'bZ ) | 0);
wire [31:0] extended_IR;
assign extended_IR = { {12{IR_to_OFF[19]}}, IR_to_OFF };
assign Bus = DrREG ? FromREG : 32'hZZZZ_ZZZZ;
assign Bus = DrMEM ? FromMEM : 32'hZZZZ_ZZZZ;
assign Bus = DrALU ? FromALU : 32'hZZZZ_ZZZZ;
assign Bus = DrPC ? ('d8 > PC ? PC + 'd8 : PC) : 32'hZZZZ_ZZZZ;
assign Bus = DrOFF ? extended_IR : 32'hZZZZ_ZZZZ;
assign Bus = DrData ? IE : 32'hZZZZ_ZZZZ;
endmodule