5 use ieee.std_logic_1164.
all;
6 use ieee.numeric_std.
all;
13 Reset_n
: in std_logic;
14 Enable
: in std_logic;
16 in_request
: out std_logic;
17 in_valid
: in std_logic;
18 in_data
: in signed
(31 downto 0);
20 in_sem_request
: out std_logic;
21 in_sem_valid
: in std_logic;
22 in_sem_addr
: out unsigned
(19 downto 0);
23 in_sem_data
: in signed
(31 downto 0);
25 out_sem_requested
: in std_logic;
26 out_sem_valid
: out std_logic;
27 out_sem_addr
: out unsigned
(19 downto 0);
28 out_sem_data
: out signed
(31 downto 0);
30 in_newframe
: in std_logic;
31 out_done
: out std_logic);
35 architecture a_ExpandBlock
of ExpandBlock
is
38 DEPTH
: positive
:= 64; -- How many slots
39 DATA_WIDTH
: positive
:= 16; -- How many bits per slot
40 ADDR_WIDTH
: positive
:= 6 -- = ceil(log2(DEPTH))
45 wr_addr
: in unsigned
(ADDR_WIDTH
-1 downto 0);
46 wr_data
: in signed
(DATA_WIDTH
-1 downto 0);
47 rd_addr
: in unsigned
(ADDR_WIDTH
-1 downto 0);
48 rd_data
: out signed
(DATA_WIDTH
-1 downto 0)
52 component ReconPixelIndex
54 Reset_n
: in std_logic;
56 in_request
: out std_logic;
57 in_valid
: in std_logic;
58 in_data
: in signed
(31 downto 0);
60 out_requested
: in std_logic;
61 out_valid
: out std_logic;
62 out_data
: out signed
(31 downto 0)
68 x
: in SIGNED
(16 downto 0);
69 sat
: out UNSIGNED
(7 downto 0));
74 Reset_n
: in std_logic;
76 in_request
: out std_logic;
77 in_valid
: in std_logic;
78 in_data
: in signed
(15 downto 0);
79 in_quantmat
: in signed
(15 downto 0);
81 out_requested
: in std_logic;
82 out_valid
: out std_logic;
83 out_data
: out signed
(15 downto 0)
87 -- We are using 1024 as the maximum width and height size
88 -- = ceil(log2(Maximum Size))
89 constant LG_MAX_SIZE
: natural
:= 10;
90 constant MEM_ADDR_WIDTH
: natural
:= 20;
92 -------------------------------------------------------------------------------
93 -- Signals that must be read at the beginning
94 -------------------------------------------------------------------------------
95 -- signal HFragments : unsigned(LG_MAX_SIZE-3 downto 0);
96 -- signal VFragments : unsigned(LG_MAX_SIZE-3 downto 0);
97 signal YStride
: unsigned
(LG_MAX_SIZE
+1 downto 0);
98 signal UVStride
: unsigned
(LG_MAX_SIZE
downto 0);
99 signal YPlaneFragments
: unsigned
(LG_MAX_SIZE
*2 downto 0);
100 signal UVPlaneFragments
: unsigned
(LG_MAX_SIZE
*2-2 downto 0);
101 -- signal ReconYDataOffset : unsigned(MEM_ADDR_WIDTH-1 downto 0);
102 -- signal ReconUDataOffset : unsigned(MEM_ADDR_WIDTH-1 downto 0);
103 -- signal ReconVDataOffset : unsigned(MEM_ADDR_WIDTH-1 downto 0);
106 -------------------------------------------------------------------------------
107 -- Signal that must be read for all frames
108 -------------------------------------------------------------------------------
109 signal FragCodMeth_FragNumber
: unsigned
(2 downto 0);
110 -- signal FragCoefEOB_FragNumber : unsigned(31 downto 0);
111 signal FragMVect_FragNumber_x
: signed
(31 downto 0);
112 signal FragMVect_FragNumber_y
: signed
(31 downto 0);
113 signal FragmentNumber
: unsigned
(31 downto 0);
114 signal FrameType
: unsigned
(7 downto 0);
116 signal GoldenFrameOfs
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
117 signal ThisFrameReconOfs
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
118 signal LastFrameReconOfs
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
121 -------------------------------------------------------------------------------
123 -------------------------------------------------------------------------------
124 signal CodingMode
: unsigned
(2 downto 0);
125 signal ReconPixelsPerLine
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
126 signal MvShift
: unsigned
(1 downto 0);
127 signal MvModMask
: unsigned
(31 downto 0);
128 signal dequant_coeffs_Ofs
: unsigned
(8 downto 0);
129 signal MVOffset
: signed
(31 downto 0);
130 signal LastFrameRecPtr
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
131 signal LastFrameRecPtr2
: unsigned
(MEM_ADDR_WIDTH
-1 downto 0);
132 signal ReconPtr2Offset
: signed
(31 downto 0);
134 signal s_in_request
: std_logic;
136 signal count
: integer range 0 to 511;
137 -------------------------------------------------------------------------------
138 -- dequant_coeffs Offsets
139 -------------------------------------------------------------------------------
140 constant Y_COEFFS_OFS
: unsigned
(8 downto 0) := "
000000000"
;
141 constant U_COEFFS_OFS
: unsigned
(8 downto 0) := "
001000000"
;
142 constant V_COEFFS_OFS
: unsigned
(8 downto 0) := "
010000000"
;
143 constant INTERY_COEFFS_OFS
: unsigned
(8 downto 0) := "
011000000"
;
144 constant INTERU_COEFFS_OFS
: unsigned
(8 downto 0) := "
100000000"
;
145 constant INTERV_COEFFS_OFS
: unsigned
(8 downto 0) := "
101000000"
;
148 -------------------------------------------------------------------------------
149 -- CodingMode constants
150 -------------------------------------------------------------------------------
151 constant CODE_INTER_NO_MV
:
152 unsigned
(2 downto 0) := "
000"
; -- INTER prediction, (0,0) motion vector implied.
153 constant CODE_INTRA
:
154 unsigned
(2 downto 0) := "
001"
; -- INTRA i.e. no prediction.
155 constant CODE_INTER_PLUS_MV
:
156 unsigned
(2 downto 0) := "
010"
; -- INTER prediction, non zero motion vector.
157 constant CODE_INTER_LAST_MV
:
158 unsigned
(2 downto 0) := "
011"
; -- Use Last Motion vector
159 constant CODE_INTER_PRIOR_LAST
:
160 unsigned
(2 downto 0) := "
100"
; -- Prior last motion vector
161 constant CODE_USING_GOLDEN
:
162 unsigned
(2 downto 0) := "
101"
; -- 'Golden frame' prediction (no MV).
163 constant CODE_GOLDEN_MV
:
164 unsigned
(2 downto 0) := "
110"
; -- 'Golden frame' prediction plus MV.
165 constant CODE_INTER_FOURMV
:
166 unsigned
(2 downto 0) := "
111"
; -- Inter prediction 4MV per macro block.
169 -------------------------------------------------------------------------------
170 -- ReconPixelIndex signal
171 -------------------------------------------------------------------------------
172 constant RPI_DATA_WIDTH
: positive
:= 32;
173 constant RPI_POS_WIDTH
: positive
:= 17;
174 signal rpi_position
: unsigned
(RPI_POS_WIDTH
-1 downto 0);
175 signal rpi_value
: signed
(RPI_DATA_WIDTH
-1 downto 0);
177 signal s_rpi_in_request
: std_logic;
178 signal s_rpi_in_valid
: std_logic;
179 signal s_rpi_in_data
: signed
(31 downto 0);
181 signal s_rpi_out_requested
: std_logic;
182 signal s_rpi_out_valid
: std_logic;
183 signal s_rpi_out_data
: signed
(31 downto 0);
186 -------------------------------------------------------------------------------
188 -------------------------------------------------------------------------------
189 constant KEY_FRAME
: unsigned
(7 downto 0) := "
00000000"
;
190 type ModeUsesMC_t
is array (0 to 7) of std_logic;
191 constant ModeUsesMC
: ModeUsesMC_t
:= ('0','0','1','1','1','0','1','1');
193 constant ZERO_M_VECTOR : signed(31 downto 0) := x"00000000";
196 -------------------------------------------------------------------------------
197 -- States and sub-states
198 -------------------------------------------------------------------------------
200 type state_t is (stt_readIn, stt_PreRecon, stt_Recon, stt_EndProc);
201 signal state : state_t;
203 type read_state_t is (stt_read1, stt_read_uniq_frame_data,
204 stt_read_dqc, stt_read_qtl, stt_read2);
205 signal read_state : read_state_t;
207 type pre_recon_state_t is (stt_PrepIDct, stt_CallIDct, stt_RecIDct,
208 stt_Calc_RPI_Value, stt_SelectRecons);
209 signal pre_recon_state : pre_recon_state_t;
211 type calc_rpi_state_t is (stt_calc_rpi1, stt_calc_rpi2);
212 signal calc_rpi_state : calc_rpi_state_t;
215 type select_recons_state_t is (stt_SelectRecons_1, stt_SelectRecons_2,
216 stt_SelectRecons_3, stt_SelectRecons_4,
217 stt_SelectRecons_5, stt_SelectRecons_6);
218 signal select_recons_state : select_recons_state_t;
221 type recon_state_t is (stt_Calculate_ReconIntra,
223 stt_Calculate_ReconInter,
224 stt_Calculate_ReconInterHalf, stt_WriteOut_Recon,
225 stt_ReadMemory, stt_WriteMemory);
226 signal recon_state, gotostate, gotostate2 : recon_state_t;
228 type recon_calc_state_t is (stt_CalcRecon1, stt_CalcRecon2,
229 stt_CalcRecon3, stt_CalcRecon4,
230 stt_CalcRecon5, stt_CalcRecon6,
231 stt_CalcRecon7, stt_CalcRecon8);
232 signal recon_calc_state : recon_calc_state_t;
235 type read_pixel_state_t is (stt_ReadPixels1, stt_ReadPixels2,
236 stt_ReadPixels3, stt_ReadPixels4,
237 stt_ReadPixels5, stt_ReadPixels6);
238 signal read_pixel_state : read_pixel_state_t;
241 type write_recon_state_t is (stt_WriteRecon1, stt_WriteRecon2,
243 signal write_recon_state : write_recon_state_t;
245 -------------------------------------------------------------------------------
247 -------------------------------------------------------------------------------
248 signal out_idct_requested : std_logic;
249 signal out_idct_valid : std_logic := '0';
250 signal out_idct_data : signed(15 downto 0);
251 signal out_idct_quantmat : signed(15 downto 0);
253 signal in_idct_request : std_logic := '0';
254 signal in_idct_valid : std_logic;
255 signal in_idct_data : signed(15 downto 0);
257 -----------------------------------------------------------------------------
258 -- IDct's handshake signals
259 -----------------------------------------------------------------------------
260 signal s_out_idct_valid : std_logic;
261 signal s_in_idct_request : std_logic;
263 -------------------------------------------------------------------------------
264 -- Memories signals and constants
265 -------------------------------------------------------------------------------
267 -----------------------------------------------------------------------------
269 -----------------------------------------------------------------------------
270 signal qtl_wr_e : std_logic;
271 signal qtl_wr_addr : unsigned(5 downto 0);
272 signal qtl_wr_data : signed(15 downto 0);
273 signal qtl_rd_addr : unsigned(5 downto 0);
274 signal qtl_rd_data : signed(15 downto 0);
276 -----------------------------------------------------------------------------
277 -- Dequantizer coefficients
278 -----------------------------------------------------------------------------
279 signal dqc_wr_e : std_logic;
280 signal dqc_wr_addr : unsigned(8 downto 0);
281 signal dqc_wr_data : signed(15 downto 0);
282 signal dqc_rd_addr : unsigned(8 downto 0);
283 signal dqc_rd_data : signed(15 downto 0);
285 -----------------------------------------------------------------------------
287 -----------------------------------------------------------------------------
288 signal rdb_wr_e : std_logic;
289 signal rdb_wr_addr : unsigned(5 downto 0);
290 signal rdb_wr_data : signed(15 downto 0);
291 signal rdb_rd_addr : unsigned(5 downto 0);
292 signal rdb_rd_data : signed(15 downto 0);
295 -------------------------------------------------------------------------------
296 -- Reconstruct signals, constants and types
297 -------------------------------------------------------------------------------
298 subtype ogg_int_17_t is signed(16 downto 0);
299 subtype ogg_int_16_t is signed(15 downto 0);
300 subtype ogg_uint_16_t is unsigned(15 downto 0);
301 subtype ogg_uint_8_t is unsigned(7 downto 0);
302 subtype ogg_int_8_t is signed(7 downto 0);
303 subtype ogg_uint_32_t is unsigned(31 downto 0);
305 subtype tiny_int is integer range 0 to 255;
307 signal sum : ogg_int_17_t;
308 signal sat : ogg_uint_8_t;
309 shared variable auxs17b : ogg_int_17_t;
313 constant dC128 : ogg_int_17_t := "00000000010000000";
315 signal s_in_sem_request : std_logic;
316 signal s_out_sem_valid : std_logic;
318 signal colcount : tiny_int := 0;
319 signal offset_RefPtr : unsigned(MEM_ADDR_WIDTH-1 downto 0);
320 signal offset_RefPtr2 : unsigned(MEM_ADDR_WIDTH-1 downto 0);
321 signal offset_ReconPtr : unsigned(MEM_ADDR_WIDTH-1 downto 0); --buffer
323 type mem_8_8bits_t is array (0 to 7) of ogg_uint_8_t;
324 signal Pixel : mem_8_8bits_t;
325 signal Pixel1 : mem_8_8bits_t;
328 signal mem_rd_data : signed(31 downto 0);
330 begin -- a_ExpandBlock
332 in_request <= s_in_request;
333 in_sem_request <= s_in_sem_request;
334 out_sem_valid <= s_out_sem_valid;
336 clamp255_0: clamp port map (sum, sat);
338 syncram_384_16: tsyncram
339 generic map (DEPTH => 384, DATA_WIDTH => 16, ADDR_WIDTH => 9)
340 port map (clk, dqc_wr_e, dqc_wr_addr, dqc_wr_data,
341 dqc_rd_addr, dqc_rd_data);
343 syncram_64_16: tsyncram
344 generic map (DEPTH => 64, DATA_WIDTH => 16, ADDR_WIDTH => 6)
345 port map (clk, rdb_wr_e, rdb_wr_addr, rdb_wr_data,
346 rdb_rd_addr, rdb_rd_data);
349 mem_64_int16: tsyncram
350 generic map (64, 16, 6)
351 port map (clk, qtl_wr_e, qtl_wr_addr, qtl_wr_data,
352 qtl_rd_addr, qtl_rd_data);
354 rpi0: reconpixelindex
355 port map (Clk => Clk,
357 in_request => s_rpi_out_requested,
358 in_valid => s_rpi_out_valid,
359 in_data => s_rpi_out_data,
361 out_requested => s_rpi_in_request,
362 out_valid => s_rpi_in_valid,
363 out_data => s_rpi_in_data);
366 port map(clk, Reset_n,
367 out_idct_requested, out_idct_valid, out_idct_data,
369 in_idct_request, in_idct_valid, in_idct_data);
372 in_idct_request <= s_in_idct_request;
373 out_idct_valid <= s_out_idct_valid;
376 RPI_HandShake: process (in_data, in_valid,
377 state, read_state, pre_recon_state,
378 calc_rpi_state, rpi_position,
380 begin -- process RPI_HandShake
381 s_rpi_out_data <= x"00000000";
382 s_rpi_out_valid <= '0';
383 if (s_in_request = '1') then
384 if (state = stt_readIn and read_state = stt_read1) then
385 s_rpi_out_data <= in_data;
386 s_rpi_out_valid <= in_valid;
389 if (state = stt_PreRecon and
390 pre_recon_state = stt_Calc_RPI_Value and
391 calc_rpi_state = stt_calc_rpi1) then
392 s_rpi_out_data <= resize(signed('0'&rpi_position
), 32);
393 s_rpi_out_valid
<= '1';
396 end process RPI_HandShake
;
401 -------------------------------------------------------------------------------
402 -- Procedures called when state is stt_readIn
403 -------------------------------------------------------------------------------
404 ---------------------------------------------------------------------------
405 -- Select the procedure called according the read_state
406 ---------------------------------------------------------------------------
410 -- HFragments <= unsigned(in_data(LG_MAX_SIZE-3 downto 0));
412 elsif (count
= 1) then
413 YPlaneFragments
<= unsigned
(in_data
(LG_MAX_SIZE
*2 downto 0));
415 elsif (count
= 2) then
416 YStride
<= unsigned
(in_data
(LG_MAX_SIZE
+1 downto 0));
418 elsif (count
= 3) then
419 UVPlaneFragments
<= unsigned
(in_data
(LG_MAX_SIZE
*2-2 downto 0));
421 elsif (count
= 4) then
422 UVStride
<= unsigned
(in_data
(LG_MAX_SIZE
downto 0));
424 elsif (count
= 5) then
425 -- VFragments <= unsigned(in_data(LG_MAX_SIZE-3 downto 0));
427 elsif (count
= 6) then
428 -- ReconYDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
430 elsif (count
= 7) then
431 -- ReconUDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
433 --elsif (count = 8) then
435 -- ReconVDataOffset <= unsigned(in_data(MEM_ADDR_WIDTH-1 downto 0));
437 read_state
<= stt_read_dqc
;
441 procedure read_dqc
is
444 dqc_wr_data
<= signed
(in_data
(15 downto 0));
445 dqc_wr_addr
<= dqc_wr_addr
+ 1;
448 dqc_wr_addr
<= Y_COEFFS_OFS
;
450 elsif (count
= 383) then
452 read_state
<= stt_read_uniq_frame_data
;
456 end procedure read_dqc
;
458 ---------------------------------------------------------------------------
459 -- Procedure that read the parameters sent one time per frame
460 ---------------------------------------------------------------------------
461 procedure ReadUniqFrameData
is
466 FrameType
<= unsigned
(in_data
(7 downto 0));
467 elsif (count
= 1) then
468 GoldenFrameOfs
<= unsigned
(in_data
(MEM_ADDR_WIDTH
-1 downto 0));
469 elsif (count
= 2) then
470 LastFrameReconOfs
<= unsigned
(in_data
(MEM_ADDR_WIDTH
-1 downto 0));
471 --elsif (count = 3) then
473 ThisFrameReconOfs
<= unsigned
(in_data
(MEM_ADDR_WIDTH
-1 downto 0));
475 read_state
<= stt_read_qtl
;
477 end procedure ReadUniqFrameData
;
479 procedure read_qtl
is
484 qtl_wr_data
<= signed
(in_data
(15 downto 0));
485 qtl_wr_addr
<= qtl_wr_addr
+ 1;
488 qtl_wr_addr
<= "
000000"
;
490 elsif (count
= 63) then
492 read_state
<= stt_read2
;
496 end procedure read_qtl
;
503 FragCodMeth_FragNumber
<= unsigned
(in_data
(2 downto 0));
505 elsif (count
= 1) then
506 -- FragCoefEOB_FragNumber <= unsigned(in_data(31 downto 0));
508 elsif (count
= 2) then
509 FragMVect_FragNumber_x
<= in_data
;
511 elsif (count
= 3) then
512 FragMVect_FragNumber_y
<= in_data
;
514 elsif (count
= 4) then
515 FragmentNumber
<= unsigned
(in_data
);
516 pre_recon_state
<= stt_PrepIDct
;
517 read_state
<= stt_read_qtl
;
518 state
<= stt_PreRecon
;
528 if (s_in_request
= '1' and in_valid
= '1') then
530 when stt_read1
=> read1
;
531 when stt_read_uniq_frame_data
=> ReadUniqFrameData
;
532 when stt_read_dqc
=> read_dqc
;
533 when stt_read_qtl
=> read_qtl
;
534 when others => read2
;
537 end procedure ReadIn
;
540 -------------------------------------------------------------------------------
541 -- Procedures called when state is stt_PreRecon
542 -------------------------------------------------------------------------------
544 procedure PrepareToCallIDct
is
547 -- Get coding mode for this block
548 if (FrameType
= KEY_FRAME
) then
549 CodingMode
<= CODE_INTRA
;
551 -- Get Motion vector and mode for this block.
552 CodingMode
<= FragCodMeth_FragNumber
;
556 -- Select the appropriate inverse Q matrix and line stride
557 if (FragmentNumber
< YPlaneFragments
) then
558 ReconPixelsPerLine
<= resize
(YStride
, MEM_ADDR_WIDTH
);
560 MvModMask
<= x"
00000001"
;
562 -- Select appropriate dequantiser matrix.
563 if (CodingMode
= CODE_INTRA
) then
564 dequant_coeffs_Ofs
<= Y_COEFFS_OFS
;
566 dequant_coeffs_Ofs
<= INTERY_COEFFS_OFS
;
569 ReconPixelsPerLine
<= resize
(UVStride
, MEM_ADDR_WIDTH
);
571 MvModMask
<= x"
00000003"
;
573 -- Select appropriate dequantiser matrix.
574 if (CodingMode
= CODE_INTRA
) then
575 if (FragmentNumber
< YPlaneFragments
+ UVPlaneFragments
) then
576 dequant_coeffs_Ofs
<= U_COEFFS_OFS
;
578 dequant_coeffs_Ofs
<= V_COEFFS_OFS
;
581 if (FragmentNumber
< YPlaneFragments
+ UVPlaneFragments
) then
582 dequant_coeffs_Ofs
<= INTERU_COEFFS_OFS
;
584 dequant_coeffs_Ofs
<= INTERV_COEFFS_OFS
;
589 pre_recon_state
<= stt_CallIDct
;
591 end procedure PrepareToCallIDct
;
593 procedure CallIDct
is
595 if (out_idct_requested
= '1') then
597 qtl_rd_addr
<= "
000000"
;
598 dqc_rd_addr
<= dequant_coeffs_Ofs
;
600 elsif (count
= 1) then
601 -- Wait for the memory delay
602 qtl_rd_addr
<= qtl_rd_addr
+ 1;
603 dqc_rd_addr
<= dqc_rd_addr
+ 1;
605 elsif (count
= 64) then
606 out_idct_data
<= dqc_rd_data
;
607 out_idct_quantmat
<= qtl_rd_data
;
608 s_out_idct_valid
<= '1';
610 elsif (count
= 65) then
611 out_idct_data
<= dqc_rd_data
;
612 out_idct_quantmat
<= qtl_rd_data
;
613 s_out_idct_valid
<= '1';
614 -- IDct can process. The module will be waiting it
616 pre_recon_state
<= stt_RecIDct
;
618 qtl_rd_addr
<= qtl_rd_addr
+ 1;
619 dqc_rd_addr
<= dqc_rd_addr
+ 1;
621 out_idct_data
<= dqc_rd_data
;
622 out_idct_quantmat
<= qtl_rd_data
;
623 s_out_idct_valid
<= '1';
627 end procedure CallIDct
;
631 s_out_idct_valid
<= '0';
632 s_in_idct_request
<= '1';
634 pre_recon_state
<= stt_Calc_RPI_Value
;
635 calc_rpi_state
<= stt_calc_rpi1
;
637 s_in_idct_request
<= '0';
638 -- Convert fragment number to a pixel offset in a reconstruction buffer.
639 rpi_position
<= resize
(FragmentNumber
, RPI_POS_WIDTH
);
641 if (s_in_idct_request
= '1' and in_idct_valid
= '1') then
643 rdb_wr_addr
<= rdb_wr_addr
+ 1;
644 rdb_wr_data
<= in_idct_data
;
646 rdb_wr_addr
<= "
000000"
;
651 end procedure RecIDct
;
654 procedure CalcRPIValue
is
656 case calc_rpi_state
is
657 when stt_calc_rpi1
=>
658 -- Wait until ReconPixelIndex can receive the data
659 if (s_rpi_out_requested
= '1') then
660 calc_rpi_state
<= stt_calc_rpi2
;
665 -- Wait until ReconPixelIndex returns the value
666 s_rpi_in_request
<= '1';
667 if (s_rpi_in_request
= '1' and s_rpi_in_valid
= '1') then
668 rpi_value
<= s_rpi_in_data
;
669 s_rpi_in_request
<= '0';
670 pre_recon_state
<= stt_SelectRecons
;
671 select_recons_state
<= stt_SelectRecons_1
;
674 end procedure CalcRPIValue
;
678 procedure SelectRecons
is
680 if (select_recons_state
= stt_SelectRecons_1
) then
682 -- Action depends on decode mode.
683 if (CodingMode
= CODE_INTER_NO_MV
) then
684 -- Inter with no motion vector
686 -- Reconstruct the pixel data using the last frame Reconstructq'ction
687 -- and change data when the motion vector is (0,0), the recon is
688 -- based on the lastframe without loop filtering---- for testing
689 offset_ReconPtr
<= resize
(ThisFrameReconOfs
+
690 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
691 offset_RefPtr
<= resize
(LastFrameReconOfs
+
692 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
693 offset_RefPtr2
<= x"
00000"
;
694 rdb_rd_addr
<= "
000000"
;
695 gotostate
<= stt_Calculate_ReconInter
;
696 recon_state
<= stt_ReadPixels
;
699 elsif (ModeUsesMC
(to_integer
(CodingMode
)) = '1') then
700 -- Work out the base motion vector offset and the 1/2 pixel offset
701 -- if any. For the U and V planes the MV specifies 1/4 pixel
702 -- accuracy. This is adjusted to 1/2 pixel as follows ( 0->0,
703 -- 1/4->1/2, 1/2->1/2, 3/4->1/2 ).
705 ReconPtr2Offset
<= x"
00000000"
;
706 MVOffset
<= x"
00000000"
;
707 if (FragMVect_FragNumber_x
> ZERO_M_VECTOR
) then
708 MVOffset
<= SHIFT_RIGHT
(FragMVect_FragNumber_x
, to_integer
(MvShift
));
709 if ((FragMVect_FragNumber_x
and signed
(MvModMask
)) /= x"
00000000"
) then
710 ReconPtr2Offset
<= x"
00000001"
;
712 elsif (FragMVect_FragNumber_x
< x"
000000000"
) then
713 MVOffset
<= - SHIFT_RIGHT
(- FragMVect_FragNumber_x
, to_integer
(MvShift
));
714 if (((-FragMVect_FragNumber_x
) and signed
(MvModMask
)) /= x"
00000000"
) then
715 ReconPtr2Offset
<= x"FFFFFFFF"
;
718 select_recons_state
<= stt_SelectRecons_2
;
720 elsif (CodingMode
= CODE_USING_GOLDEN
) then
721 -- Golden frame with motion vector
722 -- Reconstruct the pixel data using the golden frame
723 -- reconstruction and change data
724 offset_ReconPtr
<= resize
(ThisFrameReconOfs
+
725 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
726 offset_RefPtr
<= resize
(GoldenFrameOfs
+
727 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
728 offset_RefPtr2
<= x"
00000"
;
729 rdb_rd_addr
<= "
000000"
;
730 gotostate
<= stt_Calculate_ReconInter
;
731 recon_state
<= stt_ReadPixels
;
735 -- Simple Intra coding
736 -- Get the pixel index for the first pixel in the fragment.
737 offset_ReconPtr
<= resize
(ThisFrameReconOfs
+
738 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
739 offset_RefPtr
<= x"
00000"
;
740 offset_RefPtr2
<= x"
00000"
;
741 rdb_rd_addr
<= "
000000"
;
742 gotostate
<= stt_Calculate_ReconIntra
;
743 recon_state
<= stt_Calculate_ReconIntra
;
748 elsif (select_recons_state
= stt_SelectRecons_2
) then
749 if (FragMVect_FragNumber_y
> ZERO_M_VECTOR
) then
752 SHIFT_RIGHT
(FragMVect_FragNumber_y
, to_integer
(MvShift
)) *
753 signed
('0' & ReconPixelsPerLine), 32);
754 if ((FragMVect_FragNumber_y and signed(MvModMask)) /= x"00000000") then
755 ReconPtr2Offset <= ReconPtr2Offset + signed('0' & ReconPixelsPerLine
);
757 elsif (FragMVect_FragNumber_y
< ZERO_M_VECTOR
) then
760 SHIFT_RIGHT
(-FragMVect_FragNumber_y
, to_integer
(MvShift
)) *
761 signed
('0' & ReconPixelsPerLine), 32);
762 if (((-FragMVect_FragNumber_y) and signed(MvModMask)) /= x"00000000") then
763 ReconPtr2Offset <= ReconPtr2Offset - signed('0' & ReconPixelsPerLine
);
766 select_recons_state
<= stt_SelectRecons_3
;
768 elsif (select_recons_state
= stt_SelectRecons_3
) then
769 -- Set up the first of the two reconstruction buffer pointers.
770 if (CodingMode
= CODE_GOLDEN_MV
) then
771 LastFrameRecPtr
<= resize
(
772 unsigned
(('0' & signed(GoldenFrameOfs)) +
774 MVOffset), MEM_ADDR_WIDTH);
776 LastFrameRecPtr <= resize(
777 unsigned(('0' & signed
(LastFrameReconOfs
)) +
779 MVOffset
), MEM_ADDR_WIDTH
);
781 select_recons_state
<= stt_SelectRecons_4
;
783 elsif (select_recons_state
= stt_SelectRecons_4
) then
784 -- Select the appropriate reconstruction function
785 if (ReconPtr2Offset
= x"
00000000"
) then
786 -- Reconstruct the pixel dats from the reference frame and change data
787 -- (no half pixel in this case as the two references were the same.
788 offset_ReconPtr
<= resize
(ThisFrameReconOfs
+
789 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
790 offset_RefPtr
<= LastFrameRecPtr
;
791 offset_RefPtr2
<= x"
00000"
;
792 rdb_rd_addr
<= "
000000"
;
793 gotostate
<= stt_Calculate_ReconInter
;
794 recon_state
<= stt_ReadPixels
;
797 -- Fractional pixel reconstruction.
798 -- Note that we only use two pixels per reconstruction even for
800 offset_ReconPtr
<= resize
(ThisFrameReconOfs
+
801 unsigned
(rpi_value
), MEM_ADDR_WIDTH
);
802 offset_RefPtr
<= LastFrameRecPtr
;
803 offset_RefPtr2
<= resize
(
804 unsigned
(signed
('0' & LastFrameRecPtr) +
805 ReconPtr2Offset), MEM_ADDR_WIDTH);
806 rdb_rd_addr <= "000000";
807 gotostate <= stt_Calculate_ReconInterHalf;
808 recon_state <= stt_ReadPixels;
812 end procedure SelectRecons;
816 procedure PreRecon is
818 case pre_recon_state is
819 when stt_PrepIDct => PrepareToCallIDct;
820 when stt_CallIDct => CallIDct;
821 when stt_RecIDct => RecIDct;
822 when stt_Calc_RPI_Value => CalcRPIValue;
823 -- when stt_SelectRecons = other
824 when others => SelectRecons;
826 end procedure PreRecon;
829 -------------------------------------------------------------------------------
830 -- Procedures called when state is stt_Recon
831 -------------------------------------------------------------------------------
833 ---------------------------------------------------------------------------
835 ---------------------------------------------------------------------------
837 -- ReconPixelsPerLine - 'Distance
' to the next buffer's pixel
838 -- gotostate - Must be stt_Calculate_ReconIntra
839 -- rdb_rd_addr - Must be zero
840 -- offset_ReconPtr - offset to write
841 -- offset_RefPtr - Must be zero
842 -- offset_RefPtr2 - Must be zero
843 procedure Calculate_ReconIntra is
847 recon_calc_state <= stt_CalcRecon1;
848 state <= stt_EndProc;
851 if (recon_calc_state = stt_CalcRecon1) then
852 rdb_rd_addr <= rdb_rd_addr + 1;
853 recon_calc_state <= stt_CalcRecon2;
855 elsif (recon_calc_state = stt_CalcRecon2) then
856 sum <= rdb_rd_data + dC128;
857 recon_calc_state <= stt_CalcRecon3;
861 rdb_rd_addr <= rdb_rd_addr + 1;
862 Pixel(colcount) <= sat;
863 colcount <= colcount + 1;
864 recon_calc_state <= stt_CalcRecon2;
865 if (colcount = 7) then
866 rdb_rd_addr <= rdb_rd_addr;
867 recon_state <= stt_WriteOut_Recon;
869 recon_calc_state <= stt_CalcRecon1;
873 end procedure Calculate_ReconIntra;
876 procedure ReadPixels is
877 variable pointer : unsigned(1 downto 0);
879 if (read_pixel_state = stt_ReadPixels1) then
880 s_in_sem_request <= '1';
881 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr, 2);
882 recon_state <= stt_ReadMemory;
883 gotostate2 <= stt_ReadPixels;
884 if (offset_RefPtr(1 downto 0) = "00") then
885 read_pixel_state <= stt_ReadPixels2;
887 read_pixel_state <= stt_ReadPixels4;
890 elsif (read_pixel_state = stt_ReadPixels2) then
891 Pixel(0) <= unsigned(mem_rd_data(31 downto 24));
892 Pixel(1) <= unsigned(mem_rd_data(23 downto 16));
893 Pixel(2) <= unsigned(mem_rd_data(15 downto 8));
894 Pixel(3) <= unsigned(mem_rd_data(7 downto 0));
895 s_in_sem_request <= '1';
896 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr + 4, 2);
897 recon_state <= stt_ReadMemory;
898 gotostate2 <= stt_ReadPixels;
899 read_pixel_state <= stt_ReadPixels3;
901 elsif (read_pixel_state = stt_ReadPixels3) then
902 Pixel(4) <= unsigned(mem_rd_data(31 downto 24));
903 Pixel(5) <= unsigned(mem_rd_data(23 downto 16));
904 Pixel(6) <= unsigned(mem_rd_data(15 downto 8));
905 Pixel(7) <= unsigned(mem_rd_data(7 downto 0));
906 if (gotostate = stt_Calculate_ReconInter) then
907 rdb_rd_addr <= rdb_rd_addr + 1;
909 -- The eigth pixels have already been brought from buffer
910 recon_state <= gotostate;
911 read_pixel_state <= stt_ReadPixels1;
914 elsif (read_pixel_state = stt_ReadPixels4) then
915 -- If offset_RefPtr is not a multiple of 4
916 case offset_RefPtr(1 downto 0) is
918 Pixel(0) <= unsigned(mem_rd_data(23 downto 16));
919 Pixel(1) <= unsigned(mem_rd_data(15 downto 8));
920 Pixel(2) <= unsigned(mem_rd_data(7 downto 0));
922 Pixel(0) <= unsigned(mem_rd_data(15 downto 8));
923 Pixel(1) <= unsigned(mem_rd_data(7 downto 0));
925 Pixel(0) <= unsigned(mem_rd_data(7 downto 0));
927 s_in_sem_request <= '1';
928 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr + 4, 2);
929 recon_state <= stt_ReadMemory;
930 gotostate2 <= stt_ReadPixels;
931 read_pixel_state <= stt_ReadPixels5;
933 elsif (read_pixel_state = stt_ReadPixels5) then
934 case offset_RefPtr(1 downto 0) is
942 Pixel(0 + to_integer(pointer)) <= unsigned(mem_rd_data(31 downto 24));
943 Pixel(1 + to_integer(pointer)) <= unsigned(mem_rd_data(23 downto 16));
944 Pixel(2 + to_integer(pointer)) <= unsigned(mem_rd_data(15 downto 8));
945 Pixel(3 + to_integer(pointer)) <= unsigned(mem_rd_data(7 downto 0));
946 s_in_sem_request <= '1';
947 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr + 8, 2);
948 recon_state <= stt_ReadMemory;
949 gotostate2 <= stt_ReadPixels;
950 read_pixel_state <= stt_ReadPixels6;
952 elsif (read_pixel_state = stt_ReadPixels6) then
953 case offset_RefPtr(1 downto 0) is
955 Pixel(7) <= unsigned(mem_rd_data(31 downto 24));
957 Pixel(6) <= unsigned(mem_rd_data(31 downto 24));
958 Pixel(7) <= unsigned(mem_rd_data(23 downto 16));
960 Pixel(5) <= unsigned(mem_rd_data(31 downto 24));
961 Pixel(6) <= unsigned(mem_rd_data(23 downto 16));
962 Pixel(7) <= unsigned(mem_rd_data(15 downto 8));
964 if (gotostate = stt_Calculate_ReconInter) then
965 rdb_rd_addr <= rdb_rd_addr + 1;
968 -- The eigth pixels have already been brought from buffer
969 recon_state <= gotostate;
970 read_pixel_state <= stt_ReadPixels1;
972 end procedure ReadPixels;
975 ---------------------------------------------------------------------------
977 ---------------------------------------------------------------------------
979 -- ReconPixelsPerLine - 'Distance
' to the next buffer's pixel
980 -- gotostate - Must be stt_ReadRefPtr
981 -- rdb_rd_addr - Must be zero
982 -- offset_ReconPtr - offset to write
983 -- offset_RefPtr - offset of the reference buffer
984 -- offset_RefPtr2 - Must be zero
985 procedure Calculate_ReconInter is
989 recon_calc_state <= stt_CalcRecon1;
990 state <= stt_EndProc;
993 if (recon_calc_state = stt_CalcRecon1) then
994 sum <= rdb_rd_data + ("000000000" & signed(Pixel(colcount)));
995 recon_calc_state <= stt_CalcRecon2;
998 rdb_rd_addr <= rdb_rd_addr + 1;
999 Pixel(colcount) <= sat;
1000 colcount <= colcount + 1;
1001 recon_calc_state <= stt_CalcRecon1;
1002 if (colcount = 7) then
1003 rdb_rd_addr <= rdb_rd_addr;
1004 recon_state <= stt_WriteOut_Recon;
1006 recon_calc_state <= stt_CalcRecon1;
1010 end procedure Calculate_ReconInter;
1012 ---------------------------------------------------------------------------
1014 ---------------------------------------------------------------------------
1016 -- ReconPixelsPerLine - 'Distance
' to the next buffer's pixel
1017 -- gotostate - Must be stt_ReadRefPtr
1018 -- rdb_rd_addr - Must be zero
1019 -- offset_ReconPtr - offset to write
1020 -- offset_RefPtr - offset of the first reference buffer
1021 -- offset_RefPtr2 - offset of the second reference buffer
1023 procedure Calculate_ReconInterHalf is
1024 variable pointer : unsigned(1 downto 0);
1028 recon_calc_state <= stt_CalcRecon1;
1029 state <= stt_EndProc;
1032 if (recon_calc_state = stt_CalcRecon1) then
1033 s_in_sem_request <= '1';
1034 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr2, 2);
1035 recon_state <= stt_ReadMemory;
1036 gotostate2 <= gotostate;
1037 -- if offset_RefPtr2 mod 4 = 0
1038 if (offset_RefPtr2(1 downto 0) = "00") then
1039 recon_calc_state <= stt_CalcRecon2;
1041 recon_calc_state <= stt_CalcRecon4;
1044 elsif (recon_calc_state = stt_CalcRecon2) then
1045 Pixel1(0) <= unsigned(mem_rd_data(31 downto 24));
1046 Pixel1(1) <= unsigned(mem_rd_data(23 downto 16));
1047 Pixel1(2) <= unsigned(mem_rd_data(15 downto 8));
1048 Pixel1(3) <= unsigned(mem_rd_data(7 downto 0));
1049 s_in_sem_request <= '1';
1050 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr2 + 4, 2);
1051 recon_state <= stt_ReadMemory;
1052 gotostate2 <= gotostate;
1053 recon_calc_state <= stt_CalcRecon3;
1055 elsif (recon_calc_state = stt_CalcRecon3) then
1056 Pixel1(4) <= unsigned(mem_rd_data(31 downto 24));
1057 Pixel1(5) <= unsigned(mem_rd_data(23 downto 16));
1058 Pixel1(6) <= unsigned(mem_rd_data(15 downto 8));
1059 Pixel1(7) <= unsigned(mem_rd_data(7 downto 0));
1060 rdb_rd_addr <= rdb_rd_addr + 1;
1061 recon_calc_state <= stt_CalcRecon7;
1064 elsif (recon_calc_state = stt_CalcRecon4) then
1065 -- If offset_RefPtr2 is not a multiple of 4
1066 case offset_RefPtr2(1 downto 0) is
1068 Pixel1(0) <= unsigned(mem_rd_data(23 downto 16));
1069 Pixel1(1) <= unsigned(mem_rd_data(15 downto 8));
1070 Pixel1(2) <= unsigned(mem_rd_data(7 downto 0));
1072 Pixel1(0) <= unsigned(mem_rd_data(15 downto 8));
1073 Pixel1(1) <= unsigned(mem_rd_data(7 downto 0));
1075 Pixel1(0) <= unsigned(mem_rd_data(7 downto 0));
1077 s_in_sem_request <= '1';
1078 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr2 + 4, 2);
1079 recon_state <= stt_ReadMemory;
1080 gotostate2 <= gotostate;
1081 recon_calc_state <= stt_CalcRecon5;
1083 elsif (recon_calc_state = stt_CalcRecon5) then
1084 case offset_RefPtr2(1 downto 0) is
1092 Pixel1(0 + to_integer(pointer)) <= unsigned(mem_rd_data(31 downto 24));
1093 Pixel1(1 + to_integer(pointer)) <= unsigned(mem_rd_data(23 downto 16));
1094 Pixel1(2 + to_integer(pointer)) <= unsigned(mem_rd_data(15 downto 8));
1095 Pixel1(3 + to_integer(pointer)) <= unsigned(mem_rd_data(7 downto 0));
1096 s_in_sem_request <= '1';
1097 in_sem_addr <= SHIFT_RIGHT(offset_RefPtr2 + 8, 2);
1098 recon_state <= stt_ReadMemory;
1099 gotostate2 <= gotostate;
1100 recon_calc_state <= stt_CalcRecon6;
1102 elsif (recon_calc_state = stt_CalcRecon6) then
1103 case offset_RefPtr2(1 downto 0) is
1105 Pixel1(7) <= unsigned(mem_rd_data(31 downto 24));
1107 Pixel1(6) <= unsigned(mem_rd_data(31 downto 24));
1108 Pixel1(7) <= unsigned(mem_rd_data(23 downto 16));
1110 Pixel1(5) <= unsigned(mem_rd_data(31 downto 24));
1111 Pixel1(6) <= unsigned(mem_rd_data(23 downto 16));
1112 Pixel1(7) <= unsigned(mem_rd_data(15 downto 8));
1114 rdb_rd_addr <= rdb_rd_addr + 1;
1115 recon_calc_state <= stt_CalcRecon7;
1117 elsif (recon_calc_state = stt_CalcRecon7) then
1118 sum <= rdb_rd_data +
1120 ("000000000" & signed(Pixel(colcount))) +
1121 ("000000000" & signed(Pixel1(colcount))) , 1);
1122 recon_calc_state <= stt_CalcRecon8;
1126 rdb_rd_addr <= rdb_rd_addr + 1;
1127 Pixel(colcount) <= sat;
1128 colcount <= colcount + 1;
1129 recon_calc_state <= stt_CalcRecon7;
1130 if (colcount = 7) then
1131 rdb_rd_addr <= rdb_rd_addr;
1132 recon_state <= stt_WriteOut_Recon;
1134 recon_calc_state <= stt_CalcRecon1;
1138 end procedure Calculate_ReconInterHalf;
1141 procedure WriteOut_Recon is
1144 if (write_recon_state = stt_WriteRecon1) then
1145 out_sem_addr <= SHIFT_RIGHT(offset_ReconPtr, 2);
1146 out_sem_data <= signed(Pixel(0)) &
1150 s_out_sem_valid <= '1';
1151 write_recon_state <= stt_WriteRecon2;
1152 recon_state <= stt_WriteMemory;
1154 elsif (write_recon_state <= stt_WriteRecon2) then
1155 out_sem_addr <= SHIFT_RIGHT(offset_ReconPtr + 4, 2);
1156 out_sem_data <= signed(Pixel(4)) &
1160 s_out_sem_valid <= '1';
1161 write_recon_state <= stt_WriteReconLast;
1162 recon_state <= stt_WriteMemory;
1165 --write_recon_state = stt_WriteReconLast;
1166 write_recon_state <= stt_WriteRecon1;
1168 recon_state <= stt_ReadPixels;
1169 if (gotostate = stt_Calculate_ReconIntra) then
1170 recon_state <= gotostate;
1173 offset_ReconPtr <= offset_ReconPtr + ReconPixelsPerLine;
1174 offset_RefPtr <= offset_RefPtr + ReconPixelsPerLine;
1175 offset_RefPtr2 <= offset_RefPtr2 + ReconPixelsPerLine;
1178 end procedure WriteOut_Recon;
1180 procedure ReadMemory is
1182 s_in_sem_request <= '1';
1183 if (s_in_sem_request = '1' and in_sem_valid = '1') then
1184 mem_rd_data <= in_sem_data;
1185 s_in_sem_request <= '0';
1186 recon_state <= gotostate2;
1188 end procedure ReadMemory;
1192 procedure WriteMemory is
1194 if (out_sem_requested = '1') then
1195 recon_state <= stt_WriteOut_Recon;
1196 s_out_sem_valid <= '0';
1198 end procedure WriteMemory;
1203 when stt_WriteOut_Recon => WriteOut_Recon;
1204 when stt_WriteMemory => WriteMemory;
1205 when stt_ReadMemory => ReadMemory;
1206 when stt_ReadPixels => ReadPixels;
1207 when stt_Calculate_ReconInterHalf => Calculate_ReconInterHalf;
1208 when stt_Calculate_ReconInter => Calculate_ReconInter;
1209 --when stt_Calculate_ReconIntra => Calculate_ReconIntra;
1210 when others => Calculate_ReconIntra;
1212 end procedure Recon;
1215 -------------------------------------------------------------------------------
1216 -- Procedures called when state is stt_EndProc
1217 -------------------------------------------------------------------------------
1218 procedure EndProc is
1222 state <= stt_readIn;
1223 end procedure EndProc;
1226 if (clk'event and clk = '1') then
1227 if (Reset_n = '0') then
1228 state <= stt_readIn;
1229 read_state <= stt_read1;
1230 pre_recon_state <= stt_PrepIDct;
1231 select_recons_state <= stt_SelectRecons_1;
1232 read_pixel_state <= stt_ReadPixels1;
1233 write_recon_state <= stt_WriteRecon1;
1235 s_in_request <= '0';
1236 s_in_sem_request <= '0';
1238 s_out_sem_valid <= '0';
1241 s_out_idct_valid <= '0';
1242 s_in_idct_request <= '0';
1246 sum <= '0' & x"0000";
1248 rpi_position <= '0' & x"0000";
1249 -- HFragments <= x"11";
1250 -- VFragments <= x"00";
1252 UVStride <= "000" & x"00";
1253 YPlaneFragments <= '0' & x"00000";
1254 UVPlaneFragments <= "000" & x"0000";
1255 -- ReconYDataOffset <= x"00000";
1256 -- ReconUDataOffset <= x"00000";
1257 -- ReconVDataOffset <= x"00000";
1260 qtl_wr_addr <= "000000";
1261 qtl_wr_data <= "0000000000000000";
1262 qtl_rd_addr <= "000000";
1265 dqc_wr_addr <= "000000000";
1266 dqc_wr_data <= "0000000000000000";
1267 dqc_rd_addr <= "000000000";
1270 rdb_wr_addr <= "000000";
1271 rdb_wr_data <= "0000000000000000";
1272 rdb_rd_addr <= "000000";
1276 s_in_request <= '0';
1277 if (Enable = '1') then
1278 -- If is a new frame should read the dequantized matrix again.
1279 if (in_newframe = '1') then
1280 read_state <= stt_read_dqc;
1284 when stt_readIn => ReadIn;
1285 when stt_PreRecon => PreRecon;
1286 when stt_Recon => Recon;
1287 when others => EndProc;