Guest User

Untitled

a guest
Jan 17th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.26 KB | None | 0 0
  1. -- Module: XC3S_RAMB_1_PORT
  2. -- Description: 18Kb Block SelectRAM example
  3. -- Single Port 512 x 36 bits
  4. -- Use template "SelectRAM_A36.vhd"
  5. --
  6. -- Device: Spartan-3 Family
  7. ---------------------------------------------------------------------
  8. library IEEE;
  9. use IEEE.std_logic_1164.all;
  10. use ieee.numeric_std.all;
  11. --
  12. -- Syntax for Synopsys FPGA Express
  13. -- pragma translate_off
  14. library UNISIM;
  15. use UNISIM.VCOMPONENTS.ALL;
  16. -- pragma translate_on
  17. --
  18. entity dual_port_ram is
  19. port (
  20. data_in : in std_logic_vector (0 downto 0) := (others => '0');
  21. write_address : in std_logic_vector (13 downto 0) := (others => '0');
  22. write_enable : in std_logic := '0';
  23. ram_write_mask : in std_logic_vector(7 downto 0) := (others => '0');
  24.  
  25. enable : in std_logic := '0';
  26. clk : in std_logic := '0';
  27. reset : in std_logic := '0';
  28.  
  29. ram_read_mask : in std_logic_vector(7 downto 0) := (others => '0');
  30. read_address : in std_logic_vector(13 downto 0) := (others => '0');
  31. data_out : out std_logic_vector (0 downto 0) := (others => '0')
  32.  
  33. );
  34. end dual_port_ram;
  35. --
  36. architecture dual_port_ram_arq of dual_port_ram is
  37.  
  38. signal clk_signal : std_logic := '0';
  39.  
  40. signal read_enable_0 : std_logic := '0';
  41. signal write_enable_0 : std_logic := '0';
  42. signal read_enable_1 : std_logic := '0';
  43. signal write_enable_1 : std_logic := '0';
  44. signal read_enable_2 : std_logic := '0';
  45. signal write_enable_2 : std_logic := '0';
  46. signal read_enable_3 : std_logic := '0';
  47. signal write_enable_3 : std_logic := '0';
  48. signal read_enable_4 : std_logic := '0';
  49. signal write_enable_4 : std_logic := '0';
  50. signal read_enable_5 : std_logic := '0';
  51. signal write_enable_5 : std_logic := '0';
  52. signal read_enable_6 : std_logic := '0';
  53. signal write_enable_6 : std_logic := '0';
  54. signal read_enable_7 : std_logic := '0';
  55. signal write_enable_7 : std_logic := '0';
  56.  
  57. signal data_out_0 : std_logic_vector(0 downto 0) := (others => '0');
  58. signal data_out_1 : std_logic_vector(0 downto 0) := (others => '0');
  59. signal data_out_2 : std_logic_vector(0 downto 0) := (others => '0');
  60. signal data_out_3 : std_logic_vector(0 downto 0) := (others => '0');
  61. signal data_out_4 : std_logic_vector(0 downto 0) := (others => '0');
  62. signal data_out_5 : std_logic_vector(0 downto 0) := (others => '0');
  63. signal data_out_6 : std_logic_vector(0 downto 0) := (others => '0');
  64. signal data_out_7 : std_logic_vector(0 downto 0) := (others => '0');
  65.  
  66.  
  67. --Syntax for Synopsys FPGA Express
  68. component RAMB16_S1_S1
  69. --pragma translate_off
  70. -- pragma translate_on
  71. port(
  72. DOA : out std_logic_vector(0 downto 0);
  73. DOB : out std_logic_vector(0 downto 0);
  74. ADDRA : in std_logic_vector(13 downto 0);
  75. ADDRB : in std_logic_vector(13 downto 0);
  76. CLKA : in std_ulogic;
  77. CLKB : in std_ulogic;
  78. DIA : in std_logic_vector(0 downto 0);
  79. DIB : in std_logic_vector(0 downto 0);
  80. ENA : in std_ulogic;
  81. ENB : in std_ulogic;
  82. SSRA : in std_ulogic;
  83. SSRB : in std_ulogic;
  84. WEA : in std_ulogic;
  85. WEB : in std_ulogic
  86. );
  87. end component;
  88.  
  89. for ram_0 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  90. for ram_1 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  91. for ram_2 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  92. for ram_3 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  93. for ram_4 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  94. for ram_5 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  95. for ram_6 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  96. for ram_7 : RAMB16_S1_S1 use entity unisim.RAMB16_S1_S1;
  97.  
  98. --
  99. begin
  100.  
  101. --WRITE ON A READ ON B
  102. --WRITE ON A READ ON B
  103. --WRITE ON A READ ON B
  104. --WRITE ON A READ ON B
  105.  
  106. -- Block SelectRAM Instantiation
  107. ram_0: RAMB16_S1_S1
  108. port map (
  109. DOA => open,
  110. DOB => data_out_0,
  111. ADDRA => write_address,
  112. ADDRB => read_address,
  113. CLKA => clk_signal,
  114. CLKB => clk_signal,
  115. DIA => data_in,
  116. DIB => "0",
  117. ENA => write_enable_0,
  118. ENB => read_enable_0,
  119. SSRA => reset,
  120. SSRB => reset,
  121. WEA => write_enable,
  122. WEB => '0'
  123. );
  124.  
  125. ram_1: RAMB16_S1_S1
  126. port map (
  127. DOA => open,
  128. DOB => data_out_1,
  129. ADDRA => write_address,
  130. ADDRB => read_address,
  131. CLKA => clk_signal,
  132. CLKB => clk_signal,
  133. DIA => data_in,
  134. DIB => "0",
  135. ENA => write_enable_1,
  136. ENB => read_enable_1,
  137. SSRA => reset,
  138. SSRB => reset,
  139. WEA => write_enable,
  140. WEB => '0'
  141. );
  142.  
  143. ram_2: RAMB16_S1_S1
  144. port map (
  145. DOA => open,
  146. DOB => data_out_2,
  147. ADDRA => write_address,
  148. ADDRB => read_address,
  149. CLKA => clk_signal,
  150. CLKB => clk_signal,
  151. DIA => data_in,
  152. DIB => "0",
  153. ENA => write_enable_2,
  154. ENB => read_enable_2,
  155. SSRA => reset,
  156. SSRB => reset,
  157. WEA => write_enable,
  158. WEB => '0'
  159. );
  160.  
  161. ram_3: RAMB16_S1_S1
  162. port map (
  163. DOA => open,
  164. DOB => data_out_3,
  165. ADDRA => write_address,
  166. ADDRB => read_address,
  167. CLKA => clk_signal,
  168. CLKB => clk_signal,
  169. DIA => data_in,
  170. DIB => "0",
  171. ENA => write_enable_3,
  172. ENB => read_enable_3,
  173. SSRA => reset,
  174. SSRB => reset,
  175. WEA => write_enable,
  176. WEB => '0'
  177. );
  178.  
  179. ram_4: RAMB16_S1_S1
  180. port map (
  181. DOA => open,
  182. DOB => data_out_4,
  183. ADDRA => write_address,
  184. ADDRB => read_address,
  185. CLKA => clk_signal,
  186. CLKB => clk_signal,
  187. DIA => data_in,
  188. DIB => "0",
  189. ENA => write_enable_4,
  190. ENB => read_enable_4,
  191. SSRA => reset,
  192. SSRB => reset,
  193. WEA => write_enable,
  194. WEB => '0'
  195. );
  196.  
  197.  
  198. ram_5: RAMB16_S1_S1
  199. port map (
  200. DOA => open,
  201. DOB => data_out_5,
  202. ADDRA => write_address,
  203. ADDRB => read_address,
  204. CLKA => clk_signal,
  205. CLKB => clk_signal,
  206. DIA => data_in,
  207. DIB => "0",
  208. ENA => write_enable_5,
  209. ENB => read_enable_5,
  210. SSRA => reset,
  211. SSRB => reset,
  212. WEA => write_enable,
  213. WEB => '0'
  214. );
  215.  
  216. ram_6: RAMB16_S1_S1
  217. port map (
  218. DOA => open,
  219. DOB => data_out_6,
  220. ADDRA => write_address,
  221. ADDRB => read_address,
  222. CLKA => clk_signal,
  223. CLKB => clk_signal,
  224. DIA => data_in,
  225. DIB => "0",
  226. ENA => write_enable_6,
  227. ENB => read_enable_6,
  228. SSRA => reset,
  229. SSRB => reset,
  230. WEA => write_enable,
  231. WEB => '0'
  232. );
  233.  
  234. ram_7: RAMB16_S1_S1
  235. port map (
  236. DOA => open,
  237. DOB => data_out_7,
  238. ADDRA => write_address,
  239. ADDRB => read_address,
  240. CLKA => clk_signal,
  241. CLKB => clk_signal,
  242. DIA => data_in,
  243. DIB => "0",
  244. ENA => write_enable_7,
  245. ENB => read_enable_7,
  246. SSRA => reset,
  247. SSRB => reset,
  248. WEA => write_enable,
  249. WEB => '0'
  250. );
  251.  
  252. read_enable_0 <= enable and ram_read_mask(0);
  253. write_enable_0 <= enable and ram_write_mask(0);
  254. read_enable_1 <= enable and ram_read_mask(1);
  255. write_enable_1 <= enable and ram_write_mask(1);
  256. read_enable_2 <= enable and ram_read_mask(2);
  257. write_enable_2 <= enable and ram_write_mask(2);
  258. read_enable_3 <= enable and ram_read_mask(3);
  259. write_enable_3 <= enable and ram_write_mask(3);
  260. read_enable_4 <= enable and ram_read_mask(4);
  261. write_enable_4 <= enable and ram_write_mask(4);
  262. read_enable_5 <= enable and ram_read_mask(5);
  263. write_enable_5 <= enable and ram_write_mask(5);
  264. read_enable_6 <= enable and ram_read_mask(6);
  265. write_enable_6 <= enable and ram_write_mask(6);
  266. read_enable_7 <= enable and ram_read_mask(7);
  267. write_enable_7 <= enable and ram_write_mask(7);
  268.  
  269. data_out(0) <= (data_out_0(0) and ram_read_mask(0)) or (data_out_1(0) and ram_read_mask(1)) or (data_out_2(0) and ram_read_mask(2)) or (data_out_3(0) and ram_read_mask(3)) or (data_out_4(0) and ram_read_mask(4)) or (data_out_5(0) and ram_read_mask(5)) or (data_out_6(0) and ram_read_mask(6)) or (data_out_7(0) and ram_read_mask(7));
  270.  
  271.  
  272. --
  273. end dual_port_ram_arq;
  274.  
  275. library ieee;
  276. use ieee.std_logic_1164.all;
  277. use ieee.numeric_std.all;
  278.  
  279. entity dual_port_ram_tb is
  280. end entity;
  281.  
  282. architecture dual_port_ram_tb_arq of dual_port_ram_tb is
  283.  
  284. signal data_in : std_logic_vector (0 downto 0) := (others => '0');
  285. signal write_address : std_logic_vector (13 downto 0) := (others => '0');
  286. signal write_enable : std_logic := '0';
  287. signal ram_write_mask : std_logic_vector(7 downto 0) := (others => '0');
  288. signal enable : std_logic := '0';
  289. signal reset : std_logic := '0';
  290. signal clk : std_logic := '0';
  291. signal ram_read_mask : std_logic_vector(7 downto 0) := (others => '0');
  292. signal read_address : std_logic_vector(13 downto 0) := (others => '0');
  293. signal data_out : std_logic_vector (0 downto 0) := (others => '0');
  294.  
  295. component dual_port_ram is
  296. port (
  297. data_in : in std_logic_vector (0 downto 0) := (others => '0');
  298. write_address : in std_logic_vector (13 downto 0) := (others => '0');
  299. write_enable : in std_logic := '0';
  300. ram_write_mask : in std_logic_vector(7 downto 0) := (others => '0');
  301.  
  302. enable : in std_logic := '0';
  303. clk : in std_logic := '0';
  304. reset : in std_logic := '0';
  305.  
  306. ram_read_mask : in std_logic_vector(7 downto 0) := (others => '0');
  307. read_address : in std_logic_vector(13 downto 0) := (others => '0');
  308. data_out : out std_logic_vector (0 downto 0) := (others => '0')
  309. );
  310. end component;
  311.  
  312. begin
  313.  
  314. dual_port_ram_0 : dual_port_ram
  315. port map(
  316. data_in => data_in,
  317. write_address => write_address,
  318. write_enable => write_enable,
  319. ram_write_mask => ram_write_mask,
  320. enable => enable,
  321. reset => reset,
  322. clk => clk,
  323. ram_read_mask => ram_read_mask,
  324. read_address => read_address,
  325. data_out => data_out
  326. );
  327.  
  328. process
  329.  
  330. type pattern_type is record
  331. din : std_logic_vector(0 downto 0);
  332. wa : std_logic_vector(13 downto 0);
  333. wen : std_logic;
  334. rwm : std_logic_vector(7 downto 0);
  335.  
  336. rrm : std_logic_vector(7 downto 0);
  337. ra : std_logic_vector(13 downto 0);
  338. dot : std_logic_vector(0 downto 0);
  339. end record;
  340. -- The patterns to apply.
  341. type pattern_array is array (natural range <>) of pattern_type;
  342. constant patterns : pattern_array := (
  343. ("1",
  344. "00000000000001",
  345. '1',
  346. "00000001",
  347. "00000000",
  348. "00000000000000",
  349. "0"),
  350. ("0",
  351. "00000000000000",
  352. '0',
  353. "00000000",
  354. "00000001",
  355. "00000000000001",
  356. "1"),
  357. ("1",
  358. "00000001000000",
  359. '1',
  360. "00010000",
  361. "00000000",
  362. "00000000000000",
  363. "0"),
  364. ("1",
  365. "10000000000000",
  366. '1',
  367. "10000000",
  368. "00000000",
  369. "00000000000000",
  370. "0"),
  371. ("0",
  372. "00000000000000",
  373. '0',
  374. "00000000",
  375. "00010000",
  376. "00000001000000",
  377. "1"),
  378. ("0",
  379. "00000000000000",
  380. '0',
  381. "00000000",
  382. "10000000",
  383. "10000000000000",
  384. "1"),
  385. ("1",
  386. "11111111111111",
  387. '0',
  388. "11111111",
  389. "10000000",
  390. "10000000000000",
  391. "1")
  392. );
  393.  
  394.  
  395. begin
  396. clk <= '0';
  397. enable <= '1';
  398. reset <= '0';
  399.  
  400. for i in patterns'range loop
  401.  
  402. clk <= '0';
  403. wait for 1 ns;
  404.  
  405. -- Set the inputs.
  406. data_in <= patterns(i).din;
  407. write_address <= patterns(i).wa;
  408. write_enable <= patterns(i).wen;
  409. ram_write_mask <= patterns(i).rwm;
  410. ram_read_mask <= patterns(i).rrm;
  411. read_address <= patterns(i).ra;
  412.  
  413. clk <= '1';
  414.  
  415. wait for 1 ns;
  416.  
  417. assert patterns(i).dot = data_out report "BAD SAVED VALUE, EXPECTED: " & std_logic'image(patterns(i).dot(0)) & " GOT: " & std_logic'image(data_out(0));
  418.  
  419.  
  420. -- Check the outputs.
  421. end loop;
  422. assert false report "end of test" severity note;
  423. wait;
  424. end process;
  425. end;
  426.  
  427. process(data_in, clk, enable,read_address, write_address, write_enable)
  428. begin
  429. clk_signal <= clk;
  430. end process;
Add Comment
Please, Sign In to add comment