1 |
2 |
kdv |
/*
|
2 |
|
|
* resample.v
|
3 |
|
|
*
|
4 |
|
|
* Copyright (c) 2007 Koen De Vleeschauwer.
|
5 |
|
|
*
|
6 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
7 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
8 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
9 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
10 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
11 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
12 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
13 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
14 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
15 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
16 |
|
|
* SUCH DAMAGE.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/*
|
20 |
|
|
* resample - Main chroma resampling module. Synchronizes resampling and motion compensation.
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
`include "timescale.v"
|
24 |
|
|
|
25 |
|
|
`undef DEBUG
|
26 |
|
|
//`define DEBUG 1
|
27 |
|
|
|
28 |
|
|
`undef CHECK
|
29 |
|
|
`ifdef __IVERILOG__
|
30 |
|
|
`define CHECK 1
|
31 |
|
|
`endif
|
32 |
|
|
|
33 |
|
|
module resample(
|
34 |
|
|
clk, rst,
|
35 |
|
|
output_frame, output_frame_valid, output_frame_rd,
|
36 |
|
|
progressive_sequence, progressive_frame, top_field_first, repeat_first_field, mb_width, mb_height, horizontal_size, vertical_size, resample_wr_overflow,
|
37 |
|
|
disp_wr_addr_full, disp_wr_addr_almost_full, disp_wr_addr_en, disp_wr_addr_ack, disp_wr_addr, disp_rd_dta_empty, disp_rd_dta_en, disp_rd_dta_valid, disp_rd_dta,
|
38 |
|
|
pixel_wr_almost_full, interlaced, deinterlace, persistence, repeat_frame,
|
39 |
|
|
y, u, v, osd_out, position_out, pixel_wr_en
|
40 |
|
|
);
|
41 |
|
|
|
42 |
|
|
input clk; // clock
|
43 |
|
|
input rst; // synchronous active low reset
|
44 |
|
|
|
45 |
|
|
input [2:0]output_frame; // frame to be displayed
|
46 |
|
|
input output_frame_valid; // asserted when output_frame valid
|
47 |
|
|
output output_frame_rd; // assert for next output frame
|
48 |
|
|
|
49 |
|
|
input progressive_sequence;
|
50 |
|
|
input progressive_frame;
|
51 |
|
|
input top_field_first;
|
52 |
|
|
input repeat_first_field;
|
53 |
|
|
input [7:0]mb_width; // par. 6.3.3. width of the encoded luminance component of pictures in macroblocks
|
54 |
|
|
input [7:0]mb_height; // par. 6.3.3. height of the encoded luminance component of frame pictures in macroblocks
|
55 |
|
|
input [13:0]horizontal_size; // par. 6.2.2.1, par. 6.3.3
|
56 |
|
|
input [13:0]vertical_size; // par. 6.2.2.1, par. 6.3.3
|
57 |
|
|
|
58 |
|
|
/* reading reconstructed frame */
|
59 |
|
|
/* reading reconstructed frame: writing address */
|
60 |
|
|
input disp_wr_addr_full;
|
61 |
|
|
input disp_wr_addr_almost_full;
|
62 |
|
|
output disp_wr_addr_en;
|
63 |
|
|
input disp_wr_addr_ack;
|
64 |
|
|
output [21:0]disp_wr_addr;
|
65 |
|
|
/* reading reconstructed frame: reading data */
|
66 |
|
|
input disp_rd_dta_empty;
|
67 |
|
|
output disp_rd_dta_en;
|
68 |
|
|
input disp_rd_dta_valid;
|
69 |
|
|
input [63:0]disp_rd_dta;
|
70 |
|
|
|
71 |
|
|
input interlaced; // asserted if display modeline is interlaced
|
72 |
|
|
input deinterlace; // asserted if video has to be deinterlaced
|
73 |
|
|
input persistence; // asserted if last shown image persists
|
74 |
|
|
input [4:0]repeat_frame;
|
75 |
|
|
|
76 |
|
|
input pixel_wr_almost_full;
|
77 |
|
|
output [7:0]y;
|
78 |
|
|
output [7:0]u;
|
79 |
|
|
output [7:0]v;
|
80 |
|
|
output [7:0]osd_out;
|
81 |
|
|
output [2:0]position_out;
|
82 |
|
|
output pixel_wr_en;
|
83 |
|
|
|
84 |
|
|
/* resample fifo */
|
85 |
|
|
wire [2:0]resample_wr_dta;
|
86 |
|
|
wire resample_wr_en;
|
87 |
|
|
output resample_wr_overflow; // to probe
|
88 |
|
|
wire resample_wr_almost_full;
|
89 |
|
|
wire [2:0]resample_rd_dta;
|
90 |
|
|
wire resample_rd_en;
|
91 |
|
|
wire resample_rd_valid;
|
92 |
|
|
|
93 |
|
|
wire resample_addr_busy;
|
94 |
|
|
|
95 |
|
|
wire [12:0]mb_width_ext = {5'b0, mb_width};
|
96 |
|
|
|
97 |
|
|
`include "fifo_size.v"
|
98 |
|
|
|
99 |
|
|
// Generates the memory read requests for displaying a frame
|
100 |
|
|
resample_addrgen resample_addrgen (
|
101 |
|
|
.clk(clk),
|
102 |
|
|
.clk_en(1'b1),
|
103 |
|
|
.rst(rst),
|
104 |
|
|
.output_frame(output_frame),
|
105 |
|
|
.output_frame_valid(output_frame_valid),
|
106 |
|
|
.output_frame_rd(output_frame_rd),
|
107 |
|
|
.progressive_sequence(progressive_sequence),
|
108 |
|
|
.progressive_frame(progressive_frame),
|
109 |
|
|
.top_field_first(top_field_first),
|
110 |
|
|
.repeat_first_field(repeat_first_field),
|
111 |
|
|
.mb_width(mb_width),
|
112 |
|
|
.mb_height(mb_height),
|
113 |
|
|
.horizontal_size(horizontal_size),
|
114 |
|
|
.vertical_size(vertical_size),
|
115 |
|
|
|
116 |
|
|
.disp_wr_addr_full(disp_wr_addr_full),
|
117 |
|
|
.disp_wr_addr_en(disp_wr_addr_en),
|
118 |
|
|
.disp_wr_addr_ack(disp_wr_addr_ack),
|
119 |
|
|
.disp_wr_addr(disp_wr_addr),
|
120 |
|
|
|
121 |
|
|
.interlaced(interlaced),
|
122 |
|
|
.deinterlace(deinterlace),
|
123 |
|
|
.persistence(persistence),
|
124 |
|
|
.repeat_frame(repeat_frame),
|
125 |
|
|
|
126 |
|
|
.resample_wr_dta(resample_wr_dta),
|
127 |
|
|
.resample_wr_en(resample_wr_en),
|
128 |
|
|
|
129 |
|
|
.disp_wr_addr_almost_full(disp_wr_addr_almost_full),
|
130 |
|
|
.resample_wr_almost_full(resample_wr_almost_full),
|
131 |
|
|
.busy(resample_addr_busy)
|
132 |
|
|
);
|
133 |
|
|
|
134 |
|
|
wire fifo_read;
|
135 |
|
|
wire fifo_valid;
|
136 |
|
|
wire [127:0]fifo_osd; /* osd data */
|
137 |
|
|
wire [127:0]fifo_y; /* lumi */
|
138 |
|
|
wire [63:0]fifo_u_upper; /* chromi, upper row */
|
139 |
|
|
wire [63:0]fifo_u_lower; /* chromi, lower row */
|
140 |
|
|
wire [63:0]fifo_v_upper; /* chromi, upper row */
|
141 |
|
|
wire [63:0]fifo_v_lower; /* chromi, lower row */
|
142 |
|
|
wire [2:0]fifo_position; /* position of pixels, as in resample_codes */
|
143 |
|
|
|
144 |
|
|
// Reads the pixels from memory fifo
|
145 |
|
|
resample_dta resample_dta (
|
146 |
|
|
.clk(clk),
|
147 |
|
|
.clk_en(1'b1),
|
148 |
|
|
.rst(rst),
|
149 |
|
|
.fifo_read(fifo_read),
|
150 |
|
|
.fifo_valid(fifo_valid),
|
151 |
|
|
.disp_rd_dta_empty(disp_rd_dta_empty),
|
152 |
|
|
.disp_rd_dta_en(disp_rd_dta_en),
|
153 |
|
|
.disp_rd_dta_valid(disp_rd_dta_valid),
|
154 |
|
|
.disp_rd_dta(disp_rd_dta),
|
155 |
|
|
.resample_rd_dta(resample_rd_dta),
|
156 |
|
|
.resample_rd_en(resample_rd_en),
|
157 |
|
|
.resample_rd_valid(resample_rd_valid),
|
158 |
|
|
.fifo_osd(fifo_osd),
|
159 |
|
|
.fifo_y(fifo_y),
|
160 |
|
|
.fifo_u_upper(fifo_u_upper),
|
161 |
|
|
.fifo_u_lower(fifo_u_lower),
|
162 |
|
|
.fifo_v_upper(fifo_v_upper),
|
163 |
|
|
.fifo_v_lower(fifo_v_lower),
|
164 |
|
|
.fifo_position(fifo_position)
|
165 |
|
|
);
|
166 |
|
|
|
167 |
|
|
// bilinear chroma upscaling, 4:2:0 to 4:4:4
|
168 |
|
|
resample_bilinear resample_bilinear (
|
169 |
|
|
.clk(clk),
|
170 |
|
|
.clk_en(1'b1),
|
171 |
|
|
.rst(rst),
|
172 |
|
|
.fifo_read(fifo_read),
|
173 |
|
|
.fifo_valid(fifo_valid),
|
174 |
|
|
.fifo_osd(fifo_osd),
|
175 |
|
|
.fifo_y(fifo_y),
|
176 |
|
|
.fifo_u_upper(fifo_u_upper),
|
177 |
|
|
.fifo_u_lower(fifo_u_lower),
|
178 |
|
|
.fifo_v_upper(fifo_v_upper),
|
179 |
|
|
.fifo_v_lower(fifo_v_lower),
|
180 |
|
|
.fifo_position(fifo_position),
|
181 |
|
|
.y(y),
|
182 |
|
|
.u(u),
|
183 |
|
|
.v(v),
|
184 |
|
|
.osd_out(osd_out),
|
185 |
|
|
.position_out(position_out),
|
186 |
|
|
.pixel_wr_en(pixel_wr_en),
|
187 |
|
|
.pixel_wr_almost_full(pixel_wr_almost_full)
|
188 |
|
|
);
|
189 |
|
|
|
190 |
|
|
// fifo between resample_addr and resample_dta
|
191 |
|
|
fifo_sc
|
192 |
|
|
#(.addr_width(RESAMPLE_DEPTH),
|
193 |
|
|
.dta_width(9'd3),
|
194 |
|
|
.prog_thresh(RESAMPLE_THRESHOLD))
|
195 |
|
|
resample_fifo (
|
196 |
|
|
.rst(rst),
|
197 |
|
|
.clk(clk),
|
198 |
|
|
.din(resample_wr_dta),
|
199 |
|
|
.wr_en(resample_wr_en),
|
200 |
|
|
.full(),
|
201 |
|
|
.wr_ack(),
|
202 |
|
|
.overflow(resample_wr_overflow),
|
203 |
|
|
.prog_full(resample_wr_almost_full),
|
204 |
|
|
.dout(resample_rd_dta),
|
205 |
|
|
.rd_en(resample_rd_en),
|
206 |
|
|
.prog_empty(),
|
207 |
|
|
.empty(),
|
208 |
|
|
.valid(resample_rd_valid),
|
209 |
|
|
.underflow()
|
210 |
|
|
);
|
211 |
|
|
|
212 |
|
|
`ifdef CHECK
|
213 |
|
|
always @(posedge clk)
|
214 |
|
|
if (resample_wr_overflow)
|
215 |
|
|
begin
|
216 |
|
|
#0 $display("%m\t*** error: resample_fifo overflow. **");
|
217 |
|
|
$stop;
|
218 |
|
|
end
|
219 |
|
|
`endif
|
220 |
|
|
|
221 |
|
|
`ifdef DEBUG
|
222 |
|
|
|
223 |
|
|
always @(posedge clk)
|
224 |
|
|
$strobe("%m\toutput_frame: %d output_frame_valid: %d addr_clk_en: %d",
|
225 |
|
|
output_frame, output_frame_valid, addr_clk_en);
|
226 |
|
|
|
227 |
|
|
always @(posedge clk)
|
228 |
|
|
if (disp_wr_addr_almost_full)
|
229 |
|
|
$display("%m\taddr_clk_en: disp_wr_addr_almost_full");
|
230 |
|
|
|
231 |
|
|
`endif
|
232 |
|
|
endmodule
|
233 |
|
|
/* not truncated */
|