1 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
2 |
|
|
// File Name : jpeg_regdata.v
|
3 |
|
|
// Module Name : jpeg_regdata
|
4 |
|
|
// Description : get Data
|
5 |
|
|
// Project : JPEG Decoder
|
6 |
|
|
// Belong to :
|
7 |
|
|
// Author : H.Ishihara
|
8 |
|
|
// E-Mail : hidemi@sweetcafe.jp
|
9 |
|
|
// HomePage : http://www.sweetcafe.jp/
|
10 |
|
|
// Date : 2006/10/01
|
11 |
|
|
// Rev. : 1.1
|
12 |
|
|
//---------------------------------------------------------------------------
|
13 |
|
|
// Rev. Date Description
|
14 |
|
|
//---------------------------------------------------------------------------
|
15 |
|
|
// 1.01 2006/10/01 1st Release
|
16 |
|
|
// 1.02 2006/10/04 Remove a RegEnd register.
|
17 |
|
|
// When reset, clear on OutEnable,PreEnable,DataOut registers.
|
18 |
|
|
// Remove some comments.
|
19 |
|
|
//---------------------------------------------------------------------------
|
20 |
|
|
// $Id:
|
21 |
|
|
//---------------------------------------------------------------------------
|
22 |
|
|
`timescale 1ps / 1ps
|
23 |
|
|
|
24 |
|
|
module jpeg_regdata
|
25 |
|
|
(
|
26 |
|
|
rst,
|
27 |
|
|
clk,
|
28 |
|
|
|
29 |
|
|
// Read Data
|
30 |
|
|
DataInStart,
|
31 |
|
|
DataIn, //
|
32 |
|
|
DataInEnable, // Data Enable
|
33 |
|
|
DataInRead, // Data Read
|
34 |
|
|
|
35 |
|
|
// DataOut
|
36 |
|
|
DataOut, // Data Out
|
37 |
|
|
DataOutEnable, // Data Out Enable
|
38 |
|
|
DataOutEnd, // Data Out End
|
39 |
|
|
|
40 |
|
|
//
|
41 |
|
|
ImageEnable,
|
42 |
|
|
|
43 |
|
|
// UseData
|
44 |
|
|
UseBit, // Used data bit
|
45 |
|
|
UseWidth, // Used data bit width
|
46 |
|
|
UseByte, // Used data byte
|
47 |
|
|
UseWord // Used data word
|
48 |
|
|
);
|
49 |
|
|
|
50 |
|
|
input rst;
|
51 |
|
|
input clk;
|
52 |
|
|
|
53 |
|
|
input DataInStart;
|
54 |
|
|
input [31:0] DataIn;
|
55 |
|
|
input DataInEnable;
|
56 |
|
|
output DataInRead;
|
57 |
|
|
|
58 |
|
|
output [31:0] DataOut;
|
59 |
|
|
output DataOutEnable;
|
60 |
|
|
output DataOutEnd;
|
61 |
|
|
|
62 |
|
|
input ImageEnable;
|
63 |
|
|
|
64 |
|
|
input UseBit;
|
65 |
|
|
input [6:0] UseWidth;
|
66 |
|
|
input UseByte;
|
67 |
|
|
input UseWord;
|
68 |
|
|
|
69 |
|
|
wire RegValid;
|
70 |
|
|
reg [95:0] RegData;
|
71 |
|
|
reg [7:0] RegWidth;
|
72 |
|
|
|
73 |
|
|
assign RegValid = RegWidth > 64;
|
74 |
|
|
assign DataInRead = RegValid == 1'b0 & DataInEnable == 1'b1;
|
75 |
|
|
|
76 |
|
|
always @(posedge clk or negedge rst) begin
|
77 |
|
|
if(!rst) begin
|
78 |
|
|
RegData <= 96'd0;
|
79 |
|
|
RegWidth <= 8'h00;
|
80 |
|
|
end else begin
|
81 |
|
|
if(DataInStart == 1'b1) begin
|
82 |
|
|
RegData <= 96'd0;
|
83 |
|
|
RegWidth <= 8'h00;
|
84 |
|
|
end else if(RegValid == 1'b0 & DataInEnable == 1'b1) begin
|
85 |
|
|
if(ImageEnable == 1'b1) begin
|
86 |
|
|
if(RegData[39: 8] == 32'hFF00FF00) begin
|
87 |
|
|
RegWidth <= RegWidth + 16;
|
88 |
|
|
RegData[95:64] <= {8'h00,RegData[71:48]};
|
89 |
|
|
RegData[63:32] <= {RegData[47:40],16'hFFFF,RegData[7:0]};
|
90 |
|
|
end else if(RegData[39:24] == 16'hFF00 &
|
91 |
|
|
RegData[15: 0] == 16'hFF00) begin
|
92 |
|
|
RegWidth <= RegWidth + 16;
|
93 |
|
|
RegData[95:64] <= {8'h00,RegData[71:48]};
|
94 |
|
|
RegData[63:32] <= {RegData[47:40],8'hFF,RegData[23:16],8'hFF};
|
95 |
|
|
end else if(RegData[31: 0] == 32'hFF00FF00) begin
|
96 |
|
|
RegWidth <= RegWidth + 16;
|
97 |
|
|
RegData[95:64] <= {16'h0000,RegData[71:56]};
|
98 |
|
|
RegData[63:32] <= {RegData[55:40],16'hFFFF};
|
99 |
|
|
end else if(RegData[39:24] == 16'hFF00) begin
|
100 |
|
|
RegWidth <= RegWidth + 24;
|
101 |
|
|
RegData[95:64] <= {RegData[71:40]};
|
102 |
|
|
RegData[63:32] <= {8'hFF,RegData[23:0]};
|
103 |
|
|
end else if(RegData[31:16] == 16'hFF00) begin
|
104 |
|
|
RegWidth <= RegWidth + 24;
|
105 |
|
|
RegData[95:64] <= {RegData[71:40]};
|
106 |
|
|
RegData[63:32] <= {RegData[39:32],8'hFF,RegData[15:0]};
|
107 |
|
|
end else if(RegData[23: 8] == 16'hFF00) begin
|
108 |
|
|
RegWidth <= RegWidth + 24;
|
109 |
|
|
RegData[95:64] <= {RegData[71:40]};
|
110 |
|
|
RegData[63:32] <= {RegData[39:32],RegData[31:24],8'hFF,RegData[7:0]};
|
111 |
|
|
end else if(RegData[15: 0] == 16'hFF00) begin
|
112 |
|
|
RegWidth <= RegWidth + 24;
|
113 |
|
|
RegData[95:64] <= {RegData[71:40]};
|
114 |
|
|
RegData[63:32] <= {RegData[39:32],RegData[31:16],8'hFF};
|
115 |
|
|
end else begin
|
116 |
|
|
RegWidth <= RegWidth + 32;
|
117 |
|
|
RegData[95:64] <= RegData[63:32];
|
118 |
|
|
RegData[63:32] <= RegData[31:0];
|
119 |
|
|
end
|
120 |
|
|
end else begin // if (ImageEnable == 1'b1)
|
121 |
|
|
RegWidth <= RegWidth + 32;
|
122 |
|
|
RegData[95:64] <= RegData[63:32];
|
123 |
|
|
RegData[63:32] <= RegData[31:0];
|
124 |
|
|
end // else: !if(ImageEnable == 1'b1)
|
125 |
|
|
RegData[31: 0] <= {DataIn[7:0],DataIn[15:8],DataIn[23:16],DataIn[31:24]};
|
126 |
|
|
end else if(UseBit == 1'b1) begin // if (RegValid == 1'b0 & DataInEnable == 1'b1)
|
127 |
|
|
RegWidth <= RegWidth - UseWidth;
|
128 |
|
|
end else if(UseByte == 1'b1) begin
|
129 |
|
|
RegWidth <= RegWidth - 8;
|
130 |
|
|
end else if(UseWord == 1'b1) begin
|
131 |
|
|
RegWidth <= RegWidth - 16;
|
132 |
|
|
end
|
133 |
|
|
end // else: !if(!rst)
|
134 |
|
|
end // always @ (posedge clk or negedge rst)
|
135 |
|
|
|
136 |
|
|
assign DataOutEnd = (//RegData[39:24] == 16'hFFD9 |
|
137 |
|
|
RegData[31:16] == 16'hFFD9 |
|
138 |
|
|
RegData[23: 8] == 16'hFFD9 |
|
139 |
|
|
RegData[15: 0] == 16'hFFD9
|
140 |
|
|
);
|
141 |
|
|
|
142 |
|
|
function [31:0] SliceData;
|
143 |
|
|
input [95:0] RegData;
|
144 |
|
|
input [7:0] RegWidth;
|
145 |
|
|
|
146 |
|
|
case(RegWidth)
|
147 |
|
|
8'd65: SliceData = RegData[64:33];
|
148 |
|
|
8'd66: SliceData = RegData[65:34];
|
149 |
|
|
8'd67: SliceData = RegData[66:35];
|
150 |
|
|
8'd68: SliceData = RegData[67:36];
|
151 |
|
|
8'd69: SliceData = RegData[68:37];
|
152 |
|
|
8'd70: SliceData = RegData[69:38];
|
153 |
|
|
8'd71: SliceData = RegData[70:39];
|
154 |
|
|
8'd72: SliceData = RegData[71:40];
|
155 |
|
|
8'd73: SliceData = RegData[72:41];
|
156 |
|
|
8'd74: SliceData = RegData[73:42];
|
157 |
|
|
8'd75: SliceData = RegData[74:43];
|
158 |
|
|
8'd76: SliceData = RegData[75:44];
|
159 |
|
|
8'd77: SliceData = RegData[76:45];
|
160 |
|
|
8'd78: SliceData = RegData[77:46];
|
161 |
|
|
8'd79: SliceData = RegData[78:47];
|
162 |
|
|
8'd80: SliceData = RegData[79:48];
|
163 |
|
|
8'd81: SliceData = RegData[80:49];
|
164 |
|
|
8'd82: SliceData = RegData[81:50];
|
165 |
|
|
8'd83: SliceData = RegData[82:51];
|
166 |
|
|
8'd84: SliceData = RegData[83:52];
|
167 |
|
|
8'd85: SliceData = RegData[84:53];
|
168 |
|
|
8'd86: SliceData = RegData[85:54];
|
169 |
|
|
8'd87: SliceData = RegData[86:55];
|
170 |
|
|
8'd88: SliceData = RegData[87:56];
|
171 |
|
|
8'd89: SliceData = RegData[88:57];
|
172 |
|
|
8'd90: SliceData = RegData[89:58];
|
173 |
|
|
8'd91: SliceData = RegData[90:59];
|
174 |
|
|
8'd92: SliceData = RegData[91:60];
|
175 |
|
|
8'd93: SliceData = RegData[92:61];
|
176 |
|
|
8'd94: SliceData = RegData[93:62];
|
177 |
|
|
8'd95: SliceData = RegData[94:63];
|
178 |
|
|
8'd96: SliceData = RegData[95:64];
|
179 |
|
|
default: SliceData = 32'h00000000;
|
180 |
|
|
endcase // case(RegWidth)
|
181 |
|
|
endfunction // SliceData
|
182 |
|
|
|
183 |
|
|
reg OutEnable;
|
184 |
|
|
reg PreEnable;
|
185 |
|
|
|
186 |
|
|
reg [31:0] DataOut;
|
187 |
|
|
|
188 |
|
|
always @(posedge clk or negedge rst) begin
|
189 |
|
|
if(!rst) begin
|
190 |
|
|
OutEnable <= 1'b0;
|
191 |
|
|
PreEnable <= 1'b0;
|
192 |
|
|
DataOut <= 32'h00000000;
|
193 |
|
|
end else begin
|
194 |
|
|
OutEnable <= RegWidth >64;
|
195 |
|
|
PreEnable <= (UseBit == 1'b1 | UseByte == 1'b1 | UseWord == 1'b1);
|
196 |
|
|
DataOut <= SliceData(RegData,RegWidth);
|
197 |
|
|
end
|
198 |
|
|
end
|
199 |
|
|
|
200 |
|
|
assign DataOutEnable = (PreEnable == 1'b0)?OutEnable:1'b0;
|
201 |
|
|
|
202 |
|
|
endmodule // jpeg_regdata
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|