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

Subversion Repositories cavlc

[/] [cavlc/] [trunk/] [rtl/] [cavlc_read_run_befores.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 qiubin
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  cavlc_read_run_befores                                      ////
4
////                                                              ////
5
////  Description                                                 ////
6
////       decode runs and combine them with levels               ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - bin qiu, qiubin@opencores.org                         ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2011 Authors and OPENCORES.ORG                 ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38 6 qiubin
//2011-8-16 initiial revision
39
 
40
`include "defines.v"
41
 
42 7 qiubin
module cavlc_read_run_befores
43
(
44
    clk,
45
    rst_n,
46
    ena,
47
    sel,
48
    clr,
49
    ZeroLeft_init,
50
 
51
    rbsp,
52
    i,
53
    TotalZeros_comb,
54
 
55
    level_0,
56
    level_1,
57
    level_2,
58
    level_3,
59
    level_4,
60
    level_5,
61
    level_6,
62
    level_7,
63
    level_8,
64
    level_9,
65
    level_10,
66
    level_11,
67
    level_12,
68
    level_13,
69
    level_14,
70
    level_15,
71
 
72
    coeff_0,
73
    coeff_1,
74
    coeff_2,
75
    coeff_3,
76
    coeff_4,
77
    coeff_5,
78
    coeff_6,
79
    coeff_7,
80
    coeff_8,
81
    coeff_9,
82
    coeff_10,
83
    coeff_11,
84
    coeff_12,
85
    coeff_13,
86
    coeff_14,
87
    coeff_15,
88
    ZeroLeft,
89
    len_comb
90
);
91 6 qiubin
//----------------------
92
//ports
93
//----------------------
94 7 qiubin
input   clk;
95
input   rst_n;
96
input   ena;
97
input   sel;
98
input   clr;
99
input   ZeroLeft_init;
100 6 qiubin
 
101 7 qiubin
input   [0:10]  rbsp;
102
input   [3:0]   i;          //range from TotalCoeff-1 to 0
103
input   [3:0]   TotalZeros_comb;
104 6 qiubin
 
105 7 qiubin
input   [8:0]   level_0;
106
input   [8:0]   level_1;
107
input   [8:0]   level_2;
108
input   [8:0]   level_3;
109
input   [8:0]   level_4;
110
input   [8:0]   level_5;
111
input   [8:0]   level_6;
112
input   [8:0]   level_7;
113
input   [8:0]   level_8;
114
input   [8:0]   level_9;
115
input   [8:0]   level_10;
116
input   [8:0]   level_11;
117
input   [8:0]   level_12;
118
input   [8:0]   level_13;
119
input   [8:0]   level_14;
120
input   [8:0]   level_15;
121 6 qiubin
 
122 7 qiubin
output  [8:0]   coeff_0;
123
output  [8:0]   coeff_1;
124
output  [8:0]   coeff_2;
125
output  [8:0]   coeff_3;
126
output  [8:0]   coeff_4;
127
output  [8:0]   coeff_5;
128
output  [8:0]   coeff_6;
129
output  [8:0]   coeff_7;
130
output  [8:0]   coeff_8;
131
output  [8:0]   coeff_9;
132
output  [8:0]   coeff_10;
133
output  [8:0]   coeff_11;
134
output  [8:0]   coeff_12;
135
output  [8:0]   coeff_13;
136
output  [8:0]   coeff_14;
137
output  [8:0]   coeff_15;
138 6 qiubin
 
139 7 qiubin
output  [3:0]   ZeroLeft;
140 6 qiubin
 
141 7 qiubin
output  [3:0]   len_comb;
142 6 qiubin
 
143
//----------------------
144
//regs
145
//----------------------
146 7 qiubin
reg     [3:0]   run;
147
reg     [3:0]   len;
148
reg     [8:0]   coeff;
149 6 qiubin
 
150
 
151 7 qiubin
reg     [3:0]   len_comb;
152 6 qiubin
 
153
//----------------------
154
//FFs
155
//----------------------
156 7 qiubin
reg     [3:0]   ZeroLeft;
157 6 qiubin
 
158 7 qiubin
reg     [8:0]   coeff_0;
159
reg     [8:0]   coeff_1;
160
reg     [8:0]   coeff_2;
161
reg     [8:0]   coeff_3;
162
reg     [8:0]   coeff_4;
163
reg     [8:0]   coeff_5;
164
reg     [8:0]   coeff_6;
165
reg     [8:0]   coeff_7;
166
reg     [8:0]   coeff_8;
167
reg     [8:0]   coeff_9;
168
reg     [8:0]   coeff_10;
169
reg     [8:0]   coeff_11;
170
reg     [8:0]   coeff_12;
171
reg     [8:0]   coeff_13;
172
reg     [8:0]   coeff_14;
173
reg     [8:0]   coeff_15;
174 6 qiubin
 
175
//----------------------
176
//run & len
177
//----------------------
178
always @(rbsp or ZeroLeft or ena or sel)
179
if (ena && sel)
180
case(ZeroLeft)
181 7 qiubin
 
182
    1 : begin len <= 1; run <= rbsp[0]? 0:1; end
183
    2 : begin if (rbsp[0]) begin
184
            run <= 0;
185
            len <= 1;
186
        end
187
        else if (rbsp[1]) begin
188
            run <= 1;
189
            len <= 2;
190
        end
191
        else begin
192
            run <= 2;
193
            len <= 2;
194
        end
195
    end
196
    3 : begin
197
        run <= 3 - rbsp[0:1];
198
        len <= 2;
199
    end
200
    4 : begin
201
        if (rbsp[0:1] != 0) begin
202
            run <= 3 - rbsp[0:1];
203
            len <= 2;
204
        end
205
        else begin
206
            run <= rbsp[2]? 3:4;
207
            len <= 3;
208
        end
209
    end
210
    5 : begin
211
        if (rbsp[0]) begin
212
            run <= rbsp[1]? 0:1;
213
            len <= 2;
214
        end
215
        else if (rbsp[1]) begin
216
            run <= rbsp[2]? 2:3;
217
            len <= 3;
218
        end
219
        else begin
220
            run <= rbsp[2]? 4:5;
221
            len <= 3;
222
        end
223
    end
224
    6 : begin
225
        if (rbsp[0:1] == 2'b11) begin
226
            run <= 0;
227
            len <= 2;
228
        end
229
        else begin
230
            len <= 3;
231
            case(rbsp[0:2])
232
                3'b000 : run <= 1;
233
                3'b001 : run <= 2;
234
                3'b011 : run <= 3;
235
                3'b010 : run <= 4;
236
                3'b101 : run <= 5;
237
                default: run <= 6;
238
            endcase
239
        end
240
    end
241
    default : begin
242
        if (rbsp[0:2] != 0) begin
243
            run <= 7 - rbsp[0:2];
244
            len <= 3;
245
        end
246
        else begin
247
            case (1'b1)
248
                rbsp[3] : begin run <= 7;   len <= 4; end
249
                rbsp[4] : begin run <= 8;   len <= 5; end
250
                rbsp[5] : begin run <= 9;   len <= 6; end
251
                rbsp[6] : begin run <= 10;  len <= 7; end
252
                rbsp[7] : begin run <= 11;  len <= 8; end
253
                rbsp[8] : begin run <= 12;  len <= 9; end
254
                rbsp[9] : begin run <= 13;  len <= 10;end
255
                rbsp[10]: begin run <= 14;  len <= 11;end
256
                default : begin run <= 'bx; len <='bx;end
257
            endcase
258
        end
259
    end
260 6 qiubin
endcase
261
else begin
262 7 qiubin
    len <= 0;
263
    run <= 0;
264 6 qiubin
end
265
 
266
//----------------------
267
//len_comb
268
//----------------------
269
always @(*)
270
if (i >  0)
271 7 qiubin
    len_comb <= len;
272 6 qiubin
else
273 7 qiubin
    len_comb <= 0;
274
 
275
 
276 6 qiubin
//----------------------
277
//ZeroLeft
278
//----------------------
279
always @(posedge clk or negedge rst_n)
280
if (!rst_n)
281 7 qiubin
    ZeroLeft <= 0;
282
else if (ena && clr)    //in case TotalCoeff >= max_coeff_num
283
    ZeroLeft <= 0;
284 6 qiubin
else if (ena && ZeroLeft_init)
285 7 qiubin
    ZeroLeft <= TotalZeros_comb;
286 6 qiubin
else if (ena && sel )//if ZeroLeft == 0, run will be 0
287 7 qiubin
    ZeroLeft <= ZeroLeft - run;
288
 
289 6 qiubin
//----------------------
290
//coeff
291
//----------------------
292
always @(*)
293
if (ena && sel)
294
case (i)
295 7 qiubin
 
296
    1 :coeff <= level_1;
297
    2 :coeff <= level_2;
298
    3 :coeff <= level_3;
299
    4 :coeff <= level_4;
300
    5 :coeff <= level_5;
301
    6 :coeff <= level_6;
302
    7 :coeff <= level_7;
303
    8 :coeff <= level_8;
304
    9 :coeff <= level_9;
305
    10:coeff <= level_10;
306
    11:coeff <= level_11;
307
    12:coeff <= level_12;
308
    13:coeff <= level_13;
309
    14:coeff <= level_14;
310
    15:coeff <= level_15;
311 6 qiubin
endcase
312
else
313 7 qiubin
    coeff <= 0;
314 6 qiubin
 
315
//----------------------
316
//coeff_0 to coeff_15
317
//----------------------
318
always @(posedge clk or negedge rst_n)
319
if (!rst_n) begin
320 7 qiubin
    coeff_0 <= 0;   coeff_1 <= 0;   coeff_2 <= 0;   coeff_3 <= 0;
321
    coeff_4 <= 0;   coeff_5 <= 0;   coeff_6 <= 0;   coeff_7 <= 0;
322
    coeff_8 <= 0;   coeff_9 <= 0;   coeff_10<= 0;   coeff_11<= 0;
323
    coeff_12<= 0;   coeff_13<= 0;   coeff_14<= 0;   coeff_15<= 0;
324 6 qiubin
end
325
else if (ena && clr) begin
326 7 qiubin
    coeff_0 <= 0;   coeff_1 <= 0;   coeff_2 <= 0;   coeff_3 <= 0;
327
    coeff_4 <= 0;   coeff_5 <= 0;   coeff_6 <= 0;   coeff_7 <= 0;
328
    coeff_8 <= 0;   coeff_9 <= 0;   coeff_10<= 0;   coeff_11<= 0;
329
    coeff_12<= 0;   coeff_13<= 0;   coeff_14<= 0;   coeff_15<= 0;
330 6 qiubin
end
331
else if (ena && sel && ZeroLeft > 0)
332
case (ZeroLeft+i)
333 7 qiubin
    1 :coeff_1  <= coeff;
334
    2 :coeff_2  <= coeff;
335
    3 :coeff_3  <= coeff;
336
    4 :coeff_4  <= coeff;
337
    5 :coeff_5  <= coeff;
338
    6 :coeff_6  <= coeff;
339
    7 :coeff_7  <= coeff;
340
    8 :coeff_8  <= coeff;
341
    9 :coeff_9  <= coeff;
342
    10:coeff_10 <= coeff;
343
    11:coeff_11 <= coeff;
344
    12:coeff_12 <= coeff;
345
    13:coeff_13 <= coeff;
346
    14:coeff_14 <= coeff;
347
    default:
348
    coeff_15    <= coeff;
349 6 qiubin
endcase
350
else if (ena && sel) begin
351 7 qiubin
    if (i >= 0) coeff_0  <= level_0;
352
    if (i >= 1) coeff_1  <= level_1;
353
    if (i >= 2) coeff_2  <= level_2;
354
    if (i >= 3) coeff_3  <= level_3;
355
    if (i >= 4) coeff_4  <= level_4;
356
    if (i >= 5) coeff_5  <= level_5;
357
    if (i >= 6) coeff_6  <= level_6;
358
    if (i >= 7) coeff_7  <= level_7;
359
    if (i >= 8) coeff_8  <= level_8;
360
    if (i >= 9) coeff_9  <= level_9;
361
    if (i >= 10)coeff_10 <= level_10;
362
    if (i >= 11)coeff_11 <= level_11;
363
    if (i >= 12)coeff_12 <= level_12;
364
    if (i >= 13)coeff_13 <= level_13;
365
    if (i >= 14)coeff_14 <= level_14;
366
    if (i == 15)coeff_15 <= level_15;
367 6 qiubin
end
368
endmodule

powered by: WebSVN 2.1.0

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