multiplex.vhd 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 03.06.2019 18:42:50
  6. -- Design Name:
  7. -- Module Name: multiplex - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.std_logic_arith.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24. use work.myPackage.ALL;
  25. entity multiplex is
  26. generic(
  27. busWidth : integer:=32
  28. );
  29. Port ( clk : in STD_LOGIC;
  30. start : in STD_LOGIC;
  31. ready: out std_logic;
  32. rst : in STD_LOGIC;
  33. done : out STD_LOGIC;
  34. idle : out STD_LOGIC;
  35. moduleId : in STD_LOGIC_VECTOR (31 downto 0);
  36. srcData : in STD_LOGIC_VECTOR (busWidth-1 downto 0);
  37. srcValid : in std_logic;
  38. srcReady : out std_logic;
  39. dstData : out STD_LOGIC_VECTOR (busWidth-1 downto 0);
  40. dstValid : out std_logic;
  41. dstReady : in std_logic
  42. );
  43. end multiplex;
  44. architecture Behavioral of multiplex is
  45. component dummyModule is
  46. generic(
  47. busWidth : integer:=32;
  48. regDepth : integer:=4);
  49. Port ( clk : in STD_LOGIC;
  50. rst_n : in STD_LOGIC;
  51. start : in STD_LOGIC;
  52. ready: out std_logic;
  53. idle : out std_logic;
  54. done : out std_logic;
  55. srcData : in STD_LOGIC_VECTOR (busWidth-1 downto 0);
  56. srcValid : in std_logic;
  57. srcReady : out std_logic;
  58. dstData : out STD_LOGIC_VECTOR (busWidth-1 downto 0);
  59. dstValid : out std_logic;
  60. dstReady : in std_logic);
  61. end component;
  62. component filter11x11_strm is
  63. port (
  64. width : IN STD_LOGIC_VECTOR (31 downto 0);
  65. height : IN STD_LOGIC_VECTOR (31 downto 0);
  66. filt1 : IN STD_LOGIC_VECTOR (31 downto 0);
  67. filt2 : IN STD_LOGIC_VECTOR (31 downto 0);
  68. src_V_TDATA : IN STD_LOGIC_VECTOR (31 downto 0);
  69. dst_V_TDATA : OUT STD_LOGIC_VECTOR (31 downto 0);
  70. ap_clk : IN STD_LOGIC;
  71. ap_rst_n : IN STD_LOGIC;
  72. ap_start : IN STD_LOGIC;
  73. src_V_TVALID : IN STD_LOGIC;
  74. src_V_TREADY : OUT STD_LOGIC;
  75. dst_V_TVALID : OUT STD_LOGIC;
  76. dst_V_TREADY : IN STD_LOGIC;
  77. ap_done : OUT STD_LOGIC;
  78. ap_ready : OUT STD_LOGIC;
  79. ap_idle : OUT STD_LOGIC);
  80. end component;
  81. component conv2d_5x5_224p is
  82. generic(
  83. busWidth : integer := 32;
  84. kernelSize : integer := 5;
  85. imageWidth : integer := 224 + 4);
  86. Port ( clk : in STD_LOGIC;
  87. rst_n : in std_logic;
  88. start : in STD_LOGIC;
  89. ready: out std_logic;
  90. idle : out std_logic := '0';
  91. done : out std_logic := '0';
  92. srcData : in STD_LOGIC_VECTOR (busWidth-1 downto 0);
  93. srcValid : in std_logic;
  94. srcReady : out std_logic;
  95. dstData : out STD_LOGIC_VECTOR (busWidth-1 downto 0);
  96. dstValid : out std_logic;
  97. dstReady : in std_logic);
  98. end component;
  99. component ram is
  100. generic(
  101. busWidth : integer:=busWidth;
  102. addrWidth: integer);
  103. port(
  104. clk : in std_logic;
  105. wrEn : in std_logic;
  106. wrAddr : in std_logic_vector(addrWidth-1 downto 0);
  107. rdAddr : in std_logic_vector(addrWidth-1 downto 0);
  108. wrData : in std_logic_vector(busWidth-1 downto 0);
  109. rdData : out std_logic_vector(busWidth-1 downto 0)
  110. );
  111. end component;
  112. constant ramAddrWidth : integer := 4;
  113. type muxBitVector is array(0 to moduleCount-1) of std_logic;
  114. type muxDataVector is array(0 to moduleCount-1) of std_logic_vector(busWidth-1 downto 0);
  115. type configRam_t is array(integer range <>) of std_logic_vector(busWidth-1 downto 0);
  116. signal imgWidth : std_logic_vector(busWidth-1 downto 0) := std_logic_vector(conv_unsigned(224, 32));
  117. signal imgHeight : std_logic_vector(busWidth-1 downto 0) := std_logic_vector(conv_unsigned(224, 32));
  118. signal h_coeff : configRam_t(0 to 4);
  119. signal v_coeff : configRam_t(0 to 4);
  120. signal h_coeff_rdAddr : std_logic_vector(2 downto 0);
  121. signal h_coeff_rdEn : std_logic;
  122. signal v_coeff_rdAddr : std_logic_vector(2 downto 0);
  123. signal v_coeff_rdEn : std_logic;
  124. signal ram_wrEn : std_logic;
  125. signal ram_wrAddr : std_logic_vector(ramAddrWidth-1 downto 0);
  126. signal ram_wrData : std_logic_vector(busWidth-1 downto 0);
  127. signal ram_rdAddr : std_logic_vector(ramAddrWidth-1 downto 0);
  128. signal ram_rdData : std_logic_vector(busWidth-1 downto 0);
  129. signal muxSrcData : std_logic_vector(busWidth-1 downto 0);
  130. signal muxSrcValid : std_logic;
  131. signal muxSrcReady : muxBitVector := (others => '1');
  132. signal muxDstData : muxDataVector;
  133. signal muxDstValid : muxBitVector := (others => '0');
  134. signal muxDstReady : std_logic;
  135. signal muxReady : muxBitVector := (others => '1');
  136. signal muxIdle : muxBitVector := (others => '1');
  137. signal muxDone : muxBitVector := (others => '1');
  138. signal muxStart : muxBitVector := (others => '0');
  139. begin
  140. dummyBig : dummyModule
  141. generic map (
  142. regDepth => 1024
  143. ) port map (
  144. clk => clk,
  145. rst_n => rst,
  146. srcData => muxSrcData,
  147. srcValid=> muxSrcValid,
  148. srcReady=> muxSrcReady(0),
  149. dstData => muxDstData(0),
  150. dstValid => muxDstValid(0),
  151. dstReady => muxDstReady,
  152. start => muxStart(0),
  153. ready => muxReady(0),
  154. idle => muxIdle(0),
  155. done => muxDone(0)
  156. );
  157. dummy : dummyModule
  158. generic map (
  159. regDepth => 4
  160. ) port map (
  161. clk => clk,
  162. rst_n => rst,
  163. srcData => muxSrcData,
  164. srcValid=> muxSrcValid,
  165. srcReady=> muxSrcReady(1),
  166. dstData => muxDstData(1),
  167. dstValid => muxDstValid(1),
  168. dstReady => muxDstReady,
  169. start => muxStart(1),
  170. ready => muxReady(1),
  171. idle => muxIdle(1),
  172. done => muxDone(1)
  173. );
  174. f11 : filter11x11_strm port map (
  175. ap_clk => clk,
  176. ap_rst_n => rst,
  177. ap_start => muxStart(2),
  178. ap_done => muxDone(2),
  179. ap_ready => muxReady(2),
  180. ap_idle => muxIdle(2),
  181. width => imgWidth,
  182. height => imgHeight,
  183. src_V_TDATA => muxSrcData,
  184. src_V_TVALID => muxSrcValid,
  185. src_V_TREADY => muxSrcReady(2),
  186. dst_V_TDATA => muxDstData(2),
  187. dst_V_TVALID => muxDstValid(2),
  188. dst_V_TREADY => muxDstReady,
  189. filt1 => x"00000001",
  190. filt2 => x"00000001"
  191. );
  192. conv2d_5x5 : conv2d_5x5_224p port map (
  193. clk => clk,
  194. rst_n => rst,
  195. srcData => muxSrcData,
  196. srcValid=> muxSrcValid,
  197. srcReady=> muxSrcReady(3),
  198. dstData => muxDstData(3),
  199. dstValid => muxDstValid(3),
  200. dstReady => muxDstReady,
  201. start => muxStart(3),
  202. ready => muxReady(3),
  203. idle => muxIdle(3),
  204. done => muxDone(3)
  205. );
  206. config_ram : ram generic map(
  207. addrWidth => ramAddrWidth
  208. ) port map(
  209. clk => clk,
  210. wrEn => ram_wrEn,
  211. wrAddr => ram_wrAddr,
  212. rdAddr => ram_rdAddr,
  213. wrData => ram_wrData,
  214. rdData => ram_rdData
  215. );
  216. readConfig : process(h_coeff_rdEn)
  217. variable rdAddr : std_logic_vector(ramAddrWidth-1 downto 0);
  218. begin
  219. if h_coeff_rdEn = '1' then
  220. elsif v_coeff_rdEn = '1' then
  221. end if;
  222. end process;
  223. switching : process(moduleId, muxSrcReady, muxReady, muxDstData, muxDstValid, muxDone, muxIdle, start)
  224. variable i : integer range 0 to moduleCount-1;
  225. begin
  226. i := 0;
  227. for k in 0 to moduleCount-1 loop
  228. if moduleIds(k) = moduleId then
  229. i := k;
  230. end if;
  231. end loop;
  232. ready <= muxReady(i);
  233. dstData <= muxDstData(i);
  234. done <= muxDone(i);
  235. idle <= muxIdle(i);
  236. dstValid <= muxDstValid(i);
  237. srcReady <= muxSrcReady(i);
  238. muxStart <= (others => '0');
  239. muxStart(i) <= start;
  240. end process;
  241. muxSrcValid <= srcValid;
  242. muxSrcData <= srcData;
  243. muxDstReady <= dstReady;
  244. end Behavioral;