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

Subversion Repositories mpeg2fpga

[/] [mpeg2fpga/] [trunk/] [rtl/] [mpeg2/] [motcomp.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kdv
/*
2
 * motcomp.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
 * motcomp - 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 motcomp(
34
  clk, clk_en, rst, busy,
35
  picture_coding_type, picture_structure, motion_type, dct_type,
36
  macroblock_address, macroblock_motion_forward, macroblock_motion_backward, macroblock_intra,
37
  mb_width, mb_height, horizontal_size, vertical_size, chroma_format,
38
  motion_vector_valid,
39
  pmv_0_0_0, pmv_0_0_1, pmv_1_0_0, pmv_1_0_1, pmv_0_1_0, pmv_0_1_1, pmv_1_1_0, pmv_1_1_1,
40
  dmv_0_0, dmv_0_1, dmv_1_0, dmv_1_1,
41
  motion_vert_field_select_0_0, motion_vert_field_select_0_1, motion_vert_field_select_1_0, motion_vert_field_select_1_1,
42
  second_field, update_picture_buffers, progressive_sequence, progressive_frame, top_field_first, repeat_first_field, last_frame,
43
  idct_rd_dta_empty, idct_rd_dta_en, idct_rd_dta, idct_rd_dta_valid, frame_idct_wr_overflow, dct_block_wr_overflow, mvec_wr_almost_full, mvec_wr_overflow, dst_wr_overflow,
44
  source_select,
45
  fwd_wr_addr_clk_en, fwd_wr_addr_full, fwd_wr_addr_almost_full, fwd_wr_addr_en, fwd_wr_addr_ack, fwd_wr_addr, fwd_rd_dta_clk_en, fwd_rd_dta_empty, fwd_rd_dta_en, fwd_rd_dta_valid, fwd_rd_dta,
46
  bwd_wr_addr_clk_en, bwd_wr_addr_full, bwd_wr_addr_almost_full, bwd_wr_addr_en, bwd_wr_addr_ack, bwd_wr_addr, bwd_rd_dta_clk_en, bwd_rd_dta_empty, bwd_rd_dta_en, bwd_rd_dta_valid, bwd_rd_dta,
47
  recon_wr_full, recon_wr_almost_full, recon_wr_en, recon_wr_ack, recon_wr_addr, recon_wr_dta,
48
  output_frame, output_frame_valid, output_frame_rd, output_progressive_sequence, output_progressive_frame, output_top_field_first, output_repeat_first_field
49
  );
50
 
51
  input              clk;                      // clock
52
  input              clk_en;                   // clock enable
53
  input              rst;                      // synchronous active low reset
54
  output reg         busy;                     // addrgen freezes vld while processing motion vectors 
55
 
56
  input         [2:0]picture_coding_type;      // identifies whether a picture is an I, P or B picture.
57
  input         [1:0]picture_structure;        // one of FRAME_PICTURE, TOP_FIELD or BOTTOM_FIELD
58
  input         [1:0]motion_type;              // one of MC_FIELD, MC_FRAME, MC_16X8 or MC_DMV
59
  input              dct_type;                 // dct_type == 1 : field dct coded; dct_type == 0 : frame dct coded
60
  input        [12:0]macroblock_address;       // absolute position of the current macroblock. top-left macroblock has macroblock_address zero.
61
  input              macroblock_motion_forward;
62
  input              macroblock_motion_backward;
63
  input              macroblock_intra;
64
  input         [7:0]mb_width;                 // par. 6.3.3. width of the encoded luminance component of pictures in macroblocks
65
  input         [7:0]mb_height;                // par. 6.3.3. height of the encoded luminance component of frame pictures in macroblocks
66
  input        [13:0]horizontal_size;               /* par. 6.2.2.1, par. 6.3.3 */
67
  input        [13:0]vertical_size;                 /* par. 6.2.2.1, par. 6.3.3 */
68
  input         [1:0]chroma_format;
69
  input              motion_vector_valid;      // asserted when pmv_x_x_x, dmv_x_x valid
70
  input signed [12:0]pmv_0_0_0;                // predicted motion vector
71
  input signed [12:0]pmv_0_0_1;                // predicted motion vector
72
  input signed [12:0]pmv_1_0_0;                // predicted motion vector
73
  input signed [12:0]pmv_1_0_1;                // predicted motion vector
74
  input signed [12:0]pmv_0_1_0;                // predicted motion vector
75
  input signed [12:0]pmv_0_1_1;                // predicted motion vector
76
  input signed [12:0]pmv_1_1_0;                // predicted motion vector
77
  input signed [12:0]pmv_1_1_1;                // predicted motion vector
78
  input signed [12:0]dmv_0_0;                  // dual-prime motion vector.
79
  input signed [12:0]dmv_0_1;                  // dual-prime motion vector.
80
  input signed [12:0]dmv_1_0;                  // dual-prime motion vector.
81
  input signed [12:0]dmv_1_1;                  // dual-prime motion vector.
82
  input              motion_vert_field_select_0_0;
83
  input              motion_vert_field_select_0_1;
84
  input              motion_vert_field_select_1_0;
85
  input              motion_vert_field_select_1_1;
86
  input              second_field;
87
  input              update_picture_buffers;
88
  input              progressive_sequence;
89
  input              progressive_frame;
90
  input              top_field_first;
91
  input              repeat_first_field;
92
  input              last_frame;
93
 
94
  /* for probe */
95
  output             dct_block_wr_overflow;
96
  output             frame_idct_wr_overflow;
97
  /* reading idct coefficients */
98
  input              idct_rd_dta_empty;
99
  output             idct_rd_dta_en;
100
  input        [71:0]idct_rd_dta;
101
  input              idct_rd_dta_valid;
102
 
103
  /* trick modes */
104
  input         [2:0]source_select;                 /* select video out source */
105
 
106
  /* reading forward reference frame */
107
  /* reading forward reference frame: writing address */
108
  output           fwd_wr_addr_clk_en;
109
  input            fwd_wr_addr_full;
110
  input            fwd_wr_addr_almost_full;
111
  output           fwd_wr_addr_en;
112
  input            fwd_wr_addr_ack;
113
  output     [21:0]fwd_wr_addr;
114
  /* reading forward reference frame: reading data */
115
  output           fwd_rd_dta_clk_en;
116
  input            fwd_rd_dta_empty;
117
  output           fwd_rd_dta_en;
118
  input            fwd_rd_dta_valid;
119
  input      [63:0]fwd_rd_dta;
120
 
121
  /* reading backward reference frame: writing address */
122
  output           bwd_wr_addr_clk_en;
123
  input            bwd_wr_addr_full;
124
  input            bwd_wr_addr_almost_full;
125
  output           bwd_wr_addr_en;
126
  input            bwd_wr_addr_ack;
127
  output     [21:0]bwd_wr_addr;
128
  /* reading backward reference frame: reading data */
129
  output           bwd_rd_dta_clk_en;
130
  input            bwd_rd_dta_empty;
131
  output           bwd_rd_dta_en;
132
  input            bwd_rd_dta_valid;
133
  input      [63:0]bwd_rd_dta;
134
 
135
  /* writing reconstructed frame: writing address and data */
136
  input            recon_wr_full;
137
  input            recon_wr_almost_full;
138
  input            recon_wr_ack;
139
  output           recon_wr_en;
140
  output     [21:0]recon_wr_addr;
141
  output     [63:0]recon_wr_dta;
142
 
143
  /* frame being displayed */
144
  output       [2:0]output_frame;                 /* frame to be displayed. Has value 2'd0, 2'd1 or 2'd2 */
145
  output            output_frame_valid;           /* asserted when output_frame valid */
146
  input             output_frame_rd;              /* asserted to read next output_frame */
147
  output            output_progressive_sequence;
148
  output            output_progressive_frame;
149
  output            output_top_field_first;
150
  output            output_repeat_first_field;
151
  wire              picbuf_busy;
152
 
153
  /* motion vector fifo */
154
 
155
  /* writing motion vector fifo */
156
  wire               mvec_wr_full;
157
  output             mvec_wr_almost_full;
158
  wire               mvec_wr_ack;
159
  output             mvec_wr_overflow;
160
 
161
  reg                mvec_wr_en;
162
  reg         [187:0]mvec_wr_dta;
163
  wire        [187:0]mvec_rd_dta;
164
 
165
  /* fwft reading motion vector fifo */
166
  wire               mvec_rd_dta_en;
167
  wire               mvec_rd_dta_valid;
168
  wire               mvec_rd_en;
169
  wire               mvec_rd_valid;
170
 
171
  wire          [2:0]mvec_rd_picture_coding_type;
172
  wire          [1:0]mvec_rd_picture_structure;
173
  wire          [1:0]mvec_rd_motion_type;
174
  wire               mvec_rd_dct_type;
175
  wire         [12:0]mvec_rd_macroblock_address;
176
  wire               mvec_rd_macroblock_motion_forward;
177
  wire               mvec_rd_macroblock_motion_backward;
178
  wire               mvec_rd_macroblock_intra;
179
  wire  signed [12:0]mvec_rd_pmv_0_0_0;
180
  wire  signed [12:0]mvec_rd_pmv_0_0_1;
181
  wire  signed [12:0]mvec_rd_pmv_1_0_0;
182
  wire  signed [12:0]mvec_rd_pmv_1_0_1;
183
  wire  signed [12:0]mvec_rd_pmv_0_1_0;
184
  wire  signed [12:0]mvec_rd_pmv_0_1_1;
185
  wire  signed [12:0]mvec_rd_pmv_1_1_0;
186
  wire  signed [12:0]mvec_rd_pmv_1_1_1;
187
  wire  signed [12:0]mvec_rd_dmv_0_0;
188
  wire  signed [12:0]mvec_rd_dmv_0_1;
189
  wire  signed [12:0]mvec_rd_dmv_1_0;
190
  wire  signed [12:0]mvec_rd_dmv_1_1;
191
  wire               mvec_rd_motion_vert_field_select_0_0;
192
  wire               mvec_rd_motion_vert_field_select_0_1;
193
  wire               mvec_rd_motion_vert_field_select_1_0;
194
  wire               mvec_rd_motion_vert_field_select_1_1;
195
  wire               mvec_rd_second_field;
196
  wire               mvec_rd_update_picture_buffers;
197
  wire               mvec_rd_last_frame;
198
  wire               mvec_rd_motion_vector_valid;
199
 
200
  /* block reconstruction fifo */
201
  /* writing block reconstruction fifo */
202
  wire             dst_wr_full;
203
  wire             dst_wr_almost_full;
204
  wire             dst_wr_en;
205
  wire             dst_wr_ack;
206
  output           dst_wr_overflow;
207
  wire             dst_wr_write_recon;
208
  wire       [21:0]dst_wr_write_address;
209
  wire             dst_wr_motion_forward;
210
  wire        [2:0]dst_wr_fwd_hor_offset;
211
  wire             dst_wr_fwd_hor_halfpixel;
212
  wire             dst_wr_fwd_ver_halfpixel;
213
  wire             dst_wr_motion_backward;
214
  wire        [2:0]dst_wr_bwd_hor_offset;
215
  wire             dst_wr_bwd_hor_halfpixel;
216
  wire             dst_wr_bwd_ver_halfpixel;
217
  /* reading block reconstruction fifo */
218
  wire             dst_rd_empty;
219
  wire             dst_rd_en;
220
  wire             dst_rd_valid;
221
  wire       [34:0]dst_rd_dta;
222
 
223
  /* dct type fifo */
224
  /* writing dct type fifo */
225
  wire             dct_block_wr_full;
226
  wire             dct_block_wr_almost_full;
227
  wire             dct_block_wr_en;
228
  wire        [2:0]dct_block_wr_cmd;
229
  /* reading dct type fifo */
230
  wire             dct_block_rd_empty;
231
  wire             dct_block_rd_en;
232
  wire             dct_block_rd_valid;
233
  wire        [2:0]dct_block_rd_cmd;
234
 
235
  /* idct data after conversion to frame coding */
236
  wire             frame_idct_dta_empty;
237
  wire       [71:0]frame_idct_dta;
238
  wire             frame_idct_dta_en;
239
  wire             frame_idct_dta_valid;
240
 
241
 
242
  assign fwd_wr_addr_clk_en = clk_en;
243
  assign fwd_rd_dta_clk_en = clk_en;
244
 
245
  assign bwd_wr_addr_clk_en = clk_en;
246
  assign bwd_rd_dta_clk_en = clk_en;
247
 
248
 
249
  /* freeze vld when vld asserts update_picture_buffers until motcomp_picbuf has updated the picture buffers.
250
     Else vld might generate motion vectors for the new frame before current_frame, forward and backward reference frame have been updated.
251
     Algorithm: assert flush_mvec_fifo when update_picture_buffers enters the mvec motion vector fifo, and clear flush_mvec_fifo when picbuf takes over. */
252
 
253
  reg              flush_mvec_fifo;
254
 
255
  always @(posedge clk)
256
    if (~ rst) flush_mvec_fifo <= 1'b0;
257
    else if (update_picture_buffers) flush_mvec_fifo <= 1'b1;
258
    else if (picbuf_busy) flush_mvec_fifo <= 1'b0;
259
    else flush_mvec_fifo <= flush_mvec_fifo;
260
 
261
  /* freeze vld when vld asserts update_picture_buffers; release vld when motcomp_picbuf has updated the picture buffers  */
262
  always @(posedge clk)
263
    if (~ rst) busy <= 1'b0;
264
    else if (update_picture_buffers) busy <= 1'b1;
265
    else busy <= flush_mvec_fifo || picbuf_busy;
266
 
267
`include "fifo_size.v"
268
`include "vld_codes.v"
269
 
270
  always @(posedge clk)
271
    if (~ rst) mvec_wr_dta <= 188'b0;
272
    else if (clk_en) mvec_wr_dta <= {picture_coding_type, picture_structure, motion_type, dct_type, macroblock_address, macroblock_motion_forward, macroblock_motion_backward, macroblock_intra, pmv_0_0_0, pmv_0_0_1, pmv_1_0_0, pmv_1_0_1, pmv_0_1_0, pmv_0_1_1, pmv_1_1_0, pmv_1_1_1, dmv_0_0, dmv_0_1, dmv_1_0, dmv_1_1, motion_vert_field_select_0_0, motion_vert_field_select_0_1, motion_vert_field_select_1_0, motion_vert_field_select_1_1, second_field, last_frame, update_picture_buffers, motion_vector_valid};
273
    else mvec_wr_dta <= mvec_wr_dta;
274
 
275
  always @(posedge clk)
276
    if (~ rst) mvec_wr_en <= 1'b0;
277
    else mvec_wr_en <= (motion_vector_valid || update_picture_buffers) && clk_en;
278
 
279
  /* motion vector fifo */
280
  fifo_sc
281
    #(.addr_width(MVEC_DEPTH),
282
    .prog_thresh(MVEC_THRESHOLD),
283
    .dta_width(9'd188))
284
    mvec_fifo (
285
    .rst(rst),
286
    .clk(clk),
287
    .din(mvec_wr_dta),
288
    .wr_en(mvec_wr_en),
289
    .full(mvec_wr_full),
290
    .wr_ack(mvec_wr_ack),
291
    .overflow(mvec_wr_overflow),
292
    .prog_full(mvec_wr_almost_full),
293
    .dout(mvec_rd_dta),
294
    .rd_en(mvec_rd_dta_en),
295
    .empty(),
296
    .valid(mvec_rd_dta_valid),
297
    .underflow(),
298
    .prog_empty()
299
    );
300
 
301
  fwft_reader #(.dta_width(9'd188)) mvec_fwft_reader (
302
    .rst(rst),
303
    .clk(clk),
304
    .clk_en(clk_en),
305
    .fifo_rd_en(mvec_rd_dta_en),
306
    .fifo_valid(mvec_rd_dta_valid),
307
    .fifo_dout(mvec_rd_dta),
308
    .valid(mvec_rd_valid),
309
    .dout({mvec_rd_picture_coding_type, mvec_rd_picture_structure, mvec_rd_motion_type, mvec_rd_dct_type, mvec_rd_macroblock_address, mvec_rd_macroblock_motion_forward, mvec_rd_macroblock_motion_backward, mvec_rd_macroblock_intra, mvec_rd_pmv_0_0_0, mvec_rd_pmv_0_0_1, mvec_rd_pmv_1_0_0, mvec_rd_pmv_1_0_1, mvec_rd_pmv_0_1_0, mvec_rd_pmv_0_1_1, mvec_rd_pmv_1_1_0, mvec_rd_pmv_1_1_1, mvec_rd_dmv_0_0, mvec_rd_dmv_0_1, mvec_rd_dmv_1_0, mvec_rd_dmv_1_1, mvec_rd_motion_vert_field_select_0_0, mvec_rd_motion_vert_field_select_0_1, mvec_rd_motion_vert_field_select_1_0, mvec_rd_motion_vert_field_select_1_1, mvec_rd_second_field, mvec_rd_last_frame, mvec_rd_update_picture_buffers, mvec_rd_motion_vector_valid}),
310
    .rd_en(mvec_rd_en)
311
    );
312
 
313
 
314
  /* block reconstruction fifo */
315
  fifo_sc
316
    #(.addr_width(DST_DEPTH),
317
    .prog_thresh(DST_THRESHOLD),
318
    .dta_width(9'd35)) // same value for fifo_threshold fwd_reader, bwd_reader and prog_thresh dst_fifo
319
    dst_fifo (
320
    .rst(rst),
321
    .clk(clk),
322
    .din({dst_wr_write_recon, dst_wr_write_address, dst_wr_motion_forward, dst_wr_fwd_hor_offset, dst_wr_fwd_hor_halfpixel, dst_wr_fwd_ver_halfpixel, dst_wr_motion_backward, dst_wr_bwd_hor_offset, dst_wr_bwd_hor_halfpixel, dst_wr_bwd_ver_halfpixel}),
323
    .wr_en(dst_wr_en && clk_en),
324
    .full(dst_wr_full),
325
    .wr_ack(dst_wr_ack),
326
    .overflow(dst_wr_overflow),
327
    .prog_full(dst_wr_almost_full),
328
    .dout(dst_rd_dta),
329
    .rd_en(dst_rd_en && clk_en),
330
    .empty(dst_rd_empty),
331
    .valid(dst_rd_valid),
332
    .underflow(),
333
    .prog_empty()
334
    );
335
 
336
  /* dct type fifo */
337
  fifo_sc
338
    #(.addr_width(DST_DEPTH-9'd3),
339
    .prog_thresh(9'd6), // 6 = number of blocks in a macroblock (4:2:0). Hence if ~dct_block_wr_almost_full there's enough room to write the commands for a complete macroblock.
340
    .dta_width(9'd3))
341
    dct_type_fifo (
342
    .rst(rst),
343
    .clk(clk),
344
    .din({dct_block_wr_cmd}),
345
    .wr_en(dct_block_wr_en && clk_en),
346
    .full(dct_block_wr_full),
347
    .wr_ack(),
348
    .overflow(dct_block_wr_overflow),
349
    .prog_full(dct_block_wr_almost_full),
350
    .dout({dct_block_rd_cmd}),
351
    .rd_en(dct_block_rd_en && clk_en),
352
    .empty(dct_block_rd_empty),
353
    .valid(dct_block_rd_valid),
354
    .underflow(),
355
    .prog_empty()
356
    );
357
 
358
  /* address generation */
359
  motcomp_addrgen motcomp_addrgen (
360
    .clk(clk),
361
    .clk_en(clk_en),
362
    .rst(rst),
363
 
364
    .mvec_rd_en(mvec_rd_en),
365
    .mvec_rd_valid(mvec_rd_valid),
366
 
367
    .picture_coding_type(mvec_rd_picture_coding_type),
368
    .picture_structure(mvec_rd_picture_structure),
369
    .motion_type(mvec_rd_motion_type),
370
    .dct_type(mvec_rd_dct_type),
371
    .macroblock_address(mvec_rd_macroblock_address),
372
    .macroblock_motion_forward(mvec_rd_macroblock_motion_forward),
373
    .macroblock_motion_backward(mvec_rd_macroblock_motion_backward),
374
    .macroblock_intra(mvec_rd_macroblock_intra),
375
    .mb_width(mb_width),
376
    .mb_height(mb_height),
377
    .horizontal_size(horizontal_size),
378
    .vertical_size(vertical_size),
379
    .chroma_format(chroma_format),
380
    .pmv_0_0_0(mvec_rd_pmv_0_0_0),
381
    .pmv_0_0_1(mvec_rd_pmv_0_0_1),
382
    .pmv_1_0_0(mvec_rd_pmv_1_0_0),
383
    .pmv_1_0_1(mvec_rd_pmv_1_0_1),
384
    .pmv_0_1_0(mvec_rd_pmv_0_1_0),
385
    .pmv_0_1_1(mvec_rd_pmv_0_1_1),
386
    .pmv_1_1_0(mvec_rd_pmv_1_1_0),
387
    .pmv_1_1_1(mvec_rd_pmv_1_1_1),
388
    .dmv_0_0(mvec_rd_dmv_0_0),
389
    .dmv_0_1(mvec_rd_dmv_0_1),
390
    .dmv_1_0(mvec_rd_dmv_1_0),
391
    .dmv_1_1(mvec_rd_dmv_1_1),
392
    .motion_vert_field_select_0_0(mvec_rd_motion_vert_field_select_0_0),
393
    .motion_vert_field_select_0_1(mvec_rd_motion_vert_field_select_0_1),
394
    .motion_vert_field_select_1_0(mvec_rd_motion_vert_field_select_1_0),
395
    .motion_vert_field_select_1_1(mvec_rd_motion_vert_field_select_1_1),
396
    .second_field(mvec_rd_second_field),
397
    .progressive_sequence(progressive_sequence),             // from vld
398
    .progressive_frame(progressive_frame),                   // from vld
399
    .top_field_first(top_field_first),                       // from vld
400
    .repeat_first_field(repeat_first_field),                 // from vld
401
    .last_frame(mvec_rd_last_frame),
402
    .update_picture_buffers(mvec_rd_update_picture_buffers),
403
    .motion_vector_valid(mvec_rd_motion_vector_valid),
404
 
405
    .source_select(source_select),
406
 
407
    .fwd_wr_addr_en(fwd_wr_addr_en),
408
    .fwd_wr_addr(fwd_wr_addr),
409
    .fwd_wr_addr_almost_full(fwd_wr_addr_almost_full),
410
    .bwd_wr_addr_en(bwd_wr_addr_en),
411
    .bwd_wr_addr(bwd_wr_addr),
412
    .bwd_wr_addr_almost_full(bwd_wr_addr_almost_full),
413
    .dst_wr_en(dst_wr_en),
414
    .dst_wr_almost_full(dst_wr_almost_full),
415
    .dst_wr_write_recon(dst_wr_write_recon),
416
    .dst_wr_write_address(dst_wr_write_address),
417
    .dst_wr_motion_forward(dst_wr_motion_forward),
418
    .dst_wr_fwd_hor_offset(dst_wr_fwd_hor_offset),
419
    .dst_wr_fwd_hor_halfpixel(dst_wr_fwd_hor_halfpixel),
420
    .dst_wr_fwd_ver_halfpixel(dst_wr_fwd_ver_halfpixel),
421
    .dst_wr_motion_backward(dst_wr_motion_backward),
422
    .dst_wr_bwd_hor_offset(dst_wr_bwd_hor_offset),
423
    .dst_wr_bwd_hor_halfpixel(dst_wr_bwd_hor_halfpixel),
424
    .dst_wr_bwd_ver_halfpixel(dst_wr_bwd_ver_halfpixel),
425
    .output_frame(output_frame),                             // to resample
426
    .output_frame_valid(output_frame_valid),                 // to resample
427
    .output_frame_rd(output_frame_rd),                       // to resample
428
    .output_progressive_sequence(output_progressive_sequence),// to resample
429
    .output_progressive_frame(output_progressive_frame),     // to resample
430
    .output_top_field_first(output_top_field_first),         // to resample
431
    .output_repeat_first_field(output_repeat_first_field),   // to resample
432
    .picbuf_busy(picbuf_busy),
433
    .dct_block_cmd(dct_block_wr_cmd),
434
    .dct_block_en(dct_block_wr_en),
435
    .dct_block_wr_almost_full(dct_block_wr_almost_full)
436
    );
437
 
438
  /* convert field dct coding to frame dct coding */
439
  motcomp_dcttype motcomp_dcttype (
440
    .clk(clk),
441
    .clk_en(clk_en),
442
    .rst(rst),
443
    .dct_block_empty(dct_block_rd_empty),
444
    .dct_block_cmd(dct_block_rd_cmd),
445
    .dct_block_en(dct_block_rd_en),
446
    .dct_block_valid(dct_block_rd_valid),
447
    .idct_rd_dta_empty(idct_rd_dta_empty),
448
    .idct_rd_dta(idct_rd_dta),
449
    .idct_rd_dta_en(idct_rd_dta_en),
450
    .idct_rd_dta_valid(idct_rd_dta_valid),
451
    .frame_idct_wr_overflow(frame_idct_wr_overflow),
452
    .frame_idct_rd_dta_empty(frame_idct_dta_empty),
453
    .frame_idct_rd_dta(frame_idct_dta),
454
    .frame_idct_rd_dta_en(frame_idct_dta_en),
455
    .frame_idct_rd_dta_valid(frame_idct_dta_valid)
456
    );
457
 
458
  /* block reconstruction */
459
  motcomp_recon motcomp_recon (
460
    .clk(clk),
461
    .clk_en(clk_en),
462
    .rst(rst),
463
    .dst_rd_dta_valid(dst_rd_valid),
464
    .dst_rd_dta_empty(dst_rd_empty),
465
    .dst_rd_dta_en(dst_rd_en),
466
    .dst_rd_dta(dst_rd_dta),
467
    .idct_rd_dta_empty(frame_idct_dta_empty),
468
    .idct_rd_dta_en(frame_idct_dta_en),
469
    .idct_rd_dta(frame_idct_dta),
470
    .idct_rd_dta_valid(frame_idct_dta_valid),
471
    .fwd_rd_dta_empty(fwd_rd_dta_empty),
472
    .fwd_rd_dta_en(fwd_rd_dta_en),
473
    .fwd_rd_dta(fwd_rd_dta),
474
    .fwd_rd_dta_valid(fwd_rd_dta_valid),
475
    .bwd_rd_dta_empty(bwd_rd_dta_empty),
476
    .bwd_rd_dta_en(bwd_rd_dta_en),
477
    .bwd_rd_dta(bwd_rd_dta),
478
    .bwd_rd_dta_valid(bwd_rd_dta_valid),
479
    .recon_wr_full(recon_wr_full),
480
    .recon_wr_almost_full(recon_wr_almost_full),
481
    .recon_wr_en(recon_wr_en),
482
    .recon_wr_addr(recon_wr_addr),
483
    .recon_wr_dta(recon_wr_dta)
484
    );
485
 
486
 
487
`ifdef CHECK
488
  always @(posedge clk)
489
    if (mvec_wr_overflow)
490
      begin
491
        $strobe ("%m\t*** error: mvec_wr_overflow ***");
492
        $stop;
493
      end
494
 
495
  always @(posedge clk)
496
    if (dst_wr_overflow)
497
      begin
498
        $strobe ("%m\t*** error: dst_wr_overflow ***");
499
        $stop;
500
      end
501
 
502
  always @(posedge clk)
503
    if (dct_block_wr_overflow)
504
      begin
505
        $strobe ("%m\t*** error: dct_block_wr_overflow ***");
506
        $stop;
507
      end
508
 
509
`endif
510
 
511
  /*
512
   * fifos_almost_full is asserted if dst, fwd or bwd fifo is almost full.
513
   * No need to watch recon_wr_full; motcomp_recon does that
514
   */
515
 
516
`ifdef DEBUG
517
  wire               fifos_almost_full = (dst_wr_almost_full || fwd_wr_addr_almost_full || bwd_wr_addr_almost_full || dct_block_wr_almost_full);
518
 
519
  always @(posedge clk)
520
    $strobe("%m\tbusy: %d fifos_almost_full: %d dst_wr_almost_full: %d fwd_wr_addr_almost_full: %d bwd_wr_addr_almost_full: %d", busy, fifos_almost_full, dst_wr_almost_full, fwd_wr_addr_almost_full, bwd_wr_addr_almost_full);
521
 
522
  always @(posedge clk)
523
    if (dst_wr_almost_full)
524
      $display("%m\tbusy: dst_wr_almost_full");
525
 
526
  always @(posedge clk)
527
    if (fwd_wr_addr_almost_full)
528
      $display("%m\tbusy: fwd_wr_addr_almost_full");
529
 
530
  always @(posedge clk)
531
    if (bwd_wr_addr_almost_full)
532
      $display("%m\tbusy: bwd_wr_addr_almost_full");
533
 
534
  always @(posedge clk)
535
     if (clk_en && ~busy && motion_vector_valid) $strobe("%m\tmacroblock_address: %d", macroblock_address);
536
 
537
  always @(posedge clk)
538
    if (clk_en && ~busy && motion_vector_valid)
539
      begin
540
        case (chroma_format)
541
          CHROMA420:     #0 $display("%m         CHROMA420");
542
          CHROMA422:     #0 $display("%m         CHROMA422");
543
          CHROMA444:     #0 $display("%m         CHROMA444");
544
          default        #0 $display("%m         chroma_format %h", chroma_format);
545
        endcase
546
        case (picture_coding_type)
547
          P_TYPE:        #0 $display("%m         P_TYPE");
548
          I_TYPE:        #0 $display("%m         I_TYPE");
549
          B_TYPE:        #0 $display("%m         B_TYPE");
550
          D_TYPE:        #0 $display("%m         D_TYPE"); // mpeg1 only; mpeg2 does not have D pictures
551
        endcase
552
        case (picture_structure)
553
          FRAME_PICTURE: #0 $display("%m         FRAME_PICTURE");
554
          TOP_FIELD:     #0 $display("%m         TOP_FIELD");
555
          BOTTOM_FIELD:  #0 $display("%m         BOTTOM_FIELD");
556
          default        #0 $display("%m         picture_structure %h", picture_structure);
557
        endcase
558
 
559
        /*
560
           MC_FRAME and MC_16X8 share the same code; which one is used depends upon picture_structure.
561
           In a FRAME_PICTURE you can have MC_FRAME, but never MC_16X8.
562
           In a field picture (TOP_FIELD, BOTTOM_FIELD) you can have MC_16X8, but never MC_FRAME.
563
         */
564
        case (picture_structure)
565
          FRAME_PICTURE:
566
            case (motion_type)
567
              MC_FIELD:      #0 $display("%m         MC_FIELD");
568
              MC_FRAME:      #0 $display("%m         MC_FRAME");
569
              MC_DMV:        #0 $display("%m         MC_DMV");
570
              default        #0 $display("%m         motion_type %h", motion_type);
571
            endcase
572
          TOP_FIELD,
573
          BOTTOM_FIELD:
574
            case (motion_type)
575
              MC_FIELD:      #0 $display("%m         MC_FIELD");
576
              MC_16X8:       #0 $display("%m         MC_16X8");
577
              MC_DMV:        #0 $display("%m         MC_DMV");
578
              default        #0 $display("%m         motion_type %h", motion_type);
579
            endcase
580
        endcase
581
        #0 $display("%m         macroblock_address: %d", macroblock_address);
582
        if (macroblock_intra)           #0 $display("%m         macroblock_intra");
583
        if (macroblock_motion_forward && macroblock_motion_backward)  #0 $display("%m         macroblock_motion_forward, macroblock_motion_backward");
584
        else if (macroblock_motion_forward)  #0 $display("%m         macroblock_motion_forward");
585
        else if (macroblock_motion_backward) #0 $display("%m         macroblock_motion_backward");
586
        if (dct_type) #0 $display("%m\tdct_type field");
587
        else #0 $display("%m\tdct_type frame");
588
        #0 $display("%m\tpmv_0_0_0: %d pmv_0_0_1: %d pmv_1_0_0: %d pmv_1_0_1: %d pmv_0_1_0: %d pmv_0_1_1: %d pmv_1_1_0: %d pmv_1_1_1: %d", pmv_0_0_0, pmv_0_0_1, pmv_1_0_0, pmv_1_0_1, pmv_0_1_0, pmv_0_1_1, pmv_1_1_0, pmv_1_1_1);
589
        #0 $display("%m\tdmv_0_0: %d dmv_0_1: %d dmv_1_0: %d dmv_1_1: %d", dmv_0_0, dmv_0_1, dmv_1_0, dmv_1_1);
590
        #0 $display("%m\tmotion_vert_field_select_0_0: %d motion_vert_field_select_0_1: %d motion_vert_field_select_1_0: %d motion_vert_field_select_1_1: %d", motion_vert_field_select_0_0, motion_vert_field_select_0_1, motion_vert_field_select_1_0, motion_vert_field_select_1_1);
591
      end
592
 
593
`endif
594
 
595
endmodule
596
/* not truncated */

powered by: WebSVN 2.1.0

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