-
Notifications
You must be signed in to change notification settings - Fork 4
/
MSDAP.v
1435 lines (1266 loc) · 27.5 KB
/
MSDAP.v
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
//
//
// Create Date: 11/26/2018
// Design Name: MSDAP
// Project Name: EEDG 6306 ASIC design Final Project
// Target Devices: ASIC
// Submitted by: Akash Anil Tadmare, Akshay Nandkumar Patil
// Submission Date: 12/15/2018
//
//
//////////////////////////////////////////////////////////////////////////////////
module top_level (Reset, Frame, Dclk, Sclk, InReady, OutReady, Start, InputL, InputR, OutputL, OutputR);//, OutputH );
input Frame, Reset, Sclk, Dclk, Start, InputL, InputR;
output InReady;
output OutReady;
//output [15:0] OutputRJ;
output OutputL,OutputR;
wire w1, w2, w3, w3L, w3R, w5L, w5R, w8L, w8R, w9, /*w11,*/ w12L, w12R, w13L,
w13R, w16L, w16R, w17, w19L, w19R, w20L, w20R, w21, w22, w23L, w23R, w24L,
w24R, w27L, w27R, w29, w29L, w29R, w30L, w30R, w31L, w31R, w32L, w32R, w33L, w33R, w34L, w34R, w35L, w35R, w36L, w36R, w37L, w37R, w38,
w40, w40L, w40R, w42, w43, w43L, w43R, /*w44,*/ w45 ;
wire [15:0]w4L, w4R, w10L, w10R, w18L, w18R, w28L, w28R;
wire [3:0]w6L, w6R, w7L,w7R;
wire [8:0]w14L, w14R, w15L, w15R;
wire [7:0]w25L, w25R, w26L, w26R, w39;
wire [39:0] w41L, w41R;
or2 inst_RJ_en_L (.a(w30L), .b(w31L), .out(w5L) );
or2 inst_RJ_en_R (.a(w30R), .b(w31R), .out(w5R) );
or2 inst_H_en_L (.a(w32L), .b(w33L), .out(w13L) );
or2 inst_H_en_R (.a(w32R), .b(w33R), .out(w13R) );
or3 inst_Write_Done_L (.a(w12L), .b(w19L), .c(w27L), .out(w20L) );
or3 inst_Write_Done_R (.a(w12R), .b(w19R), .c(w27R), .out(w20R) );
or3 inst_data_valid_L (.a(w34L), .b(w35L), .c(w36L), .out(w37L) );
or3 inst_data_valid_R (.a(w34R), .b(w35R), .c(w36R), .out(w37R) );
and2 inst_word_ready (.a(w3L), .b(w3R), .out(w3) );
and2 inst_sleep (.a(w29L), .b(w29R), .out(w29) );
and2 inst_prev_OutReady (.a(w40L), .b(w40R), .out(w40) );
and2 inst_word_sent (.a(w43L), .b(w43R), .out(w43));
SIPO SIPO_L (.Frame_edg(w2), .Reset(Reset), .rst(w1), .Dclk(Dclk), .data_in(InputL), .word_ready(w3L), .data_out(w4L), .received(w20L) );
SIPO SIPO_R (.Frame_edg(w2), .Reset(Reset), .rst(w1), .Dclk(Dclk), .data_in(InputR), .word_ready(w3R), .data_out(w4R), .received(w20R) );
RJmem rLmem (.Start(Start), .en(w5L), .rd_addr(w6L), .wr_addr(w7L), .wr(w8L), .rst(w9), .data_in(w4L), .data_out(w10L), .w_done(w12L), .data_valid(w36L) );
RJmem rRmem (.Start(Start), .en(w5R), .rd_addr(w6R), .wr_addr(w7R), .wr(w8R), .rst(w9), .data_in(w4R), .data_out(w10R), .w_done(w12R), .data_valid(w36R) );
Hmem hLmem (.Start(Start), .en(w13L), .rd_addr(w14L), .wr_addr(w15L), .wr(w16L), .rst(w17), .data_in(w4L), .data_out(w18L), .w_done(w19L), .data_valid(w35L) );
Hmem hRmem (.Start(Start), .en(w13R), .rd_addr(w14R), .wr_addr(w15R), .wr(w16R), .rst(w17), .data_in(w4R), .data_out(w18R), .w_done(w19R), .data_valid(w35R) );
Xmem xLmem (.Start(Start), .Reset(Reset), .rst(w22), .rd_en(w24L), .wr_en(w23L), .rd_addr(w26L), .wr_addr(w25L), .data_in(w4L), .data_out(w28L), .sleep(w29L),
.w_done(w27L), .data_valid(w34L) );
Xmem xRmem (.Start(Start), .Reset(Reset), .rst(w22), .rd_en(w24R), .wr_en(w23R), .rd_addr(w26R), .wr_addr(w25R), .data_in(w4R), .data_out(w28R), .sleep(w29R),
.w_done(w27R), .data_valid(w34R) );
ALU ALU_L (.Sclk(Sclk), .Reset(Reset), .en(w21), .Start(Start), .sleep(w29),
.RJ_en(w31L), .rr_ptr(w6L), .r_valid(w36L), .rj_data_in(w10L),
.H_en(w33L), .hr_ptr(w14L), .h_valid(w35L), .h_data_in(w18L),
.X_rd_en(w24L), .xr_ptr(w26L), /*.x_valid(w34L),*/ .x_data_in(w28L), .x_flagbit(w38), .n(w39),
.valid(w37L), .prev_OutReady(w40L), .y(w41L) );
ALU ALU_R (.Sclk(Sclk), .Reset(Reset), .en(w21), .Start(Start), .sleep(w29),
.RJ_en(w31R), .rr_ptr(w6R), .r_valid(w36R), .rj_data_in(w10R),
.H_en(w33R), .hr_ptr(w14R), .h_valid(w35R), .h_data_in(w18R),
.X_rd_en(w24R), .xr_ptr(w26R), /*.x_valid(w34R),*/ .x_data_in(w28R), .x_flagbit(w38), .n(w39),
.valid(w37R), .prev_OutReady(w40R), .y(w41R) );
PISO PISO_L (.en(w42), .Sclk(Sclk), .Start(Start), .data_in(w41L), .word_sent(w43L), .data_out(OutputL) );
PISO PISO_R (.en(w42), .Sclk(Sclk), .Start(Start), .data_in(w41R), .word_sent(w43R), .data_out(OutputR) );
controller CU (.Reset(Reset), .Frame(Frame), .Frame_edg(w2), .Start(Start), .InReady(InReady), .OutReady(OutReady), .Sclk(Sclk), .word_ready(w3),
.RJ_enL(w30L), .RJ_enR(w30R), .RJ_rst(w9), .RJ_wrL(w8L), .RJ_wrR(w8R), .rw_ptr_L(w7L), .rw_ptr_R(w7R),
.H_enL(w32L), .H_enR(w32R), .H_rst(w17), .H_wrL(w16L), .H_wrR(w16R), .hw_ptr_L(w15L), .hw_ptr_R(w15R),
.X_rst(w22), .X_wr_enL(w23L), .X_wr_enR(w23R), .xw_ptr_L(w25L), .xw_ptr_R(w25R), .x_flagbit(w38),
.ALU_en(w21), .n(w39), .prev_OutReady(w40),
.PISO_en(w42), .word_sent(w43),
.SIPO_rst(w1), .sleep(w29), .done_L(w20L), .done_R(w20R) );
//assign InReady = w11;
//assign OutReady = w45;
//assign OutputL = w44;
endmodule
module or3(a,b,c,out);
input a, b, c;
output out;
assign out = a | b | c;
endmodule
module or2(a,b,out);
input a, b;
output out;
assign out = a | b;
endmodule
module and2(a,b,out);
input a, b;
output out;
assign out = a & b;
endmodule
/****************SIPO*****************/
module SIPO (Frame_edg, rst, Reset, Dclk, data_in, word_ready, data_out, received);
input Frame_edg, Reset, Dclk, data_in, rst, received;
output reg word_ready;// = 1'b0;
output reg [15:0] data_out;// = 16'h0;
reg [3:0] bt;
always @ (negedge Dclk or posedge rst or posedge received or negedge Reset)
begin
if( Reset == 1'b0 )
begin
bt <= 4'h0;
data_out <= 16'h0000;
word_ready <= 1'b0;
end
else if( rst )
begin
bt <= 4'h0;
data_out <= 16'h0000;
word_ready <= 1'b0;
end
else if(received == 1'b1)
begin
if(word_ready== 1'b1)
begin
word_ready <= 1'b0;
end
end
else
begin
if (Frame_edg == 1'b1)
begin
if (bt == 4'h0)
begin
word_ready <= 1'b0;
end
data_out [bt] <= data_in;
{word_ready,bt} <= bt + 1'b1;
end
else
begin
word_ready <= 1'b0;
bt <= 4'h0;
end
end
end
endmodule
/*******RJmemory*******/
module RJmem (en, Start, rd_addr, wr_addr, wr, rst, data_in, data_out, w_done, data_valid );
input en, rst, wr, Start;
input [3:0] wr_addr, rd_addr;
input [15:0] data_in;
output reg w_done;
output reg data_valid;
output reg [15:0] data_out;
reg [15:0] MEM [15:0];
always @ (en or Start)
begin
if (Start== 1'b1)
begin
data_out = 16'h0000;
w_done = 1'b0;
data_valid = 1'b0;
end
else if(en== 1'b1)
begin
if (rst== 1'b1)
begin
MEM [wr_addr] = 16'h0000;
//#sclk
w_done = 1'b1;
end
else
begin
if (wr== 1'b1)
begin
MEM [wr_addr] = data_in[15:0];
//#30
w_done = 1'b1;
end
else
begin
data_out = MEM [rd_addr];
//#30
data_valid = 1'b1;
end
end
end
else
begin
w_done = 1'b0;
data_valid = 1'b0;
//data_out = 16'h0;
end
end
endmodule
/*******Hmemory*******/
module Hmem (en, Start, rd_addr, wr_addr, wr, rst, data_in, data_out, w_done, data_valid );
input en, rst, wr, Start;
input [8:0] wr_addr, rd_addr;
input [15:0] data_in;
output reg w_done;
output reg data_valid;
output reg [15:0] data_out;
reg [15:0] MEM [511:0];
always @ (Start or en)
begin
if(Start== 1'b1)
begin
w_done = 1'b0;
data_valid = 1'b0;
data_out = 16'h0000;
end
else if(en== 1'b1)
begin
if (rst== 1'b1)
begin
MEM [wr_addr] = 16'h0000;
//#sclk
w_done = 1'b1;
end
else
begin
if (wr== 1'b1)
begin
MEM [wr_addr] = data_in[15:0];
//#30
w_done = 1'b1;
end
else
begin
data_out = MEM [rd_addr];
//#30
data_valid = 1'b1;
end
end
end
else
begin
w_done = 1'b0;
data_valid = 1'b0;
//data_out = 16'h0;
end
end
endmodule
/*********************Xmemory**********************/
module Xmem (Start, Reset, rst, rd_addr, wr_addr, wr_en, rd_en, data_in, data_out, sleep, w_done, data_valid);
input Start, Reset,wr_en, rd_en, rst;
input [7:0] rd_addr, wr_addr;
input [15:0] data_in;
output reg w_done, sleep, data_valid;
output reg [15:0] data_out;
reg [15:0] MEM [255:0];
reg [11:0] sleep_count;
always @ (wr_en or Reset or Start)
begin
if(Reset == 1'b0)
begin
sleep = 1'b0;
sleep_count = 12'h0;
end
else if(Start== 1'b1)
begin
w_done = 1'b0;
sleep = 1'b0;
sleep_count = 12'h000;
end
else if(wr_en== 1'b1)
begin
if(rst== 1'b1)
begin
MEM [wr_addr] = 16'h0000;
w_done = 1'b1;
end
else
begin
MEM [wr_addr] = data_in;
//#30
if( data_in == 16'h0000 )
begin
sleep_count = sleep_count + 1'b1;
end
else
begin
sleep = 1'b0;
sleep_count = 12'h000;
end
if ( sleep_count == 12'h320 )
begin
sleep = 1'b1;
sleep_count = 12'h000;
end
w_done = 1'b1;
end
end
else
begin
w_done = 1'b0;
end
end
always @ (rd_en or Start)
begin
if(Start== 1'b1)
begin
data_out = 16'h0000;
data_valid = 1'b0;
end
else if(rd_en== 1'b1)
begin
data_out = MEM [rd_addr];
//#30
data_valid = 1'b1;
end
else
begin
data_valid = 1'b0;
//data_out = 16'h0;
end
end
endmodule
/*******************ALU****************************/
module ALU
(
Sclk, Reset, en, Start, sleep,
RJ_en, rr_ptr, r_valid, rj_data_in,
H_en, hr_ptr, h_valid, h_data_in,
X_rd_en, xr_ptr/*, x_valid*/, x_data_in, n, x_flagbit,
valid, prev_OutReady, y
);
input Sclk, Reset, en, valid, Start, x_flagbit, sleep;
output reg prev_OutReady;
output reg [39:0] y;
input r_valid;
input [15:0] rj_data_in;
output reg RJ_en;
output reg [3:0] rr_ptr;
reg [15:0] rj_data;
reg [4:0] rr_ptr_buff;
reg rj_read;
input h_valid;
input [15:0] h_data_in;
output reg H_en;
output reg [8:0] hr_ptr;
reg [15:0] h_data;
reg [8:0] hr_ptr_buff;
reg [7:0] h_cntr;
reg h_read, calc, h_finish, last_h, last_x;
//input x_valid;
input [15:0] x_data_in;
input [7:0] n;
output reg X_rd_en;
output reg [7:0] xr_ptr;
reg [15:0] x_data;
//reg [7:0] xr_ptr_buff;
reg x_read, x_finish;
reg [1:0] neg;
reg h_sign ;
reg [39:0] U ;
reg [39:0] U_curr ;
/* reg [1:0]state;
parameter Read_RJ = 2'h0;
parameter Read_H = 2'h1;
parameter Compute = 2'h2; */
//integer i = 0;
always @ (posedge Sclk or negedge Reset or posedge Start or posedge valid)
begin
if(Reset == 1'b0)
begin
RJ_en = 1'b0;
rr_ptr = 4'h0;
rj_data = 16'h0000;
rj_read = 1'b0;
H_en = 1'b0;
hr_ptr = 9'h000;
h_cntr = 8'h00;
h_data = 16'h0000;
h_read = 1'b0;
calc = 1'b0;
h_finish = 1'b0;
last_h = 1'b0;
X_rd_en = 1'b0;
xr_ptr = 8'h00;
x_read = 1'b0;
x_data = 16'h0000;
x_finish = 1'b0;
last_x = 1'b0;
U = 40'h0000000000;
U_curr = 40'h0000000000;
y = 40'h0000000000;
neg = 2'h0;
prev_OutReady = 1'b0;
end
else if(Start== 1'b1)
begin
RJ_en = 1'b0;
rr_ptr = 4'h0;
rj_data = 16'h0000;
rj_read = 1'b0;
H_en = 1'b0;
hr_ptr = 9'h000;
h_cntr = 8'h00;
h_data = 16'h0000;
h_read = 1'b0;
calc = 1'b0;
h_finish = 1'b0;
last_h = 1'b0;
X_rd_en = 1'b0;
xr_ptr = 8'h00;
x_read = 1'b0;
x_data = 16'h0000;
x_finish = 1'b0;
last_x = 1'b0;
U = 40'h0000000000;
U_curr = 40'h0000000000;
y = 40'h0000000000;
neg = 2'h0;
prev_OutReady = 1'b0;
end
else if(valid== 1'b1)
begin
RJ_en = 1'b0;
H_en = 1'b0;
X_rd_en = 1'b0;
end
else
begin
if(en== 1'b1)
begin
prev_OutReady = 1'b0;
if(sleep== 1'b0)
begin
if(x_read== 1'b1)
begin
if(neg[1]== 1'b0)
begin
x_data = x_data_in;
end
else
begin
x_data = 16'h0000;
end
x_read = 1'b0;
if ( h_sign== 1'b0 )
begin
U = U + {{8{x_data[15]}},x_data,{16{1'b0}}};//Add if positive
U_curr = U_curr + {{8{x_data[15]}},x_data,{16{1'b0}}};
end
else
begin
U = U - {{8{x_data[15]}},x_data,{16{1'b0}}};//Subtract if negative
U_curr = U_curr - {{8{x_data[15]}},x_data,{16{1'b0}}};
end
end
if(x_finish== 1'b1)
begin
//$display("U[%d] : %h", i,U_curr);
//i = i+1;
U = {U[39],U[39:1]};
U_curr = {40{1'b0}};
if(last_x == 1'b1)
begin
last_x = 1'b0;
y = U;
//i = 0;
//$display("Y : %h", y);
prev_OutReady = 1'b1;
calc = 1'b0;
end
x_finish = 1'b0;
end
if(h_finish== 1'b1)
begin
x_finish = 1'b1;
if(last_h== 1'b1)
begin
last_x = 1'b1;
end
h_finish = 1'b0;
end
if(h_read== 1'b1)
begin
h_data = h_data_in;
//H_en = 1'b0;
h_read = 1'b0;
calc = 1'b1;
end
if(calc== 1'b1)
begin
{neg,xr_ptr} = {x_flagbit, n} - h_data[7:0];
if( neg[1]== 1'b0 )
begin
X_rd_en = 1'b1;
//x_read = 1'b1;
end
h_sign = h_data[8];
x_read = 1'b1;
end
if(rj_read== 1'b1)
begin
rj_data = rj_data_in;
rj_read = 1'b0;
end
if(h_cntr != rj_data)
begin
hr_ptr = hr_ptr_buff;
H_en = 1'b1;
h_read = 1'b1;
h_cntr = h_cntr + 1'b1;
end
if(((h_cntr == rj_data) || (rr_ptr_buff == 4'h0)) && (last_h == 1'b0))
begin
if(rr_ptr == 4'hf)
begin
last_h = 1'b1;
h_finish = 1'b1;
rr_ptr = rr_ptr_buff;
end
else
begin
rr_ptr = rr_ptr_buff;
if(rr_ptr != 1'b0) //If not initial entry? then h_finished =1
begin
h_finish = 1'b1;
end
h_cntr = 8'h00;
RJ_en = 1'b1;
rj_read = 1'b1;
end
end
end
end
else
begin
RJ_en = 1'b0;
rr_ptr = 4'h0;
rj_data = 16'h0000;
rj_read = 1'b0;
H_en = 1'b0;
hr_ptr = 9'h000;
h_cntr = 8'h00;
h_data = 16'h0000;
h_read = 1'b0;
calc = 1'b0;
h_finish = 1'b0;
last_h = 1'b0;
X_rd_en = 1'b0;
x_read = 1'b0;
x_data = 16'h0000;
x_finish = 1'b0;
last_x = 1'b0;
U = 40'h0000000000;
U_curr = 40'h0000000000;
neg = 2'h0;
end
end
end
always @ (negedge Reset or posedge valid or posedge Start)
begin
if (Reset == 1'b0)
begin
rr_ptr_buff = 4'h0;
hr_ptr_buff = 9'h000;
//xr_ptr_buff = 8'h0;
end
else if(Start== 1'b1)
begin
rr_ptr_buff = 4'h0;
hr_ptr_buff = 9'h000;
//xr_ptr_buff = 8'h0;
end
else
begin
if (r_valid)
begin
rr_ptr_buff = rr_ptr + 1'b1;
end
/* if (x_valid)
begin
xr_ptr_buff = xr_ptr + 1'b1;
end */
if (h_valid)
begin
hr_ptr_buff = hr_ptr + 1'b1;
end
end
end
endmodule
/********************PISO**************************/
module PISO (en, Sclk, Start, data_in, word_sent, data_out);
input en, Sclk, Start;
input [39:0] data_in;
output reg word_sent, data_out;
reg [5:0] ybt;
reg [39:0] data;
always @ (posedge Sclk or posedge Start)
begin
if(Start)
begin
data = 40'h0000000000;
data_out = 1'b0;
ybt = 6'h00;
word_sent = 1'b0;
end
else
begin
if(en)
begin
data = data_in;
data_out = data[ybt];
ybt = ybt + 1'b1;
if(ybt == 6'h28)
begin
word_sent = 1'b1;
ybt = 6'h00;
end
end
else
begin
word_sent = 1'b0;
end
end
end
endmodule
/********************Controller********************/
module controller
(
Reset, Frame, Frame_edg, Start, InReady, Sclk, OutReady, word_ready,
RJ_enL, RJ_enR, RJ_rst, RJ_wrL, RJ_wrR, rw_ptr_L, rw_ptr_R,// r_done,
H_enL, H_enR, H_rst, H_wrL, H_wrR, hw_ptr_L, hw_ptr_R,// h_done,
X_wr_enL, X_wr_enR, X_rst, xw_ptr_L, xw_ptr_R, x_flagbit,
sleep, done_L, done_R,
ALU_en, n, prev_OutReady,
SIPO_rst,
PISO_en, word_sent
);
input Reset;
input Start;
input Sclk;
input word_ready, word_sent;
input Frame;
input done_L, done_R;
input sleep;
input prev_OutReady;
output reg Frame_edg;
output reg InReady;
output reg OutReady;
output reg SIPO_rst;
output reg ALU_en;
output reg PISO_en;
output reg RJ_enL, RJ_enR, RJ_rst, RJ_wrL, RJ_wrR;//, r_done;
output reg [3:0] rw_ptr_L, rw_ptr_R ;
reg [3:0] rw_ptr_buff_L, rw_ptr_buff_R;
reg R_clr_stop_L, R_clr_stop_R;
output reg H_enL, H_enR, H_rst, H_wrL, H_wrR;//, h_done;
output reg [8:0] hw_ptr_L, hw_ptr_R;
reg [8:0] hw_ptr_buff_L, hw_ptr_buff_R;
output reg X_rst, X_wr_enL, X_wr_enR;//, h_done;
output reg [7:0] xw_ptr_L, xw_ptr_R, n;
reg [8:0] xw_ptr_buff_L, xw_ptr_buff_R;
reg X_clr_stop_L, X_clr_stop_R;
output reg x_flagbit;
reg [3:0] state;
reg [3:0] next_state;
parameter state0 = 4'h0;
parameter state1 = 4'h1;
parameter state2 = 4'h2;
parameter state3 = 4'h3;
parameter state4 = 4'h4;
parameter state5 = 4'h5;
parameter state6 = 4'h6;
parameter state7 = 4'h7;
parameter state8 = 4'h8;
always @ (state or Frame or word_ready or Reset or Start or prev_OutReady or word_sent or sleep)
begin
if(Reset == 1'b0)
begin
next_state <= state7;
Frame_edg <= 1'b0;
OutReady = 1'b0;
ALU_en = 1'b0;
PISO_en = 1'b0;
end
else if (Start== 1'b1)
begin
ALU_en = 1'b0;
PISO_en = 1'b0;
OutReady = 1'b0;
//next_state <= state0;
end
else
begin
case ( state )
state0:
begin
if (R_clr_stop_L && R_clr_stop_R)
begin
next_state <= state1;
end
else
begin
next_state <= state0;
end
end
state1:
begin
if (Frame)
begin
next_state <= state2;
Frame_edg <= 1'b1;
end
else
begin
next_state <= state1;
end
end
state2:
begin
if (Frame)
begin
Frame_edg <= 1'b1;
end
else if (word_ready)
begin
Frame_edg <= 1'b0;
end
else
begin
next_state <= state2;
end
end
state3:
begin
if (Frame)
begin
next_state <= state4;
Frame_edg <= 1'b1;
end
else
begin
next_state <= state3;
end
end
state4:
begin
if (Frame)
begin
Frame_edg <= 1'b1;
end
else if (word_ready)
begin
Frame_edg <= 1'b0;
end
else
begin
next_state <= state4;
end
//H mem code
end
state5:
begin
if (Frame)
begin
next_state <= state6;
Frame_edg <= 1'b1;
end
else
begin
next_state <= state5;
end
end
state6:
begin
if (Frame)
begin
Frame_edg <= 1'b1;
if (prev_OutReady)
begin
PISO_en = 1'b1;
OutReady = 1'b1;
end
if( (|{x_flagbit,xw_ptr_buff_L}) )
begin
ALU_en = 1'b1;
end
end
else if (word_ready)
begin
Frame_edg <= 1'b0;
end
else if (prev_OutReady)
begin
ALU_en = 1'b0;
end
else if (word_sent)
begin
PISO_en = 1'b0;
OutReady = 1'b0;
end
else
begin
next_state <= state6;
end
end
state7:
begin
if(Reset)
begin
next_state <= state5;
end
end
state8:
begin
if (Frame)
begin
Frame_edg <= 1'b1;
if (prev_OutReady)
begin
PISO_en = 1'b1;
OutReady = 1'b1;
end
ALU_en = 1'b1;
end
else if (!sleep)
begin
ALU_en = 1'b0;
end
else if (word_ready)
begin
Frame_edg <= 1'b0;
end
else if (word_sent)
begin
PISO_en = 1'b0;
OutReady = 1'b0;
end
else
begin
next_state <= state8;
end
end
default:
begin
Frame_edg <= 1'b0;
OutReady = 1'b0;
ALU_en = 1'b0;
PISO_en = 1'b0;
end
endcase
end
end
always @ (posedge Start or posedge done_L or negedge Reset )// or posedge r_done or posedge h_done)
begin
if(Reset == 1'b0)
begin
xw_ptr_buff_L = 9'h000;
x_flagbit = 1'b0;
end
else if(Start== 1'b1)
begin
{R_clr_stop_L,rw_ptr_buff_L} = 5'h00;
hw_ptr_buff_L = 9'h000;
{X_clr_stop_L,xw_ptr_buff_L} = 9'h000;
x_flagbit = 1'b0;
end
else
begin
case (next_state)
state0:
begin
if(R_clr_stop_L == 1'b0)
begin
{R_clr_stop_L,rw_ptr_buff_L} = rw_ptr_L + 1'b1;
end
if(X_clr_stop_L == 1'b0)
begin
{X_clr_stop_L,xw_ptr_buff_L[7:0]} = xw_ptr_L + 1'b1;
end
hw_ptr_buff_L = hw_ptr_L + 1'b1;
end
state1:
begin
rw_ptr_buff_L = 4'h0;
xw_ptr_buff_L = 9'h000;
hw_ptr_buff_L = 9'h000;
end
state2:
begin
rw_ptr_buff_L = rw_ptr_L + 1'b1;
end
state3: