-
Notifications
You must be signed in to change notification settings - Fork 0
/
Milestone_2.v
602 lines (450 loc) · 12.5 KB
/
Milestone_2.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
/*
Copyright by Henry Ko and Nicola Nicolici
Developed for the Digital Systems Design course (COE3DQ4)
Department of Electrical and Computer Engineering
McMaster University
Ontario, Canada
*/
`timescale 1ns/100ps
`default_nettype none
`include "define_state.h"
//Module responsible for coordinating the FIR and RGB Converter
module Milestone_2 (
/////// board clocks ////////////
input logic CLOCK_50_I, // 50 MHz clock
input logic Resetn,
output logic [17:0] SRAM_address,
output logic [15:0] SRAM_write_data,
input logic [15:0] SRAM_read_data,
output logic SRAM_we_n,
output logic M2_done,
input logic M2_start
);
M2_state_type state;
logic common_case;
logic [5:0] SC, CB, C_END;
logic [4:0] RB;
logic [17:0] Y_address, U_address, V_address, Base_address;
logic [31:0] RAM0_write_data[1:0];
logic [31:0] RAM0_read_data[1:0];
logic [6:0] RAM0_address[1:0];
logic RAM0_write_enable[1:0];
logic [31:0] RAM1_write_data;
logic [31:0] RAM1_read_data[1:0];
logic [6:0] RAM1_address;
logic RAM1_write_enable;
logic [31:0] RAM2_read_data[1:0];
logic [6:0] RAM2_address[1:0];
//Milestone 3
logic [17:0] M3_SRAM_address;
logic [15:0] M3_SRAM_read_data;
logic [15:0] M3_SRAM_write_data;
logic M3_SRAM_we_n;
logic M3_done;
logic M3_memory_end;
logic M3_start;
logic [31:0] RAM3_write_data;
logic [31:0] RAM3_read_data[1:0];
logic [6:0] RAM3_address[1:0];
logic RAM3_write_enable;
//Fetch S'
logic [31:0] FS_write_data;
logic [6:0] FS_write_address;
logic FS_write_enable;
logic FS_done;
logic FS_memory_end;
logic FS_start;
logic [17:0] FS_SRAM_address;
logic [15:0] FS_SRAM_read_data;
//Compute T
logic MM_CT_done, MM_CT_start;
logic [31:0] MM_CT_RAM0_read_data;
logic [6:0] MM_CT_RAM0_address;
logic MM_CT_RAM0_write_enable;
logic [31:0] MM_CT_RAM2_read_data [1:0];
logic [6:0] MM_CT_RAM2_address [1:0];
logic [31:0] MM_CT_RAM1_write_data;
logic [6:0] MM_CT_RAM1_address;
logic MM_CT_RAM1_write_enable;
//Compute S
logic MM_CS_done, MM_CS_start;
logic [31:0] MM_CS_RAM1_read_data;
logic [6:0] MM_CS_RAM1_address;
logic MM_CS_RAM1_write_enable;
logic [31:0] MM_CS_RAM2_read_data [1:0];
logic [6:0] MM_CS_RAM2_address [1:0];
logic [31:0] MM_CS_RAM0_write_data;
logic [6:0] MM_CS_RAM0_address;
logic MM_CS_RAM0_write_enable;
//Write S
logic WS_done, WS_start;
logic [31:0] WS_DPRAM0_read_data;
logic [6:0] WS_DPRAM0_read_address;
logic WS_DPRAM0_write_enable;
logic [17:0] WS_SRAM_address;
logic [15:0] WS_SRAM_write_data;
logic WS_SRAM_we_n;
logic WS_memory_end;
always_ff @ (posedge CLOCK_50_I or negedge Resetn) begin
if (Resetn == 1'b0) begin
state <= S_M2_IDLE;
//FS_start <= 1'b0;
MM_CT_start <= 1'b0;
MM_CS_start <= 1'b0;
WS_start <= 1'b0;
M2_done <= 1'b0;
M3_start <= 1'b0;
end else begin
case (state)
S_M2_IDLE: begin
if (M2_start) begin
state <= S_M2_START;
end
end
S_M2_START: begin
M3_start <= 1'b1;
//FS_start <= 1'b1;
state <= S_FS;
end
S_FS: begin //First Run of M3
M3_start <= 1'b0;
if (M3_done) begin
MM_CT_start <= 1'b1;
state <= S_CT;
end
/* FS_start <= 1'b0;
if (FS_done) begin
MM_CT_start <= 1'b1;
state <= S_CT;
end */
end
S_CT: begin
if (MM_CT_done) begin
//FS_start <= 1'b1;
M3_start <= 1'b1;
MM_CT_start <= 1'b0;
MM_CS_start <= 1'b1;
state <= S_CS;
end else begin
//FS_start <= 1'b0;
M3_start <= 1'b0;
MM_CT_start <= 1'b0;
WS_start <= 1'b0;
end
end
S_CS: begin
if (MM_CS_done) begin
MM_CS_start <= 1'b0;
WS_start <= 1'b1;
//if (FS_memory_end) begin
if (M3_memory_end) begin
state <= S_WS;
end else begin
MM_CT_start <= 1'b1;
state <= S_CT;
end
end else begin
MM_CS_start <= 1'b0;
//FS_start <= 1'b0;
M3_start <= 1'b0;
MM_CT_start <= 1'b0;
WS_start <= 1'b0;
end
end
S_WS: begin
WS_start <= 1'b0;
if (WS_done && WS_memory_end) begin
M2_done <= 1'b1;
state <= S_M2_IDLE;
end
end
default: state <= S_M2_IDLE;
endcase
end
end
//Multiplex memory access
always_comb begin
case (state)
S_FS: begin
//SRAM ACCESS
//SRAM_address = FS_SRAM_address;
SRAM_address = M3_SRAM_address;
SRAM_write_data = 16'd0;
SRAM_we_n = 1'd1;
//DPRAM ACCESS
/*
RAM0_write_data[1] = FS_write_data;
RAM0_address[1] = FS_write_address;
RAM0_write_enable[1] = FS_write_enable;*/
RAM0_write_data[1] = 32'd0; //RAM3_write_data;
RAM0_address[1] = 7'd0; //RAM3_address[1];
RAM0_write_enable[1] = 1'b0; //RAM3_write_enable;
RAM0_write_data[0] = 32'd0;
RAM0_address[0] = 7'd0;
RAM0_write_enable[0] = 1'd0;
RAM1_write_data = 32'd0;
RAM1_address = 7'd0;
RAM1_write_enable = 1'd0;
RAM2_address[0] = 7'd0;
RAM2_address[1] = 7'd0;
RAM3_address[0] = 7'd0;
//FS ACCESS
//FS_SRAM_read_data = SRAM_read_data;
M3_SRAM_read_data = SRAM_read_data;
//CT ACCESS
MM_CT_RAM0_read_data = 32'd0;
MM_CT_RAM2_read_data[0] = 32'd0;
MM_CT_RAM2_read_data[1] = 32'd0;
//CS ACCESS
MM_CS_RAM1_read_data = 32'd0;
MM_CS_RAM2_read_data[0] = 32'd0;
MM_CS_RAM2_read_data[1] = 32'd0;
//WS ACCESS
WS_DPRAM0_read_data = 32'd0;
end
S_CT: begin
//SRAM ACCESS
SRAM_address = WS_SRAM_address;
SRAM_write_data = WS_SRAM_write_data;
SRAM_we_n = WS_SRAM_we_n;
//DPRAM ACCESS
RAM0_write_data[1] = 32'd0;
RAM0_address[1] = 7'd0;//MM_CT_RAM0_address;
RAM0_write_enable[1] = 1'd0;
RAM0_write_data[0] = 32'd0;
RAM0_address[0] = WS_DPRAM0_read_address;
RAM0_write_enable[0] = 1'd0;
RAM1_write_data = MM_CT_RAM1_write_data;
RAM1_address = MM_CT_RAM1_address;
RAM1_write_enable = MM_CT_RAM1_write_enable;
RAM2_address[0] = MM_CT_RAM2_address[0];
RAM2_address[1] = MM_CT_RAM2_address[1];
RAM3_address[0] = MM_CT_RAM0_address;
//FS ACCESS
//FS_SRAM_read_data = 16'd0;
M3_SRAM_read_data = 16'd0;
//CT ACCESS
MM_CT_RAM0_read_data = RAM3_read_data[0];//RAM0_read_data[1];
MM_CT_RAM2_read_data[0] = RAM2_read_data[0];
MM_CT_RAM2_read_data[1] = RAM2_read_data[1];
//CS ACCESS
MM_CS_RAM1_read_data = 32'd0;
MM_CS_RAM2_read_data[0] = 32'd0;
MM_CS_RAM2_read_data[1] = 32'd0;
//WS ACCESS
WS_DPRAM0_read_data = RAM0_read_data[0];
end
S_CS: begin
//SRAM ACCESS
//SRAM_address = FS_SRAM_address;
SRAM_address = M3_SRAM_address;
SRAM_write_data = 16'd0;
SRAM_we_n = 1'd1;
//DPRAM ACCESS
/*
RAM0_write_data[1] = FS_write_data;
RAM0_address[1] = FS_write_address;
RAM0_write_enable[1] = FS_write_enable;
*/
RAM0_write_data[1] = 32'd0;//RAM3_write_data;
RAM0_address[1] = 7'd0;//RAM3_address[1];
RAM0_write_enable[1] = 1'd0;//RAM3_write_enable;
RAM0_write_data[0] = MM_CS_RAM0_write_data;
RAM0_address[0] = MM_CS_RAM0_address;
RAM0_write_enable[0] = MM_CS_RAM0_write_enable;
RAM1_write_data = 32'd0;
RAM1_address = MM_CS_RAM1_address;
RAM1_write_enable = 1'd0;
RAM2_address[0] = MM_CS_RAM2_address[0];
RAM2_address[1] = MM_CS_RAM2_address[1];
RAM3_address[0] = 7'd0;
//FS ACCESS
//FS_SRAM_read_data = SRAM_read_data;
M3_SRAM_read_data = SRAM_read_data;
//CT ACCESS
MM_CT_RAM0_read_data = 32'd0;
MM_CT_RAM2_read_data[0] = 32'd0;
MM_CT_RAM2_read_data[1] = 32'd0;
//CS ACCESS
MM_CS_RAM1_read_data = RAM1_read_data[0];
MM_CS_RAM2_read_data[0] = RAM2_read_data[0];
MM_CS_RAM2_read_data[1] = RAM2_read_data[1];
//WS ACCESS
WS_DPRAM0_read_data = 32'd0;
end
S_WS: begin
//SRAM ACCESS
SRAM_address = WS_SRAM_address;
SRAM_write_data = WS_SRAM_write_data;
SRAM_we_n = WS_SRAM_we_n;
//DPRAM ACCESS
RAM0_write_data[1] = 32'd0;
RAM0_address[1] = 7'd0;
RAM0_write_enable[1] = 1'd0;
RAM0_write_data[0] = 32'd0;
RAM0_address[0] = WS_DPRAM0_read_address;
RAM0_write_enable[0] = 1'd0;
RAM1_write_data = 32'd0;
RAM1_address = 7'd0;
RAM1_write_enable = 1'd0;
RAM2_address[0] = 7'd0;
RAM2_address[1] = 7'd0;
RAM3_address[0] = 7'd0;
//FS ACCESS
//FS_SRAM_read_data = 16'd0;
M3_SRAM_read_data = 16'd0;
//CT ACCESS
MM_CT_RAM0_read_data = 32'd0;
MM_CT_RAM2_read_data[0] = 32'd0;
MM_CT_RAM2_read_data[1] = 32'd0;
//CS ACCESS
MM_CS_RAM1_read_data = 32'd0;
MM_CS_RAM2_read_data[0] = 32'd0;
MM_CS_RAM2_read_data[1] = 32'd0;
//WS ACCESS
WS_DPRAM0_read_data = RAM0_read_data[0];
end
default: begin
//SRAM ACCESS
SRAM_address = 18'd0;
SRAM_write_data = 16'd0;
SRAM_we_n = 1'd1;
//DPRAM ACCESS
RAM0_write_data[1] = 32'd0;
RAM0_address[1] = 7'd0;
RAM0_write_enable[1] = 1'd0;
RAM0_write_data[0] = 32'd0;
RAM0_address[0] = 7'd0;
RAM0_write_enable[0] = 1'd0;
RAM1_write_data = 32'd0;
RAM1_address = 7'd0;
RAM1_write_enable = 1'd0;
RAM2_address[0] = 7'd0;
RAM2_address[1] = 7'd0;
RAM3_address[0] = 7'd0;
//FS ACCESS
//FS_SRAM_read_data = 16'd0;
M3_SRAM_read_data = 16'd0;
//CT ACCESS
MM_CT_RAM0_read_data = 32'd0;
MM_CT_RAM2_read_data[0] = 32'd0;
MM_CT_RAM2_read_data[1] = 32'd0;
//CS ACCESS
MM_CS_RAM1_read_data = 32'd0;
MM_CS_RAM2_read_data[0] = 32'd0;
MM_CS_RAM2_read_data[1] = 32'd0;
//WS ACCESS
WS_DPRAM0_read_data = 32'd0;
end
endcase
end
WS WS_unit (
.CLOCK_50_I(CLOCK_50_I),
.Resetn(Resetn),
.SRAM_address(WS_SRAM_address),
.SRAM_we_n(WS_SRAM_we_n),
.SRAM_write_data(WS_SRAM_write_data),
.WS_done(WS_done),
.WS_start(WS_start),
.WS_memory_end(WS_memory_end),
.S_read_data(WS_DPRAM0_read_data),
.S_read_address(WS_DPRAM0_read_address),
.S_write_enable(WS_DPRAM0_write_enable)
);
Milestone_3 M3_unit (
.CLOCK_50_I(CLOCK_50_I),
.Resetn(Resetn),
.SRAM_address(M3_SRAM_address),
.SRAM_write_data(M3_SRAM_write_data),
.SRAM_read_data(M3_SRAM_read_data),
.SRAM_we_n(M3_SRAM_we_n),
.M3_memory_end(M3_memory_end),
.RAM3_write_data(RAM3_write_data),
.RAM3_read_data(RAM3_read_data),
.RAM3_address_in(RAM3_address[0]),
.RAM3_address(RAM3_address[1]),
.RAM3_write_enable(RAM3_write_enable),
.M3_done(M3_done),
.M3_start(M3_start)
);
FS FS_unit (
.CLOCK_50_I(CLOCK_50_I),
.Resetn(Resetn),
.SRAM_address(FS_SRAM_address),
.SRAM_read_data(FS_SRAM_read_data),
.FS_done(FS_done),
.FS_memory_end(FS_memory_end),
.FS_start(FS_start),
.FS_write_data(FS_write_data),
.FS_write_address(FS_write_address),
.FS_write_enable(FS_write_enable)
);
MATRIX_MULTIPLIER MM_unit_CT(
.CLOCK_50_I(CLOCK_50_I),
.Resetn(Resetn),
.MM_start(MM_CT_start),
.MM_done(MM_CT_done),
.T_S(1'b1),
//[1]
.A_read_data(MM_CT_RAM0_read_data),
.A_read_address(MM_CT_RAM0_address),
.A_write_enable(MM_CT_RAM0_write_enable),
.C_read_data(MM_CT_RAM2_read_data),
.C_read_address(MM_CT_RAM2_address),
.P_write_data(MM_CT_RAM1_write_data),
.P_write_address(MM_CT_RAM1_address),
.P_write_enable(MM_CT_RAM1_write_enable)
);
MATRIX_MULTIPLIER MM_unit_CS(
.CLOCK_50_I(CLOCK_50_I),
.Resetn(Resetn),
.MM_start(MM_CS_start),
.MM_done(MM_CS_done),
.T_S(1'b1),
//[1]
.A_read_data(MM_CS_RAM1_read_data),
.A_read_address(MM_CS_RAM1_address),
.A_write_enable(MM_CS_RAM1_write_enable),
.C_read_data(MM_CS_RAM2_read_data),
.C_read_address(MM_CS_RAM2_address),
.P_write_data(MM_CS_RAM0_write_data),
.P_write_address(MM_CS_RAM0_address),
.P_write_enable(MM_CS_RAM0_write_enable)
);
//DPRAM for S and S' values
dual_port_RAM0 dual_port_RAM_inst0 (
.address_a ( RAM0_address[0] ), //S
.address_b ( RAM0_address[1] ), //S'
.clock ( CLOCK_50_I ),
.data_a ( RAM0_write_data[0] ), //S
.data_b ( RAM0_write_data[1] ), //S'
.wren_a ( RAM0_write_enable[0] ), //S
.wren_b ( RAM0_write_enable[1] ), //S'
.q_a ( RAM0_read_data[0] ), //S
.q_b ( RAM0_read_data[1] ) //S'
);
//DPRAM for T values
dual_port_RAM1 dual_port_RAM_inst1 (
.address_a ( RAM1_address ),
.address_b ( 7'd0 ),
.clock ( CLOCK_50_I ),
.data_a ( RAM1_write_data ),
.data_b ( 32'd0 ),
.wren_a ( RAM1_write_enable ),
.wren_b ( 1'b0 ),
.q_a ( RAM1_read_data[0] ),
.q_b ( RAM1_read_data[1] )
);
//DPRAM for C values
dual_port_RAM2 dual_port_RAM_inst2 (
.address_a ( RAM2_address[0] ),
.address_b ( RAM2_address[1] ),
.clock ( CLOCK_50_I ),
.data_a ( 32'd0 ),
.data_b ( 32'd0 ),
.wren_a ( 1'b0 ),
.wren_b ( 1'b0 ),
.q_a ( RAM2_read_data[0] ),
.q_b ( RAM2_read_data[1] )
);
endmodule