-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCPU_gen.vhd
More file actions
200 lines (177 loc) · 4.73 KB
/
CPU_gen.vhd
File metadata and controls
200 lines (177 loc) · 4.73 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
----------------------------------------------------------------------------------
-- Company: Ryerson University
-- Engineer: Victor Dumitriu
--
-- Design Name: CPU Read/Write Transaction Generator
-- Module Name: CPU_gen - Behavioral
-- Target Devices: XC3S500E
--
-- Description: A testbench circuit for course COE758, Project 1.
-- The circuit plays the role of a CPU, generating read
-- and write transactions to various addresses. The Cache
-- Controller being designed for Project 1 must respond to
-- these transactions.
--
-- Dependencies: None.
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity CPU_gen is
Port (
clk : in STD_LOGIC;
rst : in STD_LOGIC;
trig : in STD_LOGIC;
-- Interface to the Cache Controller.
Address : out STD_LOGIC_VECTOR (15 downto 0);
wr_rd : out STD_LOGIC;
cs : out STD_LOGIC;
DOut : out STD_LOGIC_VECTOR (7 downto 0)
);
end CPU_gen;
architecture Behavioral of CPU_gen is
-- Pattern storage and control.
signal patOut : std_logic_vector(24 downto 0);
signal patCtrl : std_logic_vector(2 downto 0) := "111";
signal updPat : std_logic;
-- Main control.
signal st1 : std_logic_vector(2 downto 0) := "000";
signal st1N : std_logic_vector(2 downto 0);
-- Rising edge detection.
signal rReg1, rReg2 : std_logic;
signal trig_r : std_logic;
begin
--------------------------------------------------------------------------
-- Main control FSM.
--------------------------------------------------------------------------
-- State storage.
process(clk, rst, st1N)
begin
if(rst = '1')then
st1 <= "000";
else
if(clk'event and clk = '1')then
st1 <= st1N;
end if;
end if;
end process;
-- Next state generation.
process(st1, trig_r)
begin
if(st1 = "000")then
if(trig_r = '1')then
st1N <= "001";
else
st1N <= "000";
end if;
elsif(st1 = "001")then
st1N <= "010";
elsif(st1 = "010")then
st1N <= "011";
elsif(st1 = "011")then
st1N <= "100";
elsif(st1 = "100")then
st1N <= "101";
elsif(st1 = "101")then
st1N <= "000";
else
st1N <= "000";
end if;
end process;
-- Output generation.
process(st1)
begin
if(st1 = "000")then
updPat <= '0';
cs <= '0';
elsif(st1 = "001")then
updPat <= '1';
cs <= '0';
elsif(st1 = "010")then
updPat <= '0';
cs <= '1';
elsif(st1 = "011")then
updPat <= '0';
cs <= '1';
elsif(st1 = "100")then
updPat <= '0';
cs <= '1';
elsif(st1 = "101")then
updPat <= '0';
cs <= '1';
else
end if;
end process;
--------------------------------------------------------------------------
-- Pattern generator and control circuit.
--------------------------------------------------------------------------
-- Generator control circuit.
process(clk, rst, updPat, patCtrl)
begin
if(rst = '1')then
patCtrl <= "111";
else
if(clk'event and clk = '1')then
if(updPat = '1')then
patCtrl <= patCtrl + "001";
else
patCtrl <= patCtrl;
end if;
end if;
end if;
end process;
-- Pattern storage.
process(patCtrl)
begin
if(patCtrl = "000")then
patOut <= "0001000100000000101010101";
elsif(PatCtrl = "001")then
patOut <= "0001000100000010101110111";
elsif(PatCtrl = "010")then
patOut <= "0001000100000000000000000";
elsif(PatCtrl = "011")then
patOut <= "0001000100000010000000000";
elsif(PatCtrl = "100")then
patOut <= "0011001101000110000000000";
elsif(PatCtrl = "101")then
patOut <= "0100010001000100000000000";
elsif(PatCtrl = "110")then
patOut <= "0101010100000100110011001";
else
patOut <= "0110011000000110000000000";
end if;
end process;
--------------------------------------------------------------------------
-- Rising edge detector.
--------------------------------------------------------------------------
-- Register 1
process(clk, trig)
begin
if(clk'event and clk = '1')then
rReg1 <= trig;
end if;
end process;
-- Register 2
process(clk, rReg1)
begin
if(clk'event and clk = '1')then
rReg2 <= rReg1;
end if;
end process;
trig_r <= rReg1 and (not rReg2);
--------------------------------------------------------------------------
-- Output connections.
--------------------------------------------------------------------------
-- Output mapping:
-- Address [24 .. 9]
-- Data [8 .. 1]
-- Wr/Rd [0]
Address(15 downto 0) <= patOut(24 downto 9);
DOut(7 downto 0) <= patOut(8 downto 1);
wr_rd <= patOut(0);
end Behavioral;