Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.78 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. LIBRARY altera_mf;
  5. USE altera_mf.altera_mf_components.all;
  6.  
  7. entity fifo_test is
  8. end fifo_test;
  9.  
  10. architecture rtl of fifo_test is
  11. --Component declaration
  12. component scfifo
  13. generic (
  14. add_ram_output_register : string := "OFF";
  15. allow_rwcycle_when_full : string := "OFF";
  16. almost_empty_value : natural := 0;
  17. almost_full_value : natural := 0;
  18. intended_device_family : string := "Cyclone IV";
  19. enable_ecc : string := "FALSE";
  20. lpm_numwords : natural;
  21. lpm_showahead : string := "OFF";
  22. lpm_width : natural;
  23. lpm_widthu : natural := 1;
  24. overflow_checking : string := "ON";
  25. ram_block_type : string := "AUTO";
  26. underflow_checking : string := "ON";
  27. use_eab : string := "ON";
  28. lpm_hint : string := "UNUSED";
  29. lpm_type : string := "scfifo"
  30. );
  31. port(
  32. aclr : in std_logic := '0';
  33. almost_empty : out std_logic;
  34. almost_full : out std_logic;
  35. clock : in std_logic;
  36. data : in std_logic_vector(lpm_width-1 downto 0);
  37. eccstatus : out std_logic_vector(1 downto 0);
  38. empty : out std_logic;
  39. full : out std_logic;
  40. q : out std_logic_vector(lpm_width-1 downto 0);
  41. rdreq : in std_logic;
  42. sclr : in std_logic := '0';
  43. usedw : out std_logic_vector(lpm_widthu-1 downto 0);
  44. wrreq : in std_logic
  45. );
  46. end component;
  47.  
  48. -- internal signals
  49. signal aclr : std_logic := '0';
  50. signal almost_empty : std_logic;
  51. signal almost_full : std_logic;
  52. signal clock : std_logic;
  53. signal data : std_logic_vector(7 downto 0);
  54. signal eccstatus : std_logic_vector(1 downto 0);
  55. signal empty : std_logic;
  56. signal full : std_logic;
  57. signal q : std_logic_vector(7 downto 0);
  58. signal rdreq : std_logic;
  59. signal sclr : std_logic := '0';
  60. signal usedw : std_logic_vector(2 downto 0);
  61. signal wrreq : std_logic;
  62.  
  63. begin
  64.  
  65. --instantiate a scfifo
  66. fifo : scfifo
  67. generic map
  68. (
  69. almost_empty_value => 2,
  70. almost_full_value => 6,
  71. lpm_numwords => 8,
  72. lpm_showahead => "OFF",
  73. lpm_width => 8,
  74. lpm_widthu => 3,
  75. overflow_checking => "ON",
  76. underflow_checking => "ON",
  77. use_eab => "ON"
  78. )
  79. port map
  80. (
  81. aclr => aclr,
  82. almost_empty => almost_empty,
  83. almost_full => almost_full,
  84. clock => clock,
  85. data => data,
  86. eccstatus => eccstatus,
  87. empty => empty,
  88. full => full,
  89. q => q,
  90. rdreq => rdreq,
  91. sclr => sclr,
  92. usedw => usedw,
  93. wrreq => wrreq
  94. );
  95.  
  96.  
  97. --Generate the clock
  98. clk: process
  99. begin
  100. clock <= '0';
  101. wait for 10 ns;
  102. for n in 1 to 64 loop
  103. clock <= '1';
  104. wait for 10 ns;
  105. clock <= '0';
  106. wait for 10 ns;
  107. end loop;
  108.  
  109. wait;
  110. end process;
  111.  
  112. --Perform tests
  113. testv: process
  114.  
  115. begin
  116. data <= "00000000";
  117. rdreq <= '0';
  118. wrreq <= '0';
  119. wait until falling_edge(clock);
  120. assert usedw = "000" report "Wrong number of samples" severity error;
  121. assert q = "00000000" report "Wrong output" severity error;
  122. assert empty = '1' report "Empty bit unexpected" severity error;
  123. assert full = '0' report "Full bit unexpected" severity error;
  124.  
  125. --Add a word
  126. data <= "00000011";
  127. rdreq <= '0';
  128. wrreq <= '1';
  129. wait until rising_edge(clock);
  130. wait until falling_edge(clock);
  131. assert usedw = "001" report "Wrong number of samples" severity error;
  132. assert q = "00000000" report "Wrong output" severity error;
  133. assert empty = '0' report "Empty bit unexpected" severity error;
  134. assert full = '0' report "Full bit unexpected" severity error;
  135.  
  136. -- don't add
  137. data <= "10101010";
  138. rdreq <= '0';
  139. wrreq <= '0';
  140. wait until rising_edge(clock);
  141. wait until falling_edge(clock);
  142. assert usedw = "001" report "Wrong number of samples" severity error;
  143. assert q = "00000000" report "Wrong output" severity error;
  144. assert empty = '0' report "Empty bit unexpected" severity error;
  145. assert full = '0' report "Full bit unexpected" severity error;
  146.  
  147. --Add a word
  148. data <= "00001100";
  149. rdreq <= '0';
  150. wrreq <= '1';
  151. wait until rising_edge(clock);
  152. wait until falling_edge(clock);
  153. assert usedw = "010" report "Wrong number of samples" severity error;
  154. assert q = "00000000" report "Wrong output" severity error;
  155. assert empty = '0' report "Empty bit unexpected" severity error;
  156. assert full = '0' report "Full bit unexpected" severity error;
  157.  
  158. --Add a word
  159. data <= "00110000";
  160. rdreq <= '0';
  161. wrreq <= '1';
  162. wait until rising_edge(clock);
  163. wait until falling_edge(clock);
  164. assert usedw = "011" report "Wrong number of samples" severity error;
  165. assert q = "00000000" report "Wrong output" severity error;
  166. assert empty = '0' report "Empty bit unexpected" severity error;
  167. assert full = '0' report "Full bit unexpected" severity error;
  168.  
  169. -- don't add
  170. data <= "01010101";
  171. rdreq <= '0';
  172. wrreq <= '0';
  173. wait until rising_edge(clock);
  174. wait until falling_edge(clock);
  175. assert usedw = "011" report "Wrong number of samples" severity error;
  176. assert q = "00000000" report "Wrong output" severity error;
  177. assert empty = '0' report "Empty bit unexpected" severity error;
  178. assert full = '0' report "Full bit unexpected" severity error;
  179.  
  180. --Add a word
  181. data <= "11000000";
  182. rdreq <= '0';
  183. wrreq <= '1';
  184. wait until rising_edge(clock);
  185. wait until falling_edge(clock);
  186. assert usedw = "100" report "Wrong number of samples" severity error;
  187. assert q = "00000000" report "Wrong output" severity error;
  188. assert empty = '0' report "Empty bit unexpected" severity error;
  189. assert full = '0' report "Full bit unexpected" severity error;
  190.  
  191. --Read a word
  192. data <= "11000000";
  193. rdreq <= '1';
  194. wrreq <= '0';
  195. wait until rising_edge(clock);
  196. wait until falling_edge(clock);
  197. assert usedw = "011" report "Wrong number of samples" severity error;
  198. assert q = "00000011" report "Wrong output" severity error;
  199. assert empty = '0' report "Empty bit unexpected" severity error;
  200. assert full = '0' report "Full bit unexpected" severity error;
  201.  
  202. --Read a word
  203. data <= "11000000";
  204. rdreq <= '1';
  205. wrreq <= '0';
  206. wait until rising_edge(clock);
  207. wait until falling_edge(clock);
  208. assert usedw = "010" report "Wrong number of samples" severity error;
  209. assert q = "00001100" report "Wrong output" severity error;
  210. assert empty = '0' report "Empty bit unexpected" severity error;
  211. assert full = '0' report "Full bit unexpected" severity error;
  212.  
  213. --Nothing
  214. data <= "10011100";
  215. rdreq <= '0';
  216. wrreq <= '0';
  217. wait until rising_edge(clock);
  218. wait until falling_edge(clock);
  219. assert usedw = "010" report "Wrong number of samples" severity error;
  220. assert q = "00001100" report "Wrong output" severity error;
  221.  
  222. --Add and read a word
  223. data <= "11111111";
  224. rdreq <= '1';
  225. wrreq <= '1';
  226. wait until rising_edge(clock);
  227. wait until falling_edge(clock);
  228. assert usedw = "010" report "Wrong number of samples" severity error;
  229. assert q = "00110000" report "Wrong output" severity error;
  230. assert empty = '0' report "Empty bit unexpected" severity error;
  231. assert full = '0' report "Full bit unexpected" severity error;
  232.  
  233. --Read a word
  234. data <= "11011101";
  235. rdreq <= '1';
  236. wrreq <= '0';
  237. wait until rising_edge(clock);
  238. wait until falling_edge(clock);
  239. assert usedw = "001" report "Wrong number of samples" severity error;
  240. assert q = "11000000" report "Wrong output" severity error;
  241. assert empty = '0' report "Empty bit unexpected" severity error;
  242. assert full = '0' report "Full bit unexpected" severity error;
  243.  
  244.  
  245. --Read a word
  246. data <= "11011101";
  247. rdreq <= '1';
  248. wrreq <= '0';
  249. wait until rising_edge(clock);
  250. wait until falling_edge(clock);
  251. assert usedw = "000" report "Wrong number of samples" severity error;
  252. assert q = "11111111" report "Wrong output" severity error;
  253. assert empty = '1' report "Empty bit unexpected" severity error;
  254. assert full = '0' report "Full bit unexpected" severity error;
  255.  
  256. --Log to terminal
  257. assert false report "Next: fill the fifo" severity note;
  258.  
  259. --Now we fill the fifo
  260. data <= "10101010";
  261. rdreq <= '0';
  262. wrreq <= '1';
  263. for n in 1 to 8 loop
  264. wait until rising_edge(clock);
  265. wait until falling_edge(clock);
  266. end loop;
  267. assert usedw = "000" report "Wrong number of samples" severity error;
  268. assert q = "11111111" report "Wrong output" severity error;
  269. assert empty = '0' report "Empty bit unexpected" severity error;
  270. assert full = '1' report "Full bit unexpected" severity error;
  271.  
  272. --Add a word (should be dropped)
  273. data <= "00000000";
  274. rdreq <= '0';
  275. wrreq <= '1';
  276. wait until rising_edge(clock);
  277. wait until falling_edge(clock);
  278. assert usedw = "000" report "Wrong number of samples" severity error;
  279. assert q = "11111111" report "Wrong output" severity error;
  280. assert empty = '0' report "Empty bit unexpected" severity error;
  281. assert full = '1' report "Full bit unexpected" severity error;
  282.  
  283.  
  284. --Add and read a word on a full fifo (edge case - write fails then read succeeds)
  285. data <= "11110000";
  286. rdreq <= '1';
  287. wrreq <= '1';
  288. wait until rising_edge(clock);
  289. wait until falling_edge(clock);
  290. assert usedw = "111" report "edge: Wrong number of samples" severity error;
  291. assert q = "10101010" report "edge: Wrong output" severity error;
  292. assert empty = '0' report "Edge: mpty bit unexpected" severity error;
  293. assert full = '0' report "Edge: Full bit unexpected" severity error;
  294.  
  295.  
  296. --Read back remaining 7 words in the buffer
  297. data <= "00000000";
  298. rdreq <= '1';
  299. wrreq <= '0';
  300. for n in 1 to 7 loop
  301. wait until rising_edge(clock);
  302. wait until falling_edge(clock);
  303. assert q = "10101010" report "Wrong output" severity error;
  304. end loop;
  305.  
  306. assert usedw = "000" report "Wrong number of samples" severity error;
  307. assert empty = '1' report "Empty bit unexpected" severity error;
  308. assert full = '0' report "Full bit unexpected" severity error;
  309.  
  310. --Add and read a word on an empty fifo (edge case - read fails, write succeeds - output remains unchanged from previous)
  311. data <= "11110000";
  312. rdreq <= '1';
  313. wrreq <= '1';
  314. wait until rising_edge(clock);
  315. wait until falling_edge(clock);
  316. assert usedw = "001" report "edge: Wrong number of samples" severity error;
  317. assert q = "10101010" report "edge: Wrong output" severity error;
  318. assert empty = '0' report "Edge: Empty bit unexpected" severity error;
  319. assert full = '0' report "Edge: Full bit unexpected" severity error;
  320.  
  321. --Read back last write to empty the buffer once more
  322. data <= "10111010";
  323. rdreq <= '1';
  324. wrreq <= '0';
  325. wait until rising_edge(clock);
  326. wait until falling_edge(clock);
  327. assert usedw = "000" report "edge: Wrong number of samples" severity error;
  328. assert q = "11110000" report "edge: Wrong output" severity error;
  329. assert empty = '1' report "Edge: Empty bit unexpected" severity error;
  330. assert full = '0' report "Edge: Full bit unexpected" severity error;
  331.  
  332. --Read empty buffer
  333. data <= "00001111";
  334. rdreq <= '1';
  335. wrreq <= '0';
  336. wait until rising_edge(clock);
  337. wait until falling_edge(clock);
  338. assert usedw = "000" report "edge: Wrong number of samples" severity error;
  339. assert q = "11110000" report "edge: Wrong output" severity error;
  340. assert empty = '1' report "Edge: Empty bit unexpected" severity error;
  341. assert full = '0' report "Edge: Full bit unexpected" severity error;
  342.  
  343. --Add three samples to the empty buffer
  344. data <= "00000001";
  345. rdreq <= '0';
  346. wrreq <= '1';
  347. wait until rising_edge(clock);
  348. wait until falling_edge(clock);
  349. data <= "00000010";
  350. wait until rising_edge(clock);
  351. wait until falling_edge(clock);
  352. data <= "00000100";
  353. wait until rising_edge(clock);
  354. wait until falling_edge(clock);
  355. --Clear with sclr
  356. rdreq <= '0';
  357. wrreq <= '0';
  358. sclr <= '1';
  359. wait until rising_edge(clock);
  360. wait until falling_edge(clock);
  361. assert usedw = "000" report "edge: Wrong number of samples" severity error;
  362. assert empty = '1' report "Edge: Empty bit unexpected" severity error;
  363. assert full = '0' report "Edge: Full bit unexpected" severity error;
  364.  
  365. --Add three samples to the empty buffer
  366. data <= "00000001";
  367. rdreq <= '0';
  368. wrreq <= '1';
  369. wait until rising_edge(clock);
  370. wait until falling_edge(clock);
  371. data <= "00000010";
  372. wait until rising_edge(clock);
  373. wait until falling_edge(clock);
  374. data <= "00000100";
  375. wait until rising_edge(clock);
  376. wait until falling_edge(clock);
  377. --Clear with sclr and write at the same time
  378. rdreq <= '0';
  379. wrreq <= '1';
  380. sclr <= '1';
  381. wait until rising_edge(clock);
  382. wait until falling_edge(clock);
  383. assert usedw = "000" report "edge: Wrong number of samples" severity error;
  384. assert empty = '1' report "Edge: Empty bit unexpected" severity error;
  385. assert full = '0' report "Edge: Full bit unexpected" severity error;
  386. wait;
  387.  
  388.  
  389. end process;
  390.  
  391. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement