-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathdstruct_deque.vhdl
773 lines (745 loc) · 29.3 KB
/
dstruct_deque.vhdl
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
-- EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
-- vim: tabstop=2:shiftwidth=2:noexpandtab
-- kate: tab-width 2; replace-tabs off; indent-width 2;
-- =============================================================================
-- Authors: Jens Voss
--
-- Entity: Double-ended queue
--
-- Description:
-- -------------------------------------
-- Implements a deque (double-ended queue). This data structure allows two
-- acting entities to queue data elements for the consumption by the other while
-- still being able to unqueue untaken ones in LIFO fashion.
--
-- License:
-- =============================================================================
-- Copyright 2007-2016 Technische Universitaet Dresden - Germany
-- Chair of VLSI-Design, Diagnostics and Architecture
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- =============================================================================
library IEEE;
use IEEE.std_logic_1164.all;
entity dstruct_deque is
generic (
D_BITS : positive; -- Data Width
MIN_DEPTH : positive -- Minimum Deque Depth
);
port (
-- Shared Ports
clk, rst : in std_logic;
-- Port A
dinA : in std_logic_vector(D_BITS-1 downto 0); -- DataA Input
putA : in std_logic;
gotA : in std_logic;
doutA : out std_logic_vector(D_BITS-1 downto 0); -- DataA Output
validA : out std_logic;
fullA : out std_logic;
-- Port B
dinB : in std_logic_vector(D_BITS-1 downto 0); -- DataB Input
putB : in std_logic;
gotB : in std_logic;
doutB : out std_logic_vector(D_BITS-1 downto 0);
validB : out std_logic;
fullB : out std_logic
);
end entity dstruct_deque;
library IEEE;
use IEEE.numeric_std.all;
library PoC;
use PoC.config.all;
use PoC.utils.all;
use PoC.ocram.all;
architecture rtl of dstruct_deque is
-- Constants
constant A_BITS : natural := log2ceil(MIN_DEPTH);
-- MEMORY variable
-- type memory_t is array ((2**A_BITS)-1 downto 0) of std_logic_vector(D_BITS-1 downto 0);
-- signal memory : memory_t := (others => (others => '0'));
-- Signals
signal combined : std_logic_vector(3 downto 0) := (others => '0');
signal ctrl : std_logic_vector(1 downto 0) := (others => '1');
signal sub : unsigned(A_BITS-1 downto 0) := (others => '0');
-- last operation flag
signal last_operation : std_logic := '0'; -- save last operation 0 -> read, 1 -> write
type last_op_ctrl_t is (IDLE, SET, UNSET);
signal last_op_ctrl : last_op_ctrl_t := IDLE;
signal delayed_valid : std_logic := '0';
signal delay : std_logic := '0';
-- signal s_validA : std_logic := '0';
-- signal s_validB : std_logic := '0';
-- Stackpointer
-- A
signal stackpointerA : unsigned (A_BITS-1 downto 0) := shift_right(to_unsigned(MIN_DEPTH-1,A_BITS),1);
-- signal reA : std_logic := '0';
signal weA : std_logic := '0';
-- B
signal stackpointerB : unsigned (A_BITS-1 downto 0) := shift_right(to_unsigned(MIN_DEPTH-1,A_BITS),1) + 1;
-- signal reB : std_logic := '0';
signal weB : std_logic := '0';
-- ctrl signal for stackpointer operations
type ctrl_t is (PUSH, POP, IDLE);
signal ctrlA : ctrl_t := IDLE;
signal ctrlB : ctrl_t := IDLE;
-- RAM Signals
signal adrA : unsigned(A_BITS-1 downto 0) := (others => '0');
signal adrB : unsigned(A_BITS-1 downto 0) := (others => '0');
begin
ram : entity poc.ocram_tdp_wf
generic map(
A_BITS => A_BITS,
D_BITS => D_BITS,
FILENAME => ""
)
port map(
clk => clk,
ce => '1',
we1 => weA,
we2 => weB,
a1 => adrA,
a2 => adrB,
d1 => dinA,
d2 => dinB,
q1 => doutA,
q2 => doutB
);
sub <= stackpointerB - stackpointerA;
combined <= putA & gotA & putB & gotB;
process(combined, stackpointerA, stackpointerB, last_operation, ctrl)
begin
ctrlA <= IDLE;
ctrlB <= IDLE;
-- reA <= '1';
-- reB <= '1';
adrA <= stackpointerA + 1;
adrB <= stackpointerB - 1;
weA <= '0';
weB <= '0';
last_op_ctrl <= IDLE;
delay <= '0';
case(combined) is
when x"0" => --nothing
-- nothing happened/happens
-- don't update stackpointers
ctrlA <= IDLE;
ctrlB <= IDLE;
when x"1" => --readB
-- B read a valid value
-- update stackpointer
ctrlB <= POP;
-- reB <= '1';
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
if ctrl = "01" then
if(last_operation = '0') then
--> deque is empty!
-- B couldn't read a valid value => don't update SP!
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
last_op_ctrl <= UNSET;
end if;
elsif ctrl = "10" then
--> only one element left
-- side B saw empty signal
-- so B couldn't read a valid value
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
last_op_ctrl <= IDLE;
end if;
when x"2" => --writeB
ctrlB <= PUSH;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
if ctrl = "01" then
if(last_operation = '1') then
--> deque is full!
-- B cant write => don't update SP!
ctrlB <= IDLE;
weB <= '0';
adrB <= stackpointerB - 1;
else
--> deque is empty!
--> delay validA signal for one clk cycle
delay <= '1';
end if;
elsif ctrl = "00" then
--> only one spot left
-- B isn't allowed to write
-- B sees full signal atm
weB <= '0';
adrB <= stackpointerB - 1;
ctrlB <= IDLE;
end if;
when x"3" => --readB, writeB
-- B read a valid value and writes a new value at the same spot
-- don't update stackpointer
-- reB <= '1';
adrB <= stackpointerB - 1;
weB <= '1';
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- B read a valid value but new value cant be pushed!
ctrlB <= POP;
weB <= '0';
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- B couldn't read a valid value, but new value can be written!
-- delay validA signal one clk cycle
ctrlB <= PUSH;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
delay <= '1';
end if;
elsif ctrl = "10" then
--> only one element left
-- B couldn't read it, but can write new value
ctrlB <= PUSH;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
elsif ctrl = "00" then
-- only one spot left
-- B read a valid value but cant write new value
ctrlB <= POP;
weB <= '0';
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
end if;
when x"4" => --readA
-- A read a valid values
-- update stackpointer
ctrlA <= POP;
-- reA <= '1';
adrA <= stackpointerA + 2;
last_op_ctrl <= UNSET;
if (ctrl = "01" and last_operation = '0') then
--> deque is empty!
-- A couldn't read a valid value => don't update SP!
ctrlA <= IDLE;
adrA <= stackpointerA + 1;
end if;
when x"5" => --readA, readB
-- A and B read both valid values
-- update both stackpointers
ctrlA <= POP;
ctrlB <= POP;
-- reB <= '1';
adrB <= stackpointerB - 2;
-- reA <= '1';
adrA <= stackpointerA + 2;
last_op_ctrl <= UNSET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full
-- A and B read a valid value!
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- A and B couldn't a valid value => don't update SP!
ctrlB <= IDLE;
ctrlA <= IDLE;
adrA <= stackpointerA + 1;
adrB <= stackpointerB - 1;
end if;
elsif ctrl = "10" then
-- A and B both tried to read last value!
-- but only A was allowed to read value so only update stackpointerA
ctrlA <= POP;
ctrlB <= IDLE;
end if;
when x"6" => --readA, writeB
-- A read a valid value and B writes a new value
-- update both stackpointers
ctrlA <= POP;
ctrlB <= PUSH;
-- reA <= '1';
adrA <= stackpointerA + 2;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
if ctrl = "01" then
if(last_operation = '1') then
--> deque is full!
-- A read a valid value, but B cant push!
ctrlB <= IDLE;
weB <= '0';
last_op_ctrl <= UNSET;
adrB <= stackpointerB - 1;
else
--> deque is empty!
-- A couldn't read a valid value, but B can push!
-- delay validA signal one clk cycle
ctrlA <= IDLE;
adrA <= stackpointerA + 1;
last_op_ctrl <= SET;
delay <= '1';
end if;
elsif ctrl = "10" then
--> only one element in deque
--> A read valid value and B can write new value
--> But validA has to be delayed!
delay <= '1';
elsif ctrl = "00" then
--> only one spot left
-- A read valid value, but B isn't allowed to write last value
ctrlB <= IDLE;
weB <= '0';
last_op_ctrl <= UNSET;
adrB <= stackpointerB - 1;
end if;
when x"7" => --readA, readB, writeB
-- A and B read valid values and B writes a new value at the same spot
-- Update stackpointerA and don't update stackpointer B
ctrlA <= POP;
adrB <= stackpointerB - 1;
-- reB <= '1';
weB <= '1';
adrA <= stackpointerA + 2;
-- reA <= '1';
last_op_ctrl <= SET;
if ctrl = "01" then
if last_operation = '1' then
--> deque is full!
-- A and B read a valid value, but B cant push!
ctrlB <= POP;
weB <= '0';
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- A and B couldn't have read a valid value, but B can push!
-- delay validA signal one clk cycle
adrA <= stackpointerA + 1;
ctrlA <= IDLE;
ctrlB <= PUSH;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
delay <= '1';
end if;
elsif ctrl = "00" then
--> only one spot left
-- A and B read valid values, but B isn't allowed to write new value
-- B sees full signal atm
ctrlB <= POP;
weB <= '0';
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
elsif ctrl = "10" then
--> only one element in deque
-- only A read a valid value, but B can write a new value
--> validA has to be delayed!
ctrlB <= PUSH;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
delay <= '1';
end if;
when x"8" => --writeA
-- A writes a new value
-- update stackpointer
ctrlA <= PUSH;
weA <= '1';
adrA <= stackpointerA;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full
-- A cant write!
ctrlA <= IDLE;
weA <= '0';
adrA <= stackpointerA + 1;
end if;
end if;
when x"9" => --writeA, readB
-- A writes new value and B reads a valid value
-- update both stackpointers
ctrlA <= PUSH;
ctrlB <= POP;
-- reB <= '1';
weA <= '1';
adrA <= stackpointerA;
adrB <= stackpointerB - 2;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A cant write, but B read a valid value!
weA <= '0';
ctrlA <= IDLE;
adrA <= stackpointerA + 1;
last_op_ctrl <= SET;
else
--> deque is empty!
-- A can write, but B couldn't read a valid value!
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
last_op_ctrl <= SET;
end if;
elsif ctrl = "10" then
--> only one element left
-- A can write new value, but B couldn't read a valid value
-- B sees empty signal atm
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
last_op_ctrl <= SET;
end if;
when x"A" => --writeA, writeB
-- A and B write new values
-- update both Stackpointers
ctrlA <= PUSH;
ctrlB <= PUSH;
weA <= '1';
adrA <= stackpointerA;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A and B cant write!
ctrlA <= IDLE;
ctrlB <= IDLE;
weA <= '0';
weB <= '0';
adrB <= stackpointerB - 1;
adrA <= stackpointerA + 1;
last_op_ctrl <= UNSET;
else
--> deque is empty!
--> A and B can write!
last_op_ctrl <= SET;
end if;
elsif ctrl = "00" then
--> only one spot left.
-- only A is allowed to write
-- B got full signal
weB <= '0';
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
end if;
when x"B" => --writeA, readB, writeB
--> A writes a value and B read a valid value and writes a new value at the same spot!
-- update stackpointerA and don't update stackpointerB
ctrlA <= PUSH;
weA <= '1';
adrA <= stackpointerA;
-- reB <= '1';
weB <= '1';
adrB <= stackpointerB - 1;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A and B cant write, but B read a valid value!
ctrlB <= POP;
ctrlA <= IDLE;
weA <= '0';
weB <= '0';
adrA <= stackpointerA + 1;
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
else
--> deque is empty
--> A and B can write, but B couldn't read a valid value!
ctrlB <= PUSH;
adrB <= stackpointerB;
last_op_ctrl <= SET;
end if;
elsif ctrl = "00" then
--> only one spot left
-- only A can write last value
-- B only read a valid value
ctrlB <= POP;
weB <= '0';
adrB <= stackpointerB - 2;
elsif ctrl = "10" then
--> only one element left
--> B couldn't read value but A and B are allowed to write new values
ctrlB <= PUSH;
adrB <= stackpointerB;
last_op_ctrl <= SET;
end if;
when x"C" => --readA, writeA
--> A read a valid value and writes a new value at the same spot!
-- => don't update stackpointer!
ctrlA <= IDLE;
-- reA <= '1';
weA <= '1';
adrA <= stackpointerA + 1;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A cant write, but read a valid value!
ctrlA <= POP;
weA <= '0';
adrA <= stackpointerA + 2;
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- A can write, but couldn't read a valid value!
ctrlA <= PUSH;
adrA <= stackpointerA;
last_op_ctrl <= SET;
end if;
end if;
when x"D" => --readA, writeA, readB
-- A and B read valid values and A writes a new value at the same spot
-- don't update stackpointerA and update stackpointerB
ctrlB <= POP;
ctrlA <= IDLE;
-- reA <= '1';
weA <= '1';
adrA <= stackpointerA + 1;
-- reB <= '1';
adrB <= stackpointerB - 2;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A cant write new values, but A and B could read a valid value
ctrlA <= POP;
ctrlB <= POP;
adrA <= stackpointerA + 2;
weA <= '0';
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- A and B couldn't read a valid value, but A can write a new value
ctrlA <= PUSH;
adrB <= stackpointerB - 1;
ctrlB <= IDLE;
adrA <= stackpointerA;
last_op_ctrl <= SET;
end if;
elsif ctrl = "10" then
--> only one element in deque
-- only A read valid value and can write a new value
adrB <= stackpointerB - 1;
ctrlB <= IDLE;
ctrlA <= IDLE;
adrA <= stackpointerA + 1;
last_op_ctrl <= SET;
end if;
when x"E" => --readA, writeA, writeB
-- B writes a new value, A read a valid value and writes a new value at the same spot
-- update stackpiunterB and don't update stackpointerA
ctrlB <= PUSH;
ctrlA <= IDLE;
-- reA <= '1';
weA <= '1';
adrA <= stackpointerA + 1;
weB <= '1';
adrB <= stackpointerB;
last_op_ctrl <= SET;
if ctrl = "01" then
if (last_operation = '1') then
--> deque is full!
-- A and B cant write, but A could read valid value
weA <= '0';
weB <= '0';
ctrlA <= POP;
ctrlB <= IDLE;
adrB <= stackpointerB - 1;
adrA <= stackpointerA + 2;
last_op_ctrl <= UNSET;
else
--> deque is empty!
-- A couldn't read a valid value, but A and B can write new values
ctrlA <= PUSH;
ctrlB <= PUSH;
adrA <= stackpointerA;
last_op_ctrl <= SET;
end if;
elsif ctrl = "00" then
--> only one spot left
-- B cant write new value
ctrlB <= IDLE;
weB <= '0';
adrB <= stackpointerB - 1;
end if;
when x"F" => --readA, writeA,readB, writeB
-- A and B read valid values and write new values at the same stackpointers
-- don't update both stackpointers
ctrlA <= IDLE;
ctrlB <= IDLE;
-- reA <= '1';
weA <= '1';
adrA <= stackpointerA + 1;
weB <= '1';
-- reB <= '1';
adrB <= stackpointerB - 1;
last_op_ctrl <= SET;
if ctrl = "01" then
if last_operation = '1' then
--> deque is full
-- A and B could read valid values but cant write new values
ctrlA <= POP;
ctrlB <= POP;
weA <= '0';
weB <= '0';
adrA <= stackpointerA + 2;
adrB <= stackpointerB - 2;
last_op_ctrl <= UNSET;
else
--> deque is empty
-- A and B couldn't read valid values but can both write new values
ctrlA <= PUSH;
ctrlB <= PUSH;
adrA <= stackpointerA;
adrB <= stackpointerB;
last_op_ctrl <= SET;
end if;
elsif ctrl = "10" then
--> only one element left
-- only A read last value, A replaces the last element
-- B just writes new value
-- B sees empty signal atm
ctrlB <= PUSH;
adrB <= stackpointerB;
elsif ctrl = "00" then
--> only one spot left
-- B read a valid value, but isn't allowed to write
-- B sees full signal atm
ctrlB <= POP;
adrB <= stackpointerB - 2;
weB <= '0';
end if;
when others => --nothing
-- nothing happened/happens
-- don't update stackpointers
last_op_ctrl <= IDLE;
end case;
end process;
process(clk)
begin
if rising_edge(clk) then
if (rst = '1') then
last_operation <= '0';
else
case( last_op_ctrl ) is
when IDLE =>
last_operation <= last_operation;
when SET =>
last_operation <= '1';
when UNSET =>
last_operation <= '0';
when others =>
last_operation <= last_operation;
end case;
end if;
end if;
end process;
--stackpointerA operations
process(clk)
begin
if rising_edge(clk) then
if (rst = '1') then
stackpointerA <= shift_right(to_unsigned(MIN_DEPTH-1,A_BITS),1);
else
case( ctrlA ) is
when IDLE =>
stackpointerA <= stackpointerA;
when PUSH =>
stackpointerA <= stackpointerA - 1;
when POP =>
stackpointerA <= stackpointerA + 1;
when others =>
stackpointerA <= stackpointerA;
end case;
end if;
end if;
end process;
-- stackpointerB operations
process(clk)
begin
if rising_edge(clk) then
if (rst = '1') then
stackpointerB <= shift_right(to_unsigned(MIN_DEPTH-1,A_BITS),1) + 1;
else
case( ctrlB ) is
when IDLE =>
stackpointerB <= stackpointerB;
when PUSH =>
stackpointerB <= stackpointerB + 1;
when POP =>
stackpointerB <= stackpointerB - 1;
when others =>
stackpointerB <= stackpointerB;
end case;
end if;
end if;
end process;
-- delayed_valid register
process(clk)
begin
if rising_edge(clk) then
if(rst = '1') then
delayed_valid <= '0';
else
if (delay = '1') then
delayed_valid <= '1';
else
delayed_valid <= '0';
end if;
end if;
end if;
end process;
-- sub of B and A
process(sub, last_operation, delayed_valid)
begin
fullA <= '0';
fullB <= '0';
validB <= '1';
if(delayed_valid = '1') then
validA <= '0';
else
validA <= '1';
end if;
case(to_integer(sub)) is
when 0 =>
ctrl <= "00"; -- let a or b write?
-- only one spot left
-- set one side to full!
-- at the moment A has higher priority
fullB <= '1';
when 1 =>
ctrl <= "01"; -- empty or full?
if (last_operation = '1') then
fullA <= '1';
fullB <= '1';
else
validA <= '0';
validB <= '0';
end if;
when 2 =>
ctrl <= "10"; -- let a or b read?
-- only one element left
-- set one side to empty!
-- at the moment A has higher priority
validB <= '0';
when 3 =>
ctrl <= "11"; -- both can write/read
when others =>
ctrl <= "11";
end case;
end process;
end architecture;