-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIM.vhd
240 lines (204 loc) · 4.61 KB
/
TIM.vhd
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use WORK.MP_PACK.ALL;
entity TIM is
Port ( NEXT_FETCH : in STD_LOGIC;
CLK : in STD_LOGIC;
RESET : in STD_LOGIC;
MEM_R_W : in STD_LOGIC;
HALT : in STD_LOGIC;
LD_PC : out STD_LOGIC;
P_D : out STD_LOGIC;
RDBAR : out STD_LOGIC;
WRBAR : out STD_LOGIC;
INC_PC : out STD_LOGIC;
LD_IR : out STD_LOGIC;
MC_STATES : out MACHINE_STATES;
LD_STATES : out STD_LOGIC);
end TIM;
architecture Behavioral of TIM is
type TIM_STATES is (init, FET_T1, FET_T2, FET_T3, FET_T4, FET2_T1, FET2_T2, FET2_T3, FET2_T4, MEM_T1, MEM_T2, MEM_T3, MEM_T4, haltd);
signal STATE : TIM_STATES := init;
begin
process begin
wait on RESET , CLK;
if RESET = '0' then
LD_PC <= 'U';
P_D <= 'U';
RDBAR <= 'U';
WRBAR <= 'U';
INC_PC <= 'U';
LD_IR <= 'U';
LD_STATES <= 'U';
MC_STATES <= S0;
STATE <= init;
elsif RESET'EVENT then
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S0;
STATE <= init;
elsif CLK'EVENT and CLK = '1' then
case STATE is
when init =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S1;
STATE <= FET_T1;
when FET_T1 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S1;
STATE <= FET_T2;
when FET_T2 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '0';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '1';
LD_STATES <= '0';
MC_STATES <= S1;
STATE <= FET_T3;
when FET_T3 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '1';
LD_IR <= '0';
LD_STATES <= '1';
MC_STATES <= S1;
STATE <= FET_T4;
when FET_T4 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S1;
if HALT = '1' then
STATE <= haltd;
elsif NEXT_FETCH = '1' then
STATE <= FET2_T1;
else
STATE <= FET_T1;
end if;
when FET2_T1 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S2;
STATE <= FET2_T2;
when FET2_T2 =>
LD_PC <= '1';
P_D <= '1';
RDBAR <= '0';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S2;
STATE <= FET2_T3;
when FET2_T3 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '1';
LD_IR <= '0';
LD_STATES <= '1';
MC_STATES <= S2;
STATE <= FET2_T4;
when FET2_T4 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S2;
STATE <= MEM_T1;
when MEM_T1 =>
LD_PC <= '0';
P_D <= '1';
RDBAR <= '1';
WRBAR <= '1';
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S3;
STATE <= MEM_T2;
when MEM_T2 =>
LD_PC <= '0';
P_D <= '0';
if MEM_R_W = '0' then
RDBAR <= '0';
WRBAR <= '1';
else
RDBAR <= '1';
WRBAR <= '0';
end if;
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S3;
STATE <= MEM_T3;
when MEM_T3 =>
LD_PC <= '0';
P_D <= '0';
if MEM_R_W = '0' then
RDBAR <= '0';
WRBAR <= '1';
else
RDBAR <= '1';
WRBAR <= '0';
end if;
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '1';
MC_STATES <= S3;
STATE <= MEM_T4;
when MEM_T4 =>
LD_PC <= '0';
P_D <= '0';
if MEM_R_W = '0' then
RDBAR <= '0';
WRBAR <= '1';
else
RDBAR <= '1';
WRBAR <= '0';
end if;
INC_PC <= '0';
LD_IR <= '0';
LD_STATES <= '0';
MC_STATES <= S3;
STATE <= FET_T1;
when haltd =>
MC_STATES <= S0;
report "I: uP Halted";
end case;
end if;
end process;
end Behavioral;