1 ------------------------------------------------------------------------------
2 -- Copyright (C) 2011 - Kenichi Kurimoto
4 -- This program is free software; you can redistribute it and/or modify
5 -- it under the terms of the GNU General Public License as published by
6 -- the Free Software Foundation; either version 2 of the License, or
7 -- (at your option) any later version.
9 -- This program is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- GNU General Public License for more details.
14 -- You should have received a copy of the GNU General Public License
15 -- along with this program; if not, write to the Free Software
16 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -----------------------------------------------------------------------------
18 -- Entity: dctmem2cont
19 -- File: dctmem2cont.vhd
20 -- Author: Kenichi Kurimoto
21 -- Description: DCT memory and controller between idct1 and idct2
22 ------------------------------------------------------------------------------
26 use ieee.std_logic_1164.all;
27 use ieee.numeric_std.all;
32 use grlib.devices.all;
35 use techmap.gencomp.all;
39 memtech : integer := DEFMEMTECH);
43 kready1 : out std_logic;
44 kstrobe1 : in std_logic;
45 kdata1 : in std_logic_vector(15 downto 0);
46 kready2 : in std_logic;
47 kstrobe2 : out std_logic;
48 kdata2 : out std_logic_vector(15 downto 0);
53 architecture rtl of dctmem2cont is
55 type sstate_type is (mem0, mem1);
56 type mstate_type is (empty, writing, full, reading, standby);
58 type control_reg is record
61 mem0state : mstate_type;
62 mem1state : mstate_type;
63 countf : std_logic_vector(5 downto 0);
64 countb : std_logic_vector(5 downto 0);
68 signal r, rin : control_reg;
69 signal m0address, m1address : std_logic_vector(5 downto 0);
70 signal m0datain, m1datain : std_logic_vector(15 downto 0);
71 signal m0dataout, m1dataout : std_logic_vector(15 downto 0);
72 signal m0enable, m1enable : std_logic;
73 signal m0write, m1write : std_logic;
76 yram0 : syncram generic map(tech => memtech, abits => 6, dbits => 16)
77 port map( clk, m0address, m0datain, m0dataout, m0enable, m0write);
78 yram1 : syncram generic map(tech => memtech, abits => 6, dbits => 16)
79 port map( clk, m1address, m1datain, m1dataout, m1enable, m1write);
81 comb : process (r, rst, kstrobe1, kdata1, kready2, m0dataout, m1dataout)
82 variable v : control_reg;
83 variable vkready1 : std_logic;
84 variable verror : std_logic;
85 variable vm0address, vm1address : std_logic_vector(5 downto 0);
86 variable vm0enable, vm1enable, vm0write, vm1write : std_logic;
87 variable fcountup, bcountup : std_logic;
88 variable fcntint : integer;
89 variable vstrobe : std_logic;
90 variable outdata : std_logic_vector(15 downto 0);
96 vm0enable := '0'; vm1enable := '0'; vm0write := '0'; vm1write := '0';
97 fcountup := '0'; bcountup := '0';
98 vm0address := (others => '0'); vm1address := (others => '0');
100 fcntint := to_integer(unsigned(r.countf));
101 if (kstrobe1 = '1') then
102 if ((r.swf = mem0 and (r.mem0state = full or r.mem0state = reading)) or
103 (r.swf = mem1 and (r.mem1state = full or r.mem1state = reading))) then
107 if(r.swf = mem0) then
110 vm0address := r.countf(2 downto 0) & r.countf(5 downto 3);
114 vm1address := r.countf(2 downto 0) & r.countf(5 downto 3);
119 if(r.swf = mem0 and (r.mem0state = empty or r.mem0state = writing)) or
120 (r.swf = mem1 and (r.mem1state = empty or r.mem1state = writing)) then
126 if (kready2 = '1') then
127 if(r.swb = mem0 and (r.mem0state = full or r.mem0state = reading)) then
131 vm0address := r.countb;
132 elsif(r.swb = mem1 and (r.mem1state = full or r.mem1state = reading)) then
136 vm1address := r.countb;
140 if(r.swb = mem0) then
141 outdata := m0dataout;
143 outdata := m1dataout;
150 if (r.swf = mem0 and fcountup = '1') then
151 v.mem0state := writing;
154 if ( fcntint = 63 and fcountup = '1') then
159 if (r.swb = mem0 and kready2 = '1') then
160 v.mem0state := reading;
163 if (r.countb = "111111") then
164 v.mem0state := standby;
168 v.mem0state := empty;
174 if (r.swf = mem1 and fcountup = '1') then
175 v.mem1state := writing;
178 if ( fcntint = 63 and fcountup = '1') then
183 if (r.swb = mem1 and kready2 = '1') then
184 v.mem1state := reading;
187 if (r.countb = "111111") then
188 v.mem1state := standby;
192 v.mem1state := empty;
197 if(fcountup = '1') then
198 v.countf := r.countf + '1';
200 if(bcountup = '1') then
201 v.countb := r.countb + '1';
208 v.mem0state := empty;
209 v.mem1state := empty;
210 v.countf := (others => '0');
211 v.countb := (others => '0');
219 kstrobe2 <= r.stb2keep;
222 m0address <= vm0address;
223 m1address <= vm1address;
224 m0enable <= vm0enable;
225 m1enable <= vm1enable;
238 if rising_edge(clk) then