Advertisement
Guest User

FIFO

a guest
Feb 23rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity FIFO8x9 is
  6. port(
  7. clk, rst: in std_logic;
  8. RdPtrClr, WrPtrClr: in std_logic;
  9. RdInc, WrInc: in std_logic;
  10. DataIn: in std_logic_vector(8 downto 0);
  11. DataOut: out std_logic_vector(8 downto 0);
  12. rden, wren: in std_logic
  13. );
  14. end entity FIFO8x9;
  15.  
  16. architecture RTL of FIFO8x9 is
  17. --signal declarations
  18. type fifo_array is array(7 downto 0) of std_logic_vector(8 downto 0); -- makes use of VHDL’s enumerated type
  19. signal fifo: fifo_array;
  20. signal wrptr, rdptr: unsigned(2 downto 0);
  21. signal en: std_logic_vector(7 downto 0);
  22. signal dmuxout: std_logic_vector(8 downto 0);
  23.  
  24. begin
  25. fifo_proc : process (clk, rst)
  26. begin
  27. if (rst = '1') then
  28. for i in 7 downto 0 loop
  29. fifo(i) <= "000000000";
  30. end loop;
  31.  
  32. elsif (rising_edge(clk)) then
  33. if (wren = '1') then
  34. for i in 7 downto 0 loop
  35. if en(i) = '1' then
  36. fifo(i) <= DataIn;
  37. else
  38. fifo(i) <= fifo(i);
  39. end if;
  40. end loop;
  41. end if;
  42. end if;
  43. end process fifo_proc;
  44.  
  45. with wrptr select
  46. en <= "00000001" when "000",
  47. "00000010" when "001",
  48. "00000100" when "010",
  49. "00001000" when "011",
  50. "00010000" when "100",
  51. "00100000" when "101",
  52. "01000000" when "110",
  53. "10000000" when others;
  54.  
  55. rd_pointer: process (clk, rst)
  56. begin
  57. if (rst = '1') then
  58. rdptr <= "000";
  59. elsif rising_edge(clk) then
  60. if (RdPtrClr = '1') then
  61. rdptr <= "000";
  62. elsif RdInc = '1' then
  63. rdptr <= rdptr + 1;
  64. end if;
  65. end if;
  66. end process rd_pointer;
  67.  
  68. wrt_pointer: process (clk, rst)
  69. begin
  70. if (rst = '1') then
  71. wrptr <= "000";
  72. elsif rising_edge(clk) then
  73. if (WrPtrClr = '1') then
  74. wrptr <= "000";
  75. elsif WrInc = '1' then
  76. wrptr <= wrptr + 1;
  77. end if;
  78. end if;
  79. end process wrt_pointer;
  80.  
  81. with rdptr select
  82. dmuxout <= fifo(0) when "000",
  83. fifo(1) when "001",
  84. fifo(2) when "010",
  85. fifo(3) when "011",
  86. fifo(4) when "100",
  87. fifo(5) when "101",
  88. fifo(6) when "110",
  89. fifo(7) when others;
  90.  
  91. read_proc: process (rden, dmuxout)
  92. begin
  93. if (rden = '1') then
  94. DataOut <= dmuxout;
  95. -- rdptr <= rdptr + 1;
  96. else
  97. DataOut <= "ZZZZZZZZZ";
  98. end if;
  99. end process read_proc;
  100.  
  101. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement