Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- entity classifier is
- port (
- -- Optional Clock
- clk : in std_logic;
- reset : in std_logic;
- -- Dataflow
- data_out : out std_logic_vector(7 downto 0);
- data_in : in std_logic_vector(7 downto 0);
- -- Receiver Comms
- moved : in std_logic; -- On rising edge, receiver confirmed to have iterated
- move_read : out std_logic; -- Request receiver increment pointer
- -- Transmitter Comms
- move_ptr : in std_logic; -- Request to move read pointer
- movedd : out std_logic; -- Request acknowledged and enacted. (send rising edge)
- -- Transmitter RAM controls
- write_ptr : out std_logic_vector(1 downto 0);
- read_ptr : out std_logic_vector(1 downto 0)
- );
- end entity classifier;
- architecture Behavioral of classifier is
- -- Enumerated type for FSM states
- -- Classifier
- type state_type is (LOAD_DATA, CLASSIFICATION, SEND_DATA, TRANSMITTER_COMMS);
- signal current_state_dataflow, next_state_dataflow : state_type;
- -- Transmitter Comms
- type state_type is (IDLE, MOVEDD_rise, MOVEDD_fall, WAIT_MOVE_PTR);
- signal current_state_comms, next_state_comms : state_type;
- -- Register to hold data for classification
- signal classification_data_in, classification_data_out : std_logic_vector(7 downto 0);
- begin
- -- FSM process
- process (clk)
- begin
- if rising_edge(clk) then
- if reset = '1' then
- current_state_dataflow <= LOAD_DATA; -- Initial state
- current_state_comms <= IDLE;
- else
- current_state_dataflow <= next_state_dataflow; -- Update state
- current_state_comms <= next_state_comms;
- end if;
- end if;
- end process;
- ---------------------------------------------------------------
- -- FSM for receiver Comms
- -- 1. when rising_edge(moved)
- -- move_read <= '0';
- -- Receiver Comms FSM
- process (moved)
- begin
- if rising_edge(moved) then
- move_read <= '0';
- end if;
- end process;
- ---------------------------------------------------------------
- -- FSM for Dataflow
- -- Classification
- -- 1. Load data from receiver RAM
- -- 3. Perform Classification Algorithm
- -- 4. Send data to Transmitter RAM
- -- Receiver Comms
- -- 2. Set move_read <= '1';
- -- transmitter Comms
- -- 5. Increment Transmitter write_ptr
- -- 6. go back to 1.
- -- Dataflow FSM
- process (current_state_dataflow, data_in, moved)
- begin
- -- Initialize next state to what the current state is
- next_state_dataflow <= current_state_dataflow;
- case current_state_dataflow is
- when LOAD_DATA =>
- -- Step 1: Load data from receiver RAM
- if move_read = '0' then
- classification_data_in <= data_in;
- move_read <= '1';
- end if;
- next_state_dataflow <= CLASSIFICATION;
- when CLASSIFICATION =>
- -- Step 3: Perform Classification Algorithm
- -- Code for classification algorithm here
- classification_data_out <= 0x"01" when to_integer(signed(classification_data_in)) > 128
- else 0x"00";
- next_state_dataflow <= SEND_DATA;
- when SEND_DATA =>
- -- Step 4: Send data to Transmitter RAM
- data_out <= classification_data_out;
- -- Step 5: Increment Transmitter write_ptr
- write_ptr <= write_ptr + 1;
- next_state_dataflow <= LOAD_DATA;
- end case;
- end process;
- ---------------------------------------------------------------
- -- FSM for Transmitter Comms
- -- 1. when move_ptr = '1'
- -- 2. increment read_ptr
- -- 3. Send rising_edge(moved);
- -- 4. wait for move_ptr = '0'
- -- Go back to 1.
- -- Transmitter Comms FSM
- process(clk, current_state_comms, move_ptr, movedd)
- begin
- -- Initialize next state to what the current state is
- next_state_comms <= current_state_comms;
- case current_state_comms is
- when IDLE =>
- -- Step 1: when move_ptr = '1'
- if move_ptr = '1' then
- -- Step 2: increment read_ptr
- read_ptr <= read_ptr + 1;
- next_state_comms <= MOVEDD_rise;
- end if;
- when MOVEDD_rise => -- Step 3: Send rising_edge(moved);
- if rising_edge(clk) then
- movedd <= '1';
- next_state_comms <= MOVEDD_fall;
- end if;
- when MOVEDD_fall =>-- Step 3: Send rising_edge(moved);
- if falling_edge(clk) then
- movedd <= '0';
- next_state_comms <= WAIT_MOVE_PTR;
- end if;
- when WAIT_MOVE_PTR =>
- -- Step 4: wait for move_ptr = '0'
- if move_ptr = '0' then
- -- Go back to 1.
- next_state_comms <= IDLE;
- end if;
- end case;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement