Advertisement
Guest User

uart_byte_collector

a guest
Sep 4th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.63 KB | None | 0 0
  1. LIBRARY ieee;
  2. use ieee.numeric_std.all;
  3. use IEEE.std_logic_1164.all;
  4.  
  5. ENTITY uart_byte_collector IS
  6.     PORT(  
  7.             rst                     :   in  std_logic;
  8.             clk                     :   in  std_logic;
  9.            
  10.             rx_dv                   :   in  std_logic;
  11.             rx_byte                 :   in  std_logic_vector(7 downto 0);
  12.            
  13.             ready                   :   out std_logic;
  14.            
  15.             byte0                   :   out std_logic_vector(7 downto 0);
  16.             byte1                   :   out std_logic_vector(7 downto 0);
  17.             byte2                   :   out std_logic_vector(7 downto 0);
  18.             byte3                   :   out std_logic_vector(7 downto 0);
  19.             byte4                   :   out std_logic_vector(7 downto 0);
  20.             byte5                   :   out std_logic_vector(7 downto 0)
  21.         );
  22. END ENTITY uart_byte_collector;
  23.  
  24. ARCHITECTURE behavioural OF uart_byte_collector IS
  25.    
  26.     signal byte_counter : integer range 0 to 6;
  27.     type byte_array is array (0 to 5) of std_logic_vector(7 downto 0);
  28.     signal serial_byte : byte_array;
  29.     signal time_out_counter : integer range 0 to 66500000;
  30.     signal time_out_counter_enable, time_out_flag : std_logic;
  31.    
  32.     signal data_ready   :   std_logic;
  33. begin
  34.  
  35.     collect_bytes : process (rst, clk) is
  36.     begin
  37.         if rst = '1' then
  38.             serial_byte <= (others => (others => '0'));
  39.             byte_counter <= 0;
  40.             time_out_counter_enable <= '0';
  41.             data_ready <= '0';
  42.         elsif rising_edge(clk) then
  43.             if time_out_flag = '1' then
  44.                 serial_byte <= (others => (others => '0'));
  45.                 byte_counter <= 0;
  46.                 time_out_counter_enable <= '0';
  47.                 data_ready <= '0';
  48.             elsif byte_counter < 6 then
  49.                 if rx_dv = '1' then
  50.                     serial_byte(byte_counter) <= rx_byte;
  51.                     byte_counter <= byte_counter + 1;
  52.                     time_out_counter_enable <= '1';
  53.                    
  54.                 end if;
  55.             else
  56.                 if data_ready = '0' then
  57.                     data_ready <= '1';
  58.                     time_out_counter_enable <= '0';
  59.                 else
  60.                     serial_byte <= (others => (others => '0'));
  61.                     byte_counter <= 0;
  62.                     data_ready <= '0';
  63.                 end if;
  64.            
  65.             end if;
  66.            
  67.         end if;
  68.     end process;
  69.  
  70.  
  71.  
  72.     timeout : process (rst, clk) is
  73.     begin
  74.         if rst = '1' then
  75.             time_out_counter <= 0;
  76.             time_out_flag <= '0';
  77.         elsif rising_edge(clk) then
  78.             if time_out_flag = '0' then
  79.                 if time_out_counter_enable = '1' then
  80.                     time_out_counter <= time_out_counter + 1;
  81.                     if time_out_counter = 66500000 then
  82.                         time_out_flag <= '1';
  83.                         time_out_counter <= 0;
  84.                     end if;
  85.                 else
  86.                     time_out_counter <= 0;
  87.                     time_out_flag <= '0';
  88.                 end if;
  89.            
  90.             else
  91.                 time_out_counter <= 0;
  92.                 time_out_flag <= '0';
  93.            
  94.             end if;
  95.         end if;
  96.     end process;
  97.    
  98.    
  99.     ready <= data_ready;
  100.    
  101.     byte0 <= serial_byte(0);
  102.     byte1 <= serial_byte(1);
  103.     byte2 <= serial_byte(2);
  104.     byte3 <= serial_byte(3);
  105.     byte4 <= serial_byte(4);
  106.     byte5 <= serial_byte(5);
  107.    
  108. end architecture behavioural;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement