Advertisement
fransschreuder

Untitled

Jul 4th, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.79 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer: Frans Schreuder
  4. --
  5. -- Create Date: 08/04/2015 08:21:34 AM
  6. -- Design Name:
  7. -- Module Name: FT232H_interface - 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. -- Copyright (C) 2015  Frans Schreuder
  21. --
  22. -- This program is free software: you can redistribute it and/or modify
  23. -- it under the terms of the GNU General Public License as published by
  24. -- the Free Software Foundation, either version 3 of the License, or
  25. -- (at your option) any later version.
  26. --
  27. -- This program is distributed in the hope that it will be useful,
  28. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. -- GNU General Public License for more details.
  31. --
  32. -- You should have received a copy of the GNU General Public License
  33. -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
  34.  
  35. library IEEE;
  36. use IEEE.STD_LOGIC_1164.ALL;
  37.  
  38. -- Uncomment the following library declaration if using
  39. -- arithmetic functions with Signed or Unsigned values
  40. --use IEEE.NUMERIC_STD.ALL;
  41.  
  42. -- Uncomment the following library declaration if instantiating
  43. -- any Xilinx leaf cells in this code.
  44. library UNISIM;
  45. use UNISIM.VComponents.all;
  46.  
  47. entity FT232H_interface is
  48.   Port (
  49.       FT232_DATA         : inout  std_logic_vector(7 downto 0);
  50.       FT232_RXF          : in     std_logic;
  51.       FT232_TXE          : in     std_logic;
  52.       FT232_RD           : out    std_logic;
  53.       FT232_WR           : out    std_logic;
  54.       FT232_CLKOUT       : in     std_logic;
  55.       FT232_OE           : out    std_logic;
  56.       FT232_SIWU         : out    std_logic;
  57.       FT232_PWRSAV       : out    std_logic;
  58.      
  59.       fifo_clk           : in     std_logic;
  60.       reset              : in     std_logic;
  61.       rxfifo_dout        : out    std_logic_vector(7 downto 0);
  62.       rxfifo_empty       : out    std_logic;
  63.       rxfifo_rden        : in     std_logic;
  64.      
  65.       txfifo_din         : in     std_logic_vector(7 downto 0);
  66.       txfifo_full        : out    std_logic;
  67.       txfifo_wren        : in     std_logic
  68.      
  69.   );
  70. end FT232H_interface;
  71.  
  72. architecture Behavioral of FT232H_interface is
  73.  
  74. COMPONENT fifo_128x8
  75.   PORT (
  76.     rst : IN STD_LOGIC;
  77.     wr_clk : IN STD_LOGIC;
  78.     rd_clk : IN STD_LOGIC;
  79.     din : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
  80.     wr_en : IN STD_LOGIC;
  81.     rd_en : IN STD_LOGIC;
  82.     dout : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
  83.     full : OUT STD_LOGIC;
  84.     empty : OUT STD_LOGIC;
  85.     almost_full : OUT STD_LOGIC
  86.   );
  87. END COMPONENT;
  88.  
  89.   signal txfifo_dout : std_logic_vector(7 downto 0);
  90.   signal txfifo_rden : std_logic;
  91.   signal txfifo_empty : std_logic;
  92.   signal rxfifo_din  : std_logic_vector(7 downto 0);
  93.   signal rxfifo_wren : std_logic;
  94.   signal rxfifo_full : std_logic;
  95.  
  96.   signal databuf_T : std_logic;
  97.  
  98.   signal clkout : std_logic;
  99.   signal FT232_OE_s: std_logic;
  100.   signal FT232_OE_p1: std_logic;
  101.   signal FT232_OE_p2: std_logic;
  102.   signal FT232_RD_s: std_logic;
  103. begin
  104.  FT232_SIWU <= '1';
  105.  FT232_PWRSAV <= '1';
  106.  
  107. clkout_bufg: BUFG
  108.  port map(
  109.     I => FT232_CLKOUT,
  110.     O => clkout);
  111.  
  112. txfifo: fifo_128x8
  113.   PORT MAP (
  114.     rst => reset,
  115.     wr_clk => fifo_clk,
  116.     rd_clk => clkout,
  117.     din => txfifo_din,
  118.     wr_en => txfifo_wren,
  119.     rd_en => txfifo_rden,
  120.     dout => txfifo_dout,
  121.     full => txfifo_full,
  122.     empty => txfifo_empty
  123.   );
  124.  
  125. rxfifo: fifo_128x8
  126.   PORT MAP (
  127.     rst => reset,
  128.     wr_clk => clkout,
  129.     rd_clk => fifo_clk,
  130.     din => rxfifo_din,
  131.     wr_en => rxfifo_wren,
  132.     rd_en => rxfifo_rden,
  133.     dout => rxfifo_dout,
  134.     full => open,
  135.     empty => rxfifo_empty,
  136.     almost_full => rxfifo_full
  137.   );
  138.  
  139.  
  140. databuf_gen: for i in 0 to 7 generate
  141.     databuf : IOBUF
  142.     generic map (
  143.         DRIVE => 12,
  144.         IOSTANDARD => "DEFAULT",
  145.         SLEW => "FAST")
  146.     port map (
  147.         O => rxfifo_din(i), -- Buffer output
  148.         IO => FT232_DATA(i),-- Buffer inout port (connect directly to top-level port)
  149.         I => txfifo_dout(i),-- Buffer input
  150.         T => databuf_T-- 3-state enable input, high=input, low=output
  151.     );
  152. end generate;
  153.  
  154. FT232_OE <= FT232_OE_s;
  155. FT232_RD <= FT232_RD_s;
  156.  
  157. rxfifo_wren <= (not FT232_RD_s) and (not FT232_RXF);
  158.  
  159. receve: process(clkout)
  160. begin
  161.     if(rising_edge(clkout)) then
  162.         FT232_OE_p1 <= FT232_OE_s;
  163.         FT232_OE_p2 <= FT232_OE_p1;
  164.         FT232_RD_s <= '1';
  165.         FT232_OE_s <= '1';
  166.  
  167.         if(FT232_RXF = '0' and txfifo_rden = '0') then --not reading from TXfifo and data available in FT232
  168.             FT232_OE_s <= '0';
  169.             if(FT232_OE_s = '0') then --one clock after OE goes low
  170.                 if(rxfifo_full = '0') then
  171.                     FT232_RD_s <= '0';
  172.                 end if;
  173.             end if;
  174.         end if;
  175.     end if;
  176. end process;
  177.  
  178.  
  179. transmit: process( FT232_TXE, FT232_OE_s, FT232_OE_p1, FT232_OE_p2, txfifo_empty)
  180. begin
  181.     txfifo_rden <= '0';
  182.     if(FT232_OE_s = '1' and FT232_OE_p1 = '1' and FT232_OE_p2 = '1') then --make sure that we tristate whenever output is enabled, or 2 clocks after.
  183.         if(FT232_TXE = '0') then
  184.             if(txfifo_empty = '0') then
  185.                 txfifo_rden <= '1';
  186.             end if;
  187.         end if;
  188.     end if;
  189. end process;
  190.  
  191. transmit_c: process(clkout)
  192. begin
  193.     if(rising_edge(clkout)) then
  194.         FT232_WR <= '1';
  195.         databuf_T <= '1';
  196.         if( txfifo_rden = '1') then
  197.             FT232_WR <= '0';
  198.             databuf_T <= '0';
  199.         end if;
  200.     end if;
  201. end process;
  202.  
  203. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement