OpenCores
URL https://opencores.org/ocsvn/vitdec/vitdec/trunk

Subversion Repositories vitdec

[/] [vitdec/] [trunk/] [tb_ram.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 yuhuang198
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    09:38:56 11/29/2010 
7
// Design Name: 
8
// Module Name:    tb_ram 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
module tb_ram(rst, clk, frame_rst, en, in1, in2, in3, in4, out_tb, out_dc);
22
 
23
parameter               state                                   =       64;
24
parameter               nu                                              =       6;
25
parameter               tb_length                       =       128;
26
parameter               tb_length_log           =       7;
27
parameter               radix                                   =       4;              //1: radix-2;   2: radix-4              3: radix-8
28
 
29
localparam              data_width                      =       state;
30
localparam              ram_depth                       =       tb_length/radix;
31
localparam              addr_width                      =       tb_length_log;
32
 
33
input                                                           rst, clk, frame_rst, en;
34
input           [0:data_width-1] in1;
35
input           [0:data_width-1] in2;
36
input           [0:data_width-1] in3;
37
input           [0:data_width-1] in4;
38
output  [0:radix-1]                      out_tb;
39
output  [0:radix-1]                      out_dc;
40
 
41
reg     [0:3]                                    en_reg;
42
reg     [0:nu-1]                         tb_state;
43
reg     [0:nu-1]                         dec_state;
44
wire    [0:radix-1]                      tb_tmp;
45
wire    [0:radix-1]                      dc_tmp;
46
wire    [0:radix-1]                      dc_tmp_tmp;
47
wire    [0:data_width-1] out_w                   [0:3][0:radix-1];
48
reg     [0:data_width-1] in_reg  [0:radix-1];
49
reg     [0:addr_width-1] counter_tb              ;
50
reg     [0:addr_width-1] counter_tbn             ;
51
wire    [0:addr_width-1] counter_tb_w    ;
52
wire    [0:addr_width-1] counter_tbn_w   ;
53
 
54
reg     [0:1]            counter_id0             ;
55
reg     [0:1]            counter_id1             ;
56
reg     [0:1]            counter_id2             ;
57
reg     [0:1]            counter_id3             ;
58
wire    [0:1]            counter_id0_w   ;
59
wire    [0:1]            counter_id1_w   ;
60
wire    [0:1]            counter_id2_w   ;
61
wire    [0:1]            counter_id3_w   ;
62
 
63
genvar gi, gj;
64
 
65
initial
66
begin
67
        dec_state = 7;
68
        tb_state  = 7;
69
        counter_id0 = 0;
70
        counter_id1 = 1;
71
        counter_id2 = 2;
72
        counter_id3 = 3;
73
        counter_tb = 0;
74
        counter_tbn = -1;
75
end
76
 
77
always @ (clk, rst)
78
begin
79
        if      (rst == 0)               counter_tb = 0;
80
        else if(clk == 1)
81
                if      (frame_rst == 1)        counter_tb = 0;
82
                else if (en == 1)               counter_tb = (counter_tb + 1) % ram_depth;
83
end
84
 
85
assign counter_tb_w = counter_tb;
86
assign counter_tbn_w = ~counter_tb;
87
 
88
always @ (clk, rst)
89
begin
90
        if      (rst == 0)
91
        begin
92
                counter_id0 = 0;
93
                counter_id1 = 1;
94
                counter_id2 = 2;
95
                counter_id3 = 3;
96
        end
97
        else if (clk == 1)
98
                if      (frame_rst == 1)
99
                begin
100
                        counter_id0 = 0;
101
                        counter_id1 = 1;
102
                        counter_id2 = 2;
103
                        counter_id3 = 3;
104
                end
105
                else if (counter_tb == ram_depth - 1)
106
                begin
107
                        counter_id0 = (counter_id0 + 1) % 4;
108
                        counter_id1 = (counter_id1 + 1) % 4;
109
                        counter_id2 = (counter_id2 + 1) % 4;
110
                        counter_id3 = (counter_id3 + 1) % 4;
111
                end
112
end
113
 
114
assign counter_id0_w = counter_id0;
115
assign counter_id1_w = counter_id1;
116
assign counter_id2_w = counter_id2;
117
assign counter_id3_w = counter_id3;
118
 
119
always @ (counter_id0_w)
120
begin
121
        case(counter_id0_w)
122
                2'b00   :       en_reg = 4'b1000;
123
                2'b01   :       en_reg = 4'b0100;
124
                2'b10   :       en_reg = 4'b0010;
125
                2'b11   :       en_reg = 4'b0001;
126
        endcase
127
end
128
 
129
generate
130
        if (radix == 1)
131
        begin
132
                always @ (in1, clk)
133
                begin
134
                        in_reg[0] = in1;
135
                end
136
        end
137
        else if (radix == 2)
138
        begin
139
                always @ (in1, in2, clk)
140
                begin
141
                        in_reg[0] = in1;
142
                        in_reg[1] = in2;
143
                end
144
        end
145
        else if (radix == 3)
146
        begin
147
                always @ (in1, in2, in3, clk)
148
                begin
149
                        in_reg[0] = in1;
150
                        in_reg[1] = in2;
151
                        in_reg[2] = in3;
152
                end
153
        end
154
        else if (radix == 4)
155
        begin
156
                always @ (in1, in2, in3, in4, clk)
157
                begin
158
                        in_reg[0] = in1;
159
                        in_reg[1] = in2;
160
                        in_reg[2] = in3;
161
                        in_reg[3] = in4;
162
                end
163
        end
164
endgenerate
165
 
166
generate for (gi = 0; gi < radix; gi = gi + 1)
167
begin : sel
168
        assign tb_tmp[gi] = out_w[counter_id3_w][gi][tb_state];
169
        assign dc_tmp[gi] = out_w[counter_id1_w][gi][dec_state];
170
        assign dc_tmp_tmp[gi] = out_w[counter_id1_w][gi][tb_state];
171
end
172
endgenerate
173
 
174
generate for (gi = 0; gi < 4; gi = gi + 1)
175
begin : ram
176
        for (gj = 0; gj < radix; gj = gj + 1)
177
        begin : r
178
                dpram           #(      data_width,
179
                                                ram_depth,
180
                                                addr_width)
181
 
182
                ram_inst        (       in_reg[gj],
183
                                                out_w[gi][gj],
184
                                                counter_tbn_w,
185
                                                counter_tb_w,
186
                                                clk,
187
                                                rst,
188
                                                frame_rst,
189
                                                en_reg[gi]);
190
        end
191
end
192
endgenerate
193
 
194
always @ (posedge clk)
195
begin
196
        if (counter_tb == ram_depth - 1)
197
        begin
198
                dec_state = {tb_state[radix:nu-1], dc_tmp_tmp};
199
                tb_state = 7;
200
        end
201
        else
202
        begin
203
                dec_state = {dec_state[radix:nu-1], dc_tmp};
204
                tb_state = {tb_state[radix:nu-1], tb_tmp};
205
        end
206
end
207
 
208
generate for (gi = 0; gi < radix; gi = gi + 1)
209
begin : assgn_out
210
        assign out_tb[gi] = tb_state[gi];
211
        assign out_dc[gi] = dec_state[gi];
212
end
213
endgenerate
214
 
215
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.