]> rtime.felk.cvut.cz Git - fpga/uart.git/commitdiff
Receiver control FSM prototype.
authorVladimir Burian <buriavl2@fel.cvut.cz>
Fri, 28 Jan 2011 20:30:50 +0000 (21:30 +0100)
committerVladimir Burian <buriavl2@fel.cvut.cz>
Fri, 4 Feb 2011 09:12:41 +0000 (10:12 +0100)
rx_control.vhd [new file with mode: 0644]
tb/Makefile

diff --git a/rx_control.vhd b/rx_control.vhd
new file mode 100644 (file)
index 0000000..ad10c6d
--- /dev/null
@@ -0,0 +1,101 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.std_logic_arith.all;
+use ieee.std_logic_unsigned.all;
+
+entity rx_control is
+  port (
+    clk           : in  std_logic;
+    reset         : in  std_logic;
+    rx            : in  std_logic;
+    bad_start_bit : in  std_logic;
+    bad_stop_bit  : in  std_logic;
+    rx_ready      : in  std_logic;
+    rx_reset      : out std_logic;
+    rx_en         : out std_logic;
+    fifo_we       : out std_logic;
+    clk_en        : out std_logic);
+end entity rx_control;
+
+--------------------------------------------------------------------------------
+
+architecture behavioral of rx_control is
+
+  type state_t is (resetting, waiting, next_frame, receiving);
+
+  signal state : state_t;
+
+--------------------------------------------------------------------------------
+
+begin
+
+  process (clk, reset) is
+  begin
+    if reset = '1' then
+      state    <= waiting;
+      rx_reset <= '0';
+      rx_en    <= '0';
+      fifo_we  <= '0';
+      clk_en   <= '0';
+
+    elsif clk'event and clk = '1' then
+      case state is
+        when resetting =>
+          state    <= waiting;
+          rx_reset <= '0';
+          rx_en    <= '0';
+          fifo_we  <= '0';
+          clk_en   <= '0';
+
+
+        when waiting =>
+          rx_reset <= '0';
+          rx_en    <= '0';
+          fifo_we  <= '0';
+          clk_en   <= '0';
+
+          if rx = '0' then
+            state  <= next_frame;
+            rx_en  <= '1';
+            clk_en <= '1';
+          end if;
+
+
+        when next_frame =>
+          rx_reset <= '0';
+          rx_en    <= '1';
+          fifo_we  <= '0';
+          clk_en   <= '1';
+
+          if rx_ready = '0' then
+            if bad_start_bit = '1' then
+              state    <= resetting;
+              rx_reset <= '1';
+              rx_en    <= '0';
+              clk_en   <= '0';
+
+            else
+              state <= receiving;
+              rx_en <= '0';
+            end if;
+          end if;
+
+
+        when receiving =>
+          rx_reset <= '0';
+          rx_en    <= '0';
+          fifo_we  <= '0';
+          clk_en   <= '1';
+
+          if rx_ready = '1' then
+            state   <= waiting;
+            fifo_we <= '1';
+            clk_en  <= '0';
+          end if;
+
+      end case;
+    end if;
+  end process;
+
+end architecture behavioral;
+
index 88f78a0d1bdd0f96a8b29faf1786b6c2110cc049..3f6333ebf3d510c530a6996da2fa49fd80dbc230 100644 (file)
@@ -4,7 +4,8 @@ VHDL_ENTITIES = uart.o \
                 fifo.o \
                 baud_gen.o \
                 tx_control.o \
-                rx.o
+                rx.o \
+                rx_control.o
 
 STOP_TIME     = 50us