Advertisement
Endrerl

lab8_del2

Nov 14th, 2019
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.41 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity TB is
  6.   port(
  7.     CLOCK_50 : in    std_logic;
  8.     KEY      : in    std_logic_vector(3 downto 0);
  9.     SW       : in    std_logic_vector(17 downto 0);
  10.     GPIO     : inout std_logic_vector(35 downto 0);
  11.     LEDR     : out   std_logic_vector(17 downto 0);
  12.     LEDG     : out   std_logic_vector(7 downto 0)
  13.     );
  14. end entity TB;
  15.  
  16. architecture RTL of TB is
  17.  
  18.   component Enable_gen is
  19.     port(clock_50    : in  std_logic;
  20.          resetn      : in  std_logic;
  21.          velg_enable : in  std_logic_vector(2 downto 0);
  22.          Enable      : out std_logic);
  23.   end component;
  24.  
  25.   component reset_synchronizer is
  26.     port(
  27.       clk        : in  std_logic;
  28.       reset_key3 : in  std_logic;
  29.       reset_clk  : out std_logic
  30.       );
  31.   end component reset_synchronizer;
  32.  
  33.   component baudrate_gen is
  34.     port(
  35.       CLOCK_50      : in std_logic;
  36.       resetn        : in std_logic;
  37.       velg_baudrate : in std_logic_vector(2 downto 0);
  38.       start_teller  : in std_logic;
  39.  
  40.       baud_enable_m : out std_logic;
  41.       baud_enable_s : out std_logic
  42.       );
  43.   end component baudrate_gen;
  44.  
  45.   signal resetn                                          : std_logic;
  46.   signal hallo_enable                                    : std_logic;
  47.   signal hallo                                           : std_logic;
  48.   signal sender                                          : std_logic;
  49.   signal mottatt_blink                                   : std_logic;
  50.   signal vippe_a, vippe_b                                : std_logic;
  51.   signal shiftreg                                        : std_logic_vector(9 downto 0);
  52.   signal dout                                            : std_logic;
  53.   signal start_bit                                       : std_logic := '0';
  54.   signal stopp_bit                                       : std_logic := '1';
  55.   type tilstand_sender is (s_idle, s_transmit, s_shift_out, s_finish, s_wait);
  56.   signal state_sender                                    : tilstand_sender;
  57.   type tilstand_mottaker is (s_idle, s_wait_for_sender, s_shift_in, s_offload, S_error);
  58.   signal state_mottaker                                  : tilstand_mottaker;
  59.   signal start                                           : std_logic;
  60.   signal data_inn_q, data_inn_qq, data_inn_qqq, data_inn : std_logic;
  61.   signal state_error                                     : std_logic;
  62.   signal mottatt_bit                                     : std_logic;
  63.   signal data_reg                                        : std_logic_vector(7 downto 0);
  64.   signal start_teller, baud_enable_m, baud_enable_s      : std_logic;
  65.  
  66.  
  67. begin
  68.   LEDR(17)         <= hallo;
  69.   sender           <= SW(17);
  70.   LEDG(0)          <= sender;
  71.   LEDG(7)          <= mottatt_blink;
  72.   start            <= KEY(0);
  73.   data_inn         <= GPIO(7)        when sender = '0' else '1';
  74.   GPIO(7)          <= dout           when sender = '1' else 'Z';
  75.   GPIO(1)          <= hallo          when sender = '1' else 'Z';
  76.   LEDR(7 downto 0) <= SW(7 downto 0) when sender = '1' else data_reg(7 downto 0);
  77.   LEDR(16)         <= state_error    when sender = '0' else '0';
  78.   p_send_motta_hallo : process (CLOCK_50) is
  79.   begin
  80.     if rising_edge(CLOCK_50) then
  81.       if sender = '1' then
  82.         -- sender
  83.         mottatt_blink <= '0';
  84.         if resetn = '0' then
  85.           GPIO(5)      <= '1';
  86.           state_sender <= s_idle;
  87.         else
  88.           GPIO(5) <= '0';
  89.           case state_sender is
  90.             when s_idle =>
  91.               shiftreg <= (others => '0');
  92.               dout     <= '1';
  93.               if start = '0' then
  94.                 state_sender <= s_transmit;
  95.               end if;
  96.             when s_transmit =>
  97.               dout         <= '1';
  98.               shiftreg     <= stopp_bit & SW(8 downto 1) & start_bit;
  99.               state_sender <= s_shift_out;
  100.             when s_shift_out =>
  101.               if baud_enable_s = '1' then
  102.                 shiftreg <= '0' & shiftreg(9 downto 1);
  103.                 dout     <= shiftreg(0);
  104.               elsif shiftreg = "0000000000" then
  105.                 state_sender <= s_finish;
  106.               end if;
  107.             when s_finish =>
  108.               dout         <= '1';
  109.               state_sender <= s_wait;
  110.             when s_wait =>
  111.               state_sender <= s_transmit;
  112.             when others =>
  113.               state_sender <= s_idle;
  114.           end case;
  115.         end if;
  116.  
  117.       else
  118.         -- mottaker
  119.         GPIO(5) <= 'Z';
  120.  
  121.         vippe_a       <= GPIO(1);
  122.         vippe_b       <= vippe_a;
  123.         mottatt_blink <= vippe_b;
  124.  
  125.         if GPIO(5) = '1' then
  126.           state_mottaker <= s_idle;
  127.         else
  128.           case state_mottaker is
  129.             when s_idle =>
  130.               state_error <= '0';
  131.               shiftreg    <= (9 => '1', others => '0');
  132.               if mottatt_bit = '1' then
  133.                 state_mottaker <= s_wait_for_sender;
  134.               end if;
  135.             when s_wait_for_sender =>
  136.               if mottatt_bit = '0' then
  137.                 state_mottaker <= s_shift_in;
  138.               end if;
  139.             when s_shift_in =>
  140.               if baud_enable_m = '1' then
  141.                 shiftreg <= mottatt_bit & shiftreg(9 downto 1);
  142.                 if shiftreg(0) = '1' and shiftreg(9) = '0' then
  143.                   state_mottaker <= S_error;
  144.                 elsif shiftreg(0) = '1' and shiftreg(9) = '1' then
  145.                   state_mottaker <= s_offload;
  146.                 end if;
  147.               end if;
  148.             when S_error =>
  149.               state_error <= '1';
  150.             when s_offload =>
  151.               data_reg(7 downto 0) <= shiftreg(8 downto 1);
  152.               state_mottaker       <= s_idle;
  153.             when others =>
  154.               state_mottaker <= s_idle;
  155.           end case;
  156.         end if;
  157.       end if;
  158.     end if;
  159.  
  160.   end process;
  161.  
  162.  
  163.  
  164.  
  165.  
  166.   p_start_teller : process (CLOCK_50) is
  167.   begin
  168.     if rising_edge(CLOCK_50) then
  169.       if resetn = '0' then
  170.         start_teller <= '0';
  171.         data_inn_q   <= '0';
  172.         data_inn_qq  <= '0';
  173.         data_inn_qqq <= '0';
  174.       else
  175.         start_teller <= '0';
  176.         data_inn_q   <= data_inn;
  177.         data_inn_qq  <= data_inn_q;
  178.         data_inn_qqq <= data_inn_qq;
  179.         if data_inn_qqq = '1' and data_inn_qq = '0' then
  180.           mottatt_bit <= '1';
  181.           if state_mottaker = s_wait_for_sender then
  182.             start_teller <= '1';
  183.           end if;
  184.         end if;
  185.       end if;
  186.     end if;
  187.  
  188.   end process p_start_teller;
  189.  
  190.  
  191.   baudrate_gen_inst : component baudrate_gen
  192.     port map(
  193.       CLOCK_50      => CLOCK_50,
  194.       resetn        => resetn,
  195.       velg_baudrate => SW(16 downto 14),
  196.       start_teller  => start_teller,
  197.       baud_enable_m => baud_enable_m,
  198.       baud_enable_s => baud_enable_s
  199.       );
  200.  
  201.   Enable_gen_inst : component Enable_gen
  202.     port map(
  203.       clock_50    => CLOCK_50,
  204.       resetn      => resetn,
  205.       velg_enable => "000",
  206.       Enable      => hallo_enable
  207.       );
  208.  
  209.   reset_synchronizer_inst : component reset_synchronizer
  210.     port map(
  211.       clk        => CLOCK_50,
  212.       reset_key3 => KEY(3),
  213.       reset_clk  => resetn
  214.       );
  215.  
  216.   p_hallo : process (CLOCK_50) is
  217.   begin
  218.     if rising_edge(CLOCK_50) then
  219.       if resetn = '0' then
  220.         hallo <= '0';
  221.       elsif hallo_enable = '1' then
  222.         hallo <= not hallo;
  223.       end if;
  224.     end if;
  225.   end process p_hallo;
  226.  
  227.  
  228.  
  229. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement