-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrivedsm.vhd
345 lines (277 loc) · 7.11 KB
/
contrivedsm.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
-- contrived state-machine example
library ieee;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
entity contrivedsm is
generic (
STATE_MACHINE_STYLE : string := "HYBRIDJOSYB" -- "TWOPROCESS" or "SYNCHRONOUS" or "HYBRID" or "HYBRIDJOSYB"
) ;
port (
Clk : in std_logic ;
Reset : in std_logic ;
A : in std_logic ;
B : in std_logic ;
C : in std_logic ;
Stage : out natural range 0 to 3 ;
DoneP : out std_logic
) ;
end contrivedsm ;
architecture arch of contrivedsm is
constant RANGE_COUNTER : natural := 1000 ;
type contrivedsm_states is ( S0 , S1 , S2 , S3 ) ;
component downcounter
generic (
COUNT_MAX : natural := 2 ** 30 - 1
) ;
port (
Clk : in std_logic;
Reset : in std_logic := '0';
SLoad : in std_logic;
Data : in natural range 0 to COUNT_MAX := COUNT_MAX;
CntEn : in std_logic := '1';
Q : out natural range 0 to COUNT_MAX;
IsOne : out std_logic;
IsZero : out std_logic
);
end component downcounter;
begin
gentwoprocess : if STATE_MACHINE_STYLE = "TWOPROCESS" generate
signal smn , smp : contrivedsm_states ;
signal countern , counterp : natural range 0 to RANGE_COUNTER ;
signal stagen , stagep : natural range 0 to 3 ;
signal donen : std_logic ;
begin
process( smp , A , B , C , counterp , stagep)
begin
donen <= '0' ;
stagen <= stagep ;
case smp is
when S0 =>
if (A = '1') then
smn <= S1 ;
countern <= 25 ;
stagen <= 1 ;
elsif (B = '1') then
smn <= S2 ;
countern <= 50 ;
stagen <= 2 ;
elsif (C = '1') then
smn <= S3 ;
countern <= 75 ;
stagen <= 3 ;
else
smn <= S0 ;
countern <= 0 ;
end if ;
when S1 =>
if (counterp = 0) then
smn <= S2 ;
countern <= 100 ;
stagen <= 2 ;
else
smn <= S1 ;
countern <= counterp - 1 ;
end if ;
when S2 =>
stagen <= 2 ;
if (counterp = 0) then
smn <= S3 ;
countern <= 200 ;
stagen <= 3 ;
else
smn <= S2 ;
countern <= counterp - 1 ;
end if ;
when S3 =>
stagen <= 3 ;
if (counterp = 0) then
smn <= S0 ;
countern <= 0 ;
donen <= '1' ;
stagen <= 0 ;
else
smn <= S3 ;
countern <= counterp - 1 ;
end if ;
end case ;
end process ;
process (Clk, Reset) is
begin
if (Reset = '1') then
smp <= S0 ;
counterp <= 0 ;
DoneP <= '0' ;
stagep <= 0 ;
elsif rising_edge(Clk) then
smp <= smn ;
counterp <= countern ;
DoneP <= donen ;
stagep <= stagen ;
end if;
end process ;
Stage <= stagep ;
end generate ;
gensynchronous: if STATE_MACHINE_STYLE = "SYNCHRONOUS" generate
signal sm : contrivedsm_states ;
signal counter : natural range 0 to RANGE_COUNTER ;
begin
process (Clk, Reset) is
begin
if (Reset = '1') then
sm <= S0 ;
counter <= 0 ;
DoneP <= '0' ;
Stage <= 0 ;
elsif rising_edge(Clk) then
DoneP <= '0' ;
case sm is
when S0 =>
if (A = '1') then
sm <= S1 ;
counter <= 25 ;
Stage <= 1 ;
elsif (B = '1') then
sm <= S2 ;
counter <= 50 ;
Stage <= 2 ;
elsif (C = '1') then
sm <= S3 ;
counter <= 75 ;
Stage <= 3 ;
end if ;
when S1 =>
if (counter = 0) then
sm <= S2 ;
counter <= 100 ;
Stage <= 2 ;
end if ;
when S2 =>
if (counter = 0) then
sm <= S3 ;
counter <= 200 ;
Stage <= 3 ;
end if ;
when S3 =>
if (counter = 0) then
sm <= S0 ;
DoneP <= '1' ;
Stage <= 0 ;
end if ;
end case ;
if ( counter /= 0) then
counter <= counter - 1 ;
end if ;
end if;
end process ;
end generate ;
genhybrid : if (STATE_MACHINE_STYLE = "HYBRID") or (STATE_MACHINE_STYLE = "HYBRIDJOSYB") generate
signal smhn , smhp : contrivedsm_states ;
signal counterh : natural range 0 to RANGE_COUNTER ;
signal counterhdata : natural range 0 to RANGE_COUNTER;
signal counterh_IsZero : std_logic ;
signal counterhsload : std_logic;
signal donen : std_logic ;
begin
process( smhp , A , B , C , counterh_IsZero)
begin
donen <= '0' ;
counterhdata <= 200 ;
counterhsload <= '0' ;
Stage <= 0 ;
case smhp is
when S0 =>
if (A = '1') then
smhn <= S1 ;
counterhdata <= 25 ;
counterhsload <= '1' ;
elsif (B = '1') then
smhn <= S2 ;
counterhdata <= 50 ;
counterhsload <= '1' ;
elsif (C = '1') then
smhn <= S3 ;
counterhdata <= 75 ;
counterhsload <= '1' ;
else
smhn <= S0 ;
end if ;
when S1 =>
Stage <= 1 ;
if (counterh_IsZero = '1') then
smhn <= S2 ;
counterhdata <= 100 ;
counterhsload <= '1' ;
else
smhn <= S1 ;
end if ;
when S2 =>
Stage <= 2 ;
if (counterh_IsZero = '1') then
smhn <= S3 ;
counterhsload <= '1' ;
else
smhn <= S2 ;
end if ;
when S3 =>
Stage <= 3 ;
if (counterh_IsZero = '1') then
smhn <= S0 ;
donen <= '1' ;
else
smhn <= S3 ;
end if ;
end case ;
end process ;
genclockedhybrid : if STATE_MACHINE_STYLE = "HYBRID" generate
process (Clk, Reset) is
begin
if (Reset = '1') then
smhp <= S0 ;
counterh <= 0 ;
counterh_IsZero <= '0' ;
DoneP <= '0' ;
elsif rising_edge(Clk) then
smhp <= smhn ;
DoneP <= donen ;
if (counterhsload = '1') or (counterh /= 0) then
if (counterhsload = '1') then
counterh <= counterhdata ;
counterh_IsZero <= '0' ;
else
counterh <= counterh - 1 ;
if (counterh = 1) then
counterh_IsZero <= '1' ;
end if ;
end if ;
end if ;
end if;
end process ;
end generate ;
genclockedhybridjosyb : if STATE_MACHINE_STYLE = "HYBRIDJOSYB" generate
process (Clk, Reset) is
begin
if (Reset = '1') then
smhp <= S0 ;
DoneP <= '0' ;
elsif rising_edge(Clk) then
smhp <= smhn ;
DoneP <= donen ;
end if;
end process ;
counterh : downcounter
generic map(
COUNT_MAX => RANGE_COUNTER
)
port map(
Clk => Clk,
Reset => Reset,
SLoad => counterhsload ,
Data => counterhdata ,
CntEn => '1' ,
Q => open ,
IsOne => open ,
IsZero => counterh_IsZero
);
end generate ;
end generate ;
end arch ;