1 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
2 |
9 |
hidemi |
// File Name : jpeg_idctb.v
|
3 |
|
|
// Module Name : jpeg_idctb
|
4 |
|
|
// Description : data register for iDCT
|
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 : 2008/03/19
|
11 |
|
|
// Rev. : 2.00
|
12 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
13 |
|
|
// Rev. Date Description
|
14 |
|
|
//---------------------------------------------------------------------------
|
15 |
|
|
// 1.01 2006/10/01 1st Release
|
16 |
9 |
hidemi |
// 2.00 2008/03/19 Replace to RAM from D-FF
|
17 |
3 |
hidemi |
//---------------------------------------------------------------------------
|
18 |
|
|
`timescale 1ps / 1ps
|
19 |
|
|
|
20 |
9 |
hidemi |
module jpeg_idctb(
|
21 |
|
|
rst,
|
22 |
|
|
clk,
|
23 |
3 |
hidemi |
|
24 |
9 |
hidemi |
DataInit,
|
25 |
3 |
hidemi |
|
26 |
9 |
hidemi |
DataInEnable,
|
27 |
|
|
DataInPage,
|
28 |
|
|
DataInCount,
|
29 |
|
|
DataInIdle,
|
30 |
|
|
DataInA,
|
31 |
|
|
DataInB,
|
32 |
3 |
hidemi |
|
33 |
9 |
hidemi |
DataOutEnable,
|
34 |
|
|
DataOutRead,
|
35 |
|
|
DataOutAddress,
|
36 |
|
|
DataOutA,
|
37 |
|
|
DataOutB
|
38 |
|
|
);
|
39 |
3 |
hidemi |
|
40 |
9 |
hidemi |
input clk;
|
41 |
|
|
input rst;
|
42 |
3 |
hidemi |
|
43 |
9 |
hidemi |
input DataInit;
|
44 |
|
|
|
45 |
|
|
input DataInEnable;
|
46 |
|
|
input [2:0] DataInPage;
|
47 |
|
|
input [1:0] DataInCount;
|
48 |
|
|
output DataInIdle;
|
49 |
|
|
input [15:0] DataInA;
|
50 |
|
|
input [15:0] DataInB;
|
51 |
|
|
|
52 |
|
|
output DataOutEnable;
|
53 |
|
|
input DataOutRead;
|
54 |
|
|
input [4:0] DataOutAddress;
|
55 |
|
|
output [15:0] DataOutA;
|
56 |
|
|
output [15:0] DataOutB;
|
57 |
|
|
|
58 |
|
|
wire [4:0] DataInAddress;
|
59 |
|
|
reg [1:0] WriteBank, ReadBank;
|
60 |
3 |
hidemi |
|
61 |
9 |
hidemi |
assign DataInAddress = {DataInPage, DataInCount};
|
62 |
3 |
hidemi |
|
63 |
9 |
hidemi |
// Bank
|
64 |
|
|
always @(posedge clk or negedge rst) begin
|
65 |
|
|
if(!rst) begin
|
66 |
|
|
WriteBank <= 2'd0;
|
67 |
|
|
ReadBank <= 2'd0;
|
68 |
|
|
end else begin
|
69 |
|
|
if(DataInit) begin
|
70 |
|
|
WriteBank <= 2'd0;
|
71 |
|
|
end else if(DataInEnable && (DataInAddress == 5'h1F)) begin
|
72 |
|
|
WriteBank <= WriteBank + 2'd1;
|
73 |
3 |
hidemi |
end
|
74 |
9 |
hidemi |
if(DataInit) begin
|
75 |
|
|
ReadBank <= 2'd0;
|
76 |
|
|
end else if(DataOutRead && (DataOutAddress == 5'h1F)) begin
|
77 |
|
|
ReadBank <= ReadBank + 2'd1;
|
78 |
3 |
hidemi |
end
|
79 |
9 |
hidemi |
end
|
80 |
|
|
end
|
81 |
3 |
hidemi |
|
82 |
9 |
hidemi |
wire [5:0] WriteQueryA, WriteQueryB;
|
83 |
3 |
hidemi |
|
84 |
9 |
hidemi |
// Make a Write Address
|
85 |
|
|
function [5:0] F_WriteQueryA;
|
86 |
|
|
input [4:0] Count;
|
87 |
|
|
case(Count)
|
88 |
|
|
5'd0: F_WriteQueryA = {1'd0, 5'd0}; // 0
|
89 |
|
|
5'd1: F_WriteQueryA = {1'd0, 5'd4}; // 1
|
90 |
|
|
5'd2: F_WriteQueryA = {1'd0, 5'd8}; // 2
|
91 |
|
|
5'd3: F_WriteQueryA = {1'd0, 5'd12}; // 3
|
92 |
|
|
5'd4: F_WriteQueryA = {1'd0, 5'd2}; // 8
|
93 |
|
|
5'd5: F_WriteQueryA = {1'd0, 5'd6}; // 9
|
94 |
|
|
5'd6: F_WriteQueryA = {1'd0, 5'd10}; // 10
|
95 |
|
|
5'd7: F_WriteQueryA = {1'd0, 5'd14}; // 11
|
96 |
|
|
5'd8: F_WriteQueryA = {1'd0, 5'd1}; // 16
|
97 |
|
|
5'd9: F_WriteQueryA = {1'd0, 5'd5}; // 17
|
98 |
|
|
5'd10: F_WriteQueryA = {1'd0, 5'd9}; // 18
|
99 |
|
|
5'd11: F_WriteQueryA = {1'd0, 5'd13}; // 19
|
100 |
|
|
5'd12: F_WriteQueryA = {1'd1, 5'd3}; // 24
|
101 |
|
|
5'd13: F_WriteQueryA = {1'd1, 5'd7}; // 25
|
102 |
|
|
5'd14: F_WriteQueryA = {1'd1, 5'd11}; // 26
|
103 |
|
|
5'd15: F_WriteQueryA = {1'd1, 5'd15}; // 27
|
104 |
|
|
5'd16: F_WriteQueryA = {1'd1, 5'd0}; // 32
|
105 |
|
|
5'd17: F_WriteQueryA = {1'd1, 5'd4}; // 33
|
106 |
|
|
5'd18: F_WriteQueryA = {1'd1, 5'd8}; // 34
|
107 |
|
|
5'd19: F_WriteQueryA = {1'd1, 5'd12}; // 35
|
108 |
|
|
5'd20: F_WriteQueryA = {1'd0, 5'd3}; // 40
|
109 |
|
|
5'd21: F_WriteQueryA = {1'd0, 5'd7}; // 41
|
110 |
|
|
5'd22: F_WriteQueryA = {1'd0, 5'd11}; // 42
|
111 |
|
|
5'd23: F_WriteQueryA = {1'd0, 5'd15}; // 43
|
112 |
|
|
5'd24: F_WriteQueryA = {1'd1, 5'd1}; // 48
|
113 |
|
|
5'd25: F_WriteQueryA = {1'd1, 5'd5}; // 49
|
114 |
|
|
5'd26: F_WriteQueryA = {1'd1, 5'd9}; // 50
|
115 |
|
|
5'd27: F_WriteQueryA = {1'd1, 5'd13}; // 51
|
116 |
|
|
5'd28: F_WriteQueryA = {1'd1, 5'd2}; // 56
|
117 |
|
|
5'd29: F_WriteQueryA = {1'd1, 5'd6}; // 57
|
118 |
|
|
5'd30: F_WriteQueryA = {1'd1, 5'd10}; // 58
|
119 |
|
|
5'd31: F_WriteQueryA = {1'd1, 5'd14}; // 59
|
120 |
|
|
endcase
|
121 |
|
|
endfunction
|
122 |
3 |
hidemi |
|
123 |
9 |
hidemi |
function [5:0] F_WriteQueryB;
|
124 |
|
|
input [4:0] Count;
|
125 |
|
|
case(Count)
|
126 |
|
|
5'd0: F_WriteQueryB = {1'd1, 5'd28}; // 7
|
127 |
|
|
5'd1: F_WriteQueryB = {1'd1, 5'd24}; // 6
|
128 |
|
|
5'd2: F_WriteQueryB = {1'd1, 5'd20}; // 5
|
129 |
|
|
5'd3: F_WriteQueryB = {1'd1, 5'd16}; // 4
|
130 |
|
|
5'd4: F_WriteQueryB = {1'd1, 5'd30}; // 15
|
131 |
|
|
5'd5: F_WriteQueryB = {1'd1, 5'd26}; // 14
|
132 |
|
|
5'd6: F_WriteQueryB = {1'd1, 5'd22}; // 13
|
133 |
|
|
5'd7: F_WriteQueryB = {1'd1, 5'd18}; // 12
|
134 |
|
|
5'd8: F_WriteQueryB = {1'd1, 5'd29}; // 23
|
135 |
|
|
5'd9: F_WriteQueryB = {1'd1, 5'd25}; // 22
|
136 |
|
|
5'd10: F_WriteQueryB = {1'd1, 5'd21}; // 21
|
137 |
|
|
5'd11: F_WriteQueryB = {1'd1, 5'd17}; // 20
|
138 |
|
|
5'd12: F_WriteQueryB = {1'd0, 5'd31}; // 31
|
139 |
|
|
5'd13: F_WriteQueryB = {1'd0, 5'd27}; // 30
|
140 |
|
|
5'd14: F_WriteQueryB = {1'd0, 5'd23}; // 29
|
141 |
|
|
5'd15: F_WriteQueryB = {1'd0, 5'd19}; // 28
|
142 |
|
|
5'd16: F_WriteQueryB = {1'd0, 5'd28}; // 39
|
143 |
|
|
5'd17: F_WriteQueryB = {1'd0, 5'd24}; // 38
|
144 |
|
|
5'd18: F_WriteQueryB = {1'd0, 5'd20}; // 37
|
145 |
|
|
5'd19: F_WriteQueryB = {1'd0, 5'd16}; // 36
|
146 |
|
|
5'd20: F_WriteQueryB = {1'd1, 5'd31}; // 47
|
147 |
|
|
5'd21: F_WriteQueryB = {1'd1, 5'd27}; // 46
|
148 |
|
|
5'd22: F_WriteQueryB = {1'd1, 5'd23}; // 45
|
149 |
|
|
5'd23: F_WriteQueryB = {1'd1, 5'd19}; // 44
|
150 |
|
|
5'd24: F_WriteQueryB = {1'd0, 5'd29}; // 55
|
151 |
|
|
5'd25: F_WriteQueryB = {1'd0, 5'd25}; // 54
|
152 |
|
|
5'd26: F_WriteQueryB = {1'd0, 5'd21}; // 53
|
153 |
|
|
5'd27: F_WriteQueryB = {1'd0, 5'd17}; // 52
|
154 |
|
|
5'd28: F_WriteQueryB = {1'd0, 5'd30}; // 63
|
155 |
|
|
5'd29: F_WriteQueryB = {1'd0, 5'd26}; // 62
|
156 |
|
|
5'd30: F_WriteQueryB = {1'd0, 5'd22}; // 61
|
157 |
|
|
5'd31: F_WriteQueryB = {1'd0, 5'd18}; // 60
|
158 |
|
|
endcase
|
159 |
|
|
endfunction
|
160 |
3 |
hidemi |
|
161 |
9 |
hidemi |
assign WriteQueryA = F_WriteQueryA(DataInAddress);
|
162 |
|
|
assign WriteQueryB = F_WriteQueryB(DataInAddress);
|
163 |
|
|
|
164 |
|
|
// RAM(16bit x 32word x 2Bank)
|
165 |
|
|
reg [15:0] MemoryA [0:127];
|
166 |
|
|
reg [15:0] MemoryB [0:127];
|
167 |
3 |
hidemi |
|
168 |
9 |
hidemi |
wire [6:0] WriteAddressA, WriteAddressB;
|
169 |
|
|
wire [15:0] WriteDataA, WriteDataB;
|
170 |
|
|
|
171 |
|
|
assign WriteAddressA = {WriteBank, (WriteQueryA[5])?WriteQueryB[4:0]:WriteQueryA[4:0]};
|
172 |
|
|
assign WriteAddressB = {WriteBank, (WriteQueryB[5])?WriteQueryB[4:0]:WriteQueryA[4:0]};
|
173 |
|
|
|
174 |
|
|
assign WriteDataA = (WriteQueryA[5])?DataInB:DataInA;
|
175 |
|
|
assign WriteDataB = (WriteQueryB[5])?DataInB:DataInA;
|
176 |
|
|
|
177 |
|
|
// Port A(Write Only)
|
178 |
|
|
always @(posedge clk) begin
|
179 |
|
|
if(DataInEnable) MemoryA[WriteAddressA] <= WriteDataA;
|
180 |
|
|
if(DataInEnable) MemoryB[WriteAddressB] <= WriteDataB;
|
181 |
|
|
end
|
182 |
|
|
|
183 |
|
|
reg [15:0] RegMemoryA, RegMemoryB;
|
184 |
|
|
|
185 |
|
|
// Port B(Read/Wirte)
|
186 |
|
|
always @(posedge clk) begin
|
187 |
|
|
RegMemoryA <= MemoryA[{ReadBank, DataOutAddress}];
|
188 |
|
|
RegMemoryB <= MemoryB[{ReadBank, DataOutAddress}];
|
189 |
|
|
end
|
190 |
|
|
|
191 |
|
|
assign DataOutEnable = (WriteBank != ReadBank);
|
192 |
|
|
assign DataOutA = (DataOutAddress[4])?RegMemoryB:RegMemoryA;
|
193 |
|
|
assign DataOutB = (DataOutAddress[4])?RegMemoryA:RegMemoryB;
|
194 |
|
|
|
195 |
|
|
endmodule
|