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

Subversion Repositories djpeg

[/] [djpeg/] [trunk/] [src/] [jpeg_regdata.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hidemi
//---------------------------------------------------------------------------
2 5 hidemi
// File Name    : jpeg_regdata.v
3
// Module Name  : jpeg_regdata
4 9 hidemi
// Description  : Get Data
5
// Project      : JPEG Decoder
6 5 hidemi
// Belong to    : 
7 9 hidemi
// Author       : H.Ishihara
8
// E-Mail       : hidemi@sweetcafe.jp
9
// HomePage     : http://www.sweetcafe.jp/
10
// Date         : 2008/02/27
11
// Rev.         : 2.00
12 3 hidemi
//---------------------------------------------------------------------------
13 9 hidemi
// Rev. Date       Description
14 3 hidemi
//---------------------------------------------------------------------------
15
// 1.01 2006/10/01 1st Release
16
// 1.02 2006/10/04 Remove a RegEnd register.
17 9 hidemi
//                 When reset, clear on OutEnable,PreEnable,DataOut registers.
18
//                 Remove some comments.
19 5 hidemi
// 1.03 2007/04/11 Don't OutEnable, ImageEnable == 1 and DataOut == 0xFFD9XXXX
20
//                 Stop ReadEnable with DataEnd(after 0xFFD9 of ImageData)
21 9 hidemi
// 1.04 2007/10/16 Modify (RegData[31:0] == 0xFF00FF00) process
22
//                        not convert 0xFF00 -> 0xFF after convert [7:0] == 0xFF
23
// 2.00 2008/02/27 Modify RegValid, when ImageEnable == 1 then RegWidth > 64
24
//                                  when ImageEnable == 0 then RegWidth > 32
25
//                 Add    SliceData Pattern
26 3 hidemi
//---------------------------------------------------------------------------
27
`timescale 1ps / 1ps
28 5 hidemi
 
29
module jpeg_regdata(
30 9 hidemi
    rst,
31
    clk,
32
 
33
    // Read Data
34
    DataIn,         // 
35
    DataInEnable,   // Data Enable
36
    DataInRead,     // Data Read
37
 
38
    // DataOut
39
    DataOut,        // Data Out
40
    DataOutEnable,  // Data Out Enable
41
 
42
    // 
43
    ImageEnable,
44
    ProcessIdle,
45
 
46
    // UseData
47
    UseBit,         // Used data bit
48
    UseWidth,       // Used data bit width
49
    UseByte,        // Used data byte
50
    UseWord         // Used data word
51
);
52
 
53
    input           rst;
54
    input           clk;
55
 
56
    input [31:0]    DataIn;
57
    input           DataInEnable;
58
    output          DataInRead;
59
 
60
    output [31:0]   DataOut;
61
    output          DataOutEnable;
62
 
63
    input           ImageEnable;
64
    input           ProcessIdle;
65
 
66
    input           UseBit;
67
    input [6:0]     UseWidth;
68
    input           UseByte;
69
    input           UseWord;
70
 
71
    wire            RegValid;
72
    reg [95:0]      RegData;
73
    reg [6:0]       RegWidth;
74
    reg             CheckMode;
75
    reg             DataEnd;
76
 
77
    assign RegValid     = (ImageEnable)?(RegWidth > 7'd64):(RegWidth > 7'd32);
78
    assign DataInRead   = ((RegValid == 1'b0) & (DataInEnable == 1'b1) & (DataEnd == 1'b0));
79
 
80
    always @(posedge clk or negedge rst) begin
81
        if(!rst) begin
82
            RegData   <= 96'd0;
83
            RegWidth  <= 7'd0;
84
            CheckMode <= 1'b0;
85
        end else begin
86
            if(DataEnd == 1'b1 & ProcessIdle == 1'b1) begin
87
                RegData   <= 96'd0;
88
                RegWidth  <= 7'd0;
89
                CheckMode <= 1'b0;
90
            end else if(RegValid == 1'b0 & (DataInEnable == 1'b1 | DataEnd == 1'b1)) begin
91
                if(ImageEnable == 1'b1) begin
92
                    if(RegData[39: 8] == 32'hFF00FF00 & CheckMode != 1'b1) begin
93
                        RegWidth        <= RegWidth + 7'd16;
94
                        RegData[95:64]  <= {8'h00,RegData[71:48]};
95
                        RegData[63:32]  <= {RegData[47:40],16'hFFFF,RegData[7:0]};
96
                        CheckMode       <= 1'b0;
97
                    end else if(RegData[39:24] == 16'hFF00 & RegData[15: 0] == 16'hFF00 & CheckMode != 1'b1) begin
98
                        RegWidth        <= RegWidth + 7'd16;
99
                        RegData[95:64]  <= {8'h00,RegData[71:48]};
100
                        RegData[63:32]  <= {RegData[47:40],8'hFF,RegData[23:16],8'hFF};
101
                        CheckMode       <= 1'b1;
102
                    end else if(RegData[31: 0] == 32'hFF00FF00) begin
103
                        RegWidth        <= RegWidth + 7'd16;
104
                        RegData[95:64]  <= {16'h0000,RegData[63:48]};
105
                        RegData[63:32]  <= {RegData[47:32],16'hFFFF};
106
                        CheckMode       <= 1'b1;
107
                    end else if(RegData[39:24] == 16'hFF00 & CheckMode != 1'b1) begin
108
                        RegWidth        <= RegWidth + 7'd24;
109
                        RegData[95:64]  <= {RegData[71:40]};
110
                        RegData[63:32]  <= {8'hFF,RegData[23:0]};
111
                        CheckMode       <= 1'b0;
112
                    end else if(RegData[31:16] == 16'hFF00) begin
113
                        RegWidth        <= RegWidth + 7'd24;
114
                        RegData[95:64]  <= {RegData[71:40]};
115
                        RegData[63:32]  <= {RegData[39:32],8'hFF,RegData[15:0]};
116
                        CheckMode       <= 1'b0;
117
                    end else if(RegData[23: 8] == 16'hFF00) begin
118
                        RegWidth        <= RegWidth + 7'd24;
119
                        RegData[95:64]  <= {RegData[71:40]};
120
                        RegData[63:32]  <= {RegData[39:32],RegData[31:24],8'hFF,RegData[7:0]};
121
                        CheckMode       <= 1'b0;
122
                    end else if(RegData[15: 0] == 16'hFF00) begin
123
                        RegWidth        <= RegWidth + 7'd24;
124
                        RegData[95:64]  <= {RegData[71:40]};
125
                        RegData[63:32]  <= {RegData[39:32],RegData[31:16],8'hFF};
126
                        CheckMode       <= 1'b1;
127
                    end else begin
128
                        RegWidth        <= RegWidth + 7'd32;
129
                        RegData[95:64]  <= RegData[63:32];
130
                        RegData[63:32]  <= RegData[31:0];
131
                        CheckMode       <= 1'b0;
132
                    end
133 5 hidemi
                end else begin
134 9 hidemi
                    RegWidth        <= RegWidth + 7'd32;
135
                    RegData[95:64]  <= RegData[63:32];
136
                    RegData[63:32]  <= RegData[31:0];
137
                    CheckMode       <= 1'b0;
138 5 hidemi
                end
139 9 hidemi
                RegData[31: 0] <= {DataIn[7:0],DataIn[15:8],DataIn[23:16],DataIn[31:24]};
140
            end else if(UseBit == 1'b1) begin
141
                RegWidth <= RegWidth - UseWidth;
142
            end else if(UseByte == 1'b1) begin
143
                RegWidth <= RegWidth - 7'd8;
144
            end else if(UseWord == 1'b1) begin
145
                RegWidth <= RegWidth - 7'd16;
146
            end
147 5 hidemi
        end
148 9 hidemi
    end
149
 
150
    // PickUp with End of Jpeg Data
151
    always @(posedge clk or negedge rst) begin
152
        if(!rst) begin
153
            DataEnd <= 1'b0;
154
        end else begin
155
            if(ProcessIdle) begin
156
                DataEnd <= 1'b0;
157
            end else if(ImageEnable == 1'b1 & ((RegData[39:24] == 16'hFFD9 & CheckMode != 1'b1) | RegData[31:16] == 16'hFFD9 | RegData[23: 8] == 16'hFFD9 | RegData[15: 0] == 16'hFFD9)) begin
158
                DataEnd <= 1'b1;
159
            end
160 5 hidemi
        end
161 9 hidemi
    end
162
 
163
    function [31:0] SliceData;
164
        input [95:0] RegData;
165
        input [7:0]  RegWidth;
166
 
167
        case(RegWidth)
168
            //8'd33: SliceData = RegData[32: 1];
169
            //8'd34: SliceData = RegData[33: 2];
170
            //8'd35: SliceData = RegData[34: 3];
171
            //8'd36: SliceData = RegData[35: 4];
172
            //8'd37: SliceData = RegData[36: 5];
173
            //8'd38: SliceData = RegData[37: 6];
174
            //8'd39: SliceData = RegData[38: 7];
175
            8'd40: SliceData = RegData[39: 8];
176
            //8'd41: SliceData = RegData[40: 9];
177
            //8'd42: SliceData = RegData[41:10];
178
            //8'd43: SliceData = RegData[42:11];
179
            //8'd44: SliceData = RegData[43:12];
180
            //8'd45: SliceData = RegData[44:13];
181
            //8'd46: SliceData = RegData[45:14];
182
            //8'd47: SliceData = RegData[46:15];
183
            8'd48: SliceData = RegData[47:16];
184
            //8'd49: SliceData = RegData[48:17];
185
            //8'd50: SliceData = RegData[49:18];
186
            //8'd51: SliceData = RegData[50:19];
187
            //8'd52: SliceData = RegData[51:20];
188
            //8'd53: SliceData = RegData[52:21];
189
            //8'd54: SliceData = RegData[53:22];
190
            //8'd55: SliceData = RegData[54:23];
191
            8'd56: SliceData = RegData[55:24];
192
            //8'd57: SliceData = RegData[56:25];
193
            //8'd58: SliceData = RegData[57:26];
194
            //8'd59: SliceData = RegData[58:27];
195
            //8'd60: SliceData = RegData[59:28];
196
            //8'd61: SliceData = RegData[60:29];
197
            //8'd62: SliceData = RegData[61:30];
198
            //8'd63: SliceData = RegData[62:31];
199
            8'd64: SliceData = RegData[63:32];
200
            8'd65: SliceData = RegData[64:33];
201
            8'd66: SliceData = RegData[65:34];
202
            8'd67: SliceData = RegData[66:35];
203
            8'd68: SliceData = RegData[67:36];
204
            8'd69: SliceData = RegData[68:37];
205
            8'd70: SliceData = RegData[69:38];
206
            8'd71: SliceData = RegData[70:39];
207
            8'd72: SliceData = RegData[71:40];
208
            8'd73: SliceData = RegData[72:41];
209
            8'd74: SliceData = RegData[73:42];
210
            8'd75: SliceData = RegData[74:43];
211
            8'd76: SliceData = RegData[75:44];
212
            8'd77: SliceData = RegData[76:45];
213
            8'd78: SliceData = RegData[77:46];
214
            8'd79: SliceData = RegData[78:47];
215
            8'd80: SliceData = RegData[79:48];
216
            8'd81: SliceData = RegData[80:49];
217
            8'd82: SliceData = RegData[81:50];
218
            8'd83: SliceData = RegData[82:51];
219
            8'd84: SliceData = RegData[83:52];
220
            8'd85: SliceData = RegData[84:53];
221
            8'd86: SliceData = RegData[85:54];
222
            8'd87: SliceData = RegData[86:55];
223
            8'd88: SliceData = RegData[87:56];
224
            8'd89: SliceData = RegData[88:57];
225
            8'd90: SliceData = RegData[89:58];
226
            8'd91: SliceData = RegData[90:59];
227
            8'd92: SliceData = RegData[91:60];
228
            8'd93: SliceData = RegData[92:61];
229
            8'd94: SliceData = RegData[93:62];
230
            8'd95: SliceData = RegData[94:63];
231
            8'd96: SliceData = RegData[95:64];
232
            default: SliceData = 32'h00000000;
233
        endcase
234
    endfunction
235 3 hidemi
 
236 9 hidemi
    reg              OutEnable;
237
    reg              PreEnable;
238
    reg [31:0]       DataOut;
239 3 hidemi
 
240 9 hidemi
    always @(posedge clk or negedge rst) begin
241
        if(!rst) begin
242
            OutEnable   <= 1'b0;
243
            PreEnable   <= 1'b0;
244
            DataOut     <= 32'h00000000;
245
        end else begin
246
            if(DataEnd == 1'b1 & ProcessIdle == 1'b1) begin
247
                OutEnable   <= 1'b0;
248
                PreEnable   <= 1'b0;
249
                DataOut     <= 32'h00000000;
250
            end else begin
251
                OutEnable   <= RegValid;
252
                PreEnable   <= (UseBit == 1'b1 | UseByte == 1'b1 | UseWord == 1'b1);
253
                DataOut     <= SliceData(RegData,RegWidth);
254
            end
255 5 hidemi
        end
256 9 hidemi
    end
257
 
258
    assign DataOutEnable = (PreEnable == 1'b0)?OutEnable:1'b0;
259 3 hidemi
 
260 5 hidemi
endmodule

powered by: WebSVN 2.1.0

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