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

Subversion Repositories cavlc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 qiubin
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  cavlc_fsm                                                   ////
4
////                                                              ////
5
////  Description                                                 ////
6
////      controls the cavlc parsing process                      ////
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 6 qiubin
 
38 7 qiubin
//2011-8-7 18:57    initial revision
39
 
40 6 qiubin
`include "defines.v"
41
 
42
module cavlc_fsm
43
(
44 7 qiubin
    clk,
45
    rst_n,
46
    ena,
47
    start,
48
    max_coeff_num,
49
    TotalCoeff,
50
    TotalCoeff_comb,
51
    TrailingOnes,
52
    TrailingOnes_comb,
53
    ZeroLeft,
54
    state,
55
    i,
56
    idle,
57
    valid
58 6 qiubin
);
59
//------------------------
60
//ports
61
//------------------------
62 7 qiubin
input  clk;
63
input  rst_n;
64
input  ena;
65
input  start;
66 6 qiubin
 
67 7 qiubin
input  [4:0]  max_coeff_num;
68
input  [4:0]  TotalCoeff;
69
input  [4:0]  TotalCoeff_comb;
70
input  [1:0]  TrailingOnes;
71
input  [1:0]  TrailingOnes_comb;
72
input  [3:0]  ZeroLeft;
73 6 qiubin
 
74 7 qiubin
output [7:0]  state;
75
output [3:0]  i;
76 6 qiubin
output idle;
77
output valid;
78
 
79
//------------------------
80
//FFs
81
//------------------------
82 7 qiubin
reg  [7:0]  state;
83
reg  [3:0]  i;
84
reg  valid;
85 6 qiubin
 
86
//------------------------
87
//state & i & valid
88
//------------------------
89
always @(posedge clk or negedge rst_n)
90 7 qiubin
if (!rst_n) begin
91
    state   <= `cavlc_idle_s;
92
    i <= 0;
93
    valid <= 0;
94 6 qiubin
end
95
else if (ena)
96
case(state)
97 7 qiubin
    `cavlc_idle_s : begin
98
        if (start) begin
99
            state <= `cavlc_read_total_coeffs_s;
100
            valid <= 0;
101
        end
102
        else begin
103
            state <= `cavlc_idle_s;
104
        end
105
    end
106
    `cavlc_read_total_coeffs_s : begin
107
        i <= TotalCoeff_comb -1;
108
        if (TrailingOnes_comb > 0 && TotalCoeff_comb > 0)
109
            state <= `cavlc_read_t1s_flags_s;
110
        else if (TotalCoeff_comb > 0)
111
            state <= `cavlc_read_level_prefix_s;
112
        else begin
113
            state <= `cavlc_idle_s;
114
            valid <= 1;
115
        end
116
    end
117
    `cavlc_read_t1s_flags_s : begin
118
        if (TrailingOnes == TotalCoeff)
119
            state <= `cavlc_read_total_zeros_s;
120
        else begin
121
            state <= `cavlc_read_level_prefix_s;
122
            i <= i - TrailingOnes;
123
        end
124
    end
125
    `cavlc_read_level_prefix_s : begin
126
        state <= `cavlc_read_level_suffix_s;
127
    end
128
    `cavlc_read_level_suffix_s : begin
129
        state <= `cavlc_calc_level_s;
130
    end
131
    `cavlc_calc_level_s : begin
132
        if ( i == 0  && TotalCoeff < max_coeff_num)
133
            state <= `cavlc_read_total_zeros_s;
134
        else if (i == 0) begin
135
            state <= `cavlc_read_run_befores_s;
136
            i <= TotalCoeff - 1;
137
        end
138
        else begin
139
            state <= `cavlc_read_level_prefix_s;
140
            i <= i - 1;
141
        end
142
    end
143
    `cavlc_read_total_zeros_s : begin
144
        state <= `cavlc_read_run_befores_s;
145
        i <= TotalCoeff - 1;
146
    end
147
    `cavlc_read_run_befores_s : begin
148
        if (i == 0 || ZeroLeft == 0) begin
149
            state <= `cavlc_idle_s;
150
            valid <= 1;
151
        end
152
        else begin
153
            state <= `cavlc_read_run_befores_s;
154
            i <= i - 1;
155
        end
156
    end
157 6 qiubin
endcase
158
 
159
assign idle = state[`cavlc_idle_bit];
160
 
161
endmodule
162
 

powered by: WebSVN 2.1.0

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