-- Header structure: ----------------------------------------------------------------------------------------------------- --| | | 2bit | 2bit | 2bit | 2bit | 2bit | 2bit | | --| Flit_padding | Packet_id | Z_src | Y_src | X_src | Z_dest | Y_dest | X_dest | Packet_length | --|31 3bits 29|28 12 bits 17|16 6bits 11|10 6bits 5|4 5bits 0| ----------------------------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; ----------------------NoC Interface Entity--------------------------- entity noc_interface is -- constant DATA_SIZE : integer := 7; -- Define constant for vector size for data of 8 bits -- constant LENGTH : integer := 4; -- Define constant for vector size for size of Id's 5 bits -- constant PACKET : integer := 11; -- Define constant for vector size for size of Id's 12 bits -- constant REG_SIZE : integer := 31; -- Define constant for vector size for size of Reg 31 bits generic ( DATA_SIZE : natural := 7; -- Define constant for vector size for data of 8 bits LENGTH : natural := 4; -- Define constant for vector size for size of Id's 5 bits PACKET : natural := 11; -- Define constant for vector size for size of Id's 12 bits REG_SIZE : natural := 31; -- Define constant for vector size for size of Reg 31 bits SOURCE_ID : std_logic_vector(5 downto 0) := "000000"; -- Default source ID should be changed DEST_ID : std_logic_vector(5 downto 0) := "000001" -- Default destination ID should be changed ); port( clk : in std_logic; rst : in std_logic; sent_valid_from_dma : in std_logic; --From DMA data_bus_noc_in : in std_logic_vector(DATA_SIZE downto 0); --From RAM tx_packet_length_noc : in std_logic_vector(LENGTH downto 0); --From DMA local_noc_rx : in std_logic_vector(REG_SIZE downto 0);--- --From Noc local_vc_write_rx_noc: in std_logic; ---_vector(192-1 downto 0); --From NoC local_incr_rx_vec_noc: in std_logic; --From NoC rx_packet_length_noc : out std_logic_vector(LENGTH downto 0); --To DMA local_noc_tx : out std_logic_vector(REG_SIZE downto 0);--- --To NoC local_vc_write_tx_noc: out std_logic; ---_vector(192-1 downto 0); --To NoC local_incr_tx_vec_noc: out std_logic; --To NoC receive_valid_to_dma : out std_logic; --To DMA sent_ack_to_dma : out std_logic_vector(LENGTH downto 0);--------- --To DMA data_bus_noc_out : out std_logic_vector(DATA_SIZE downto 0) --To RAM ); end entity; ----------------------NoC Interface Behaviour------------------------ architecture noc_interface_arch of noc_interface is Signal packet_id : std_logic_vector(PACKET downto 0); signal count : std_logic_vector(LENGTH downto 0); signal sent_packet : std_logic_vector(LENGTH downto 0); signal packet_len : std_logic_vector(LENGTH downto 0); --signal packet_length : std_logic_vector(4 downto 0); begin rxprocess : process(clk, rst) begin if rst = '0' then rx_packet_length_noc <= (others => '0'); local_noc_tx <= (others => '0'); local_vc_write_tx_noc <= '0'; --local_incr_tx_vec_noc <= '0'; receive_valid_to_dma <= '0'; sent_ack_to_dma <= (others => '0'); data_bus_noc_out <= (others => '0'); count <= (others => '0'); sent_packet <= (others => '0'); packet_id <= (others => '0'); packet_len <= (others => '0'); elsif rising_edge(clk) then --------------------Reading from NoC-------------------------------- if (local_vc_write_rx_noc = '1') then if (local_noc_rx(31 downto 29) = "100") then rx_packet_length_noc <= local_noc_rx(LENGTH downto 0 ); --packet length packet_len <= local_noc_rx(LENGTH downto 0 ); --packet length count <= (others => '0'); --counter reset packet_id <= local_noc_rx(28 downto 17); --current packetid receive_valid_to_dma <= '1'; elsif(unsigned(count) <= unsigned(packet_len) and unsigned(packet_len) > 0) then report "receive_valid_to_dma is 1 from Line 80"; receive_valid_to_dma <= '1'; --valid to DMA count <= std_logic_vector(unsigned(count) + 1); --counter update data_bus_noc_out <= local_noc_rx(DATA_SIZE downto 0 ); --NoC is given to RAM else report "receive_valid_to_dma is 0 from Line 86"; packet_len <= (others=>'0'); receive_valid_to_dma <= '0'; data_bus_noc_out <= (others=>'0'); count <= (others=>'0'); end if; --------------------Writing to NoC---------------------------------- elsif ((sent_valid_from_dma = '1') and (to_integer(unsigned(tx_packet_length_noc)) >= 0)) then -- the valid from dma is one cycle behind if(sent_packet = "00000") then --sent_ack_to_dma <= std_logic_vector(unsigned(sent_packet) + 1); --to DMA updated value sent_packet <= std_logic_vector(unsigned(sent_packet) + 1); --updating packet id local_noc_tx <= "100" & packet_id & SOURCE_ID & DEST_ID & tx_packet_length_noc; local_vc_write_tx_noc <= '1'; else sent_ack_to_dma <= sent_packet;--std_logic_vector(unsigned(sent_packet) + 1); --to DMA updated value sent_packet <= std_logic_vector(unsigned(sent_packet) + 1); local_noc_tx <= std_logic_vector(to_unsigned(0, 24)) & data_bus_noc_in; --24bit zeros in msb and 8 bit data local_vc_write_tx_noc <= '1'; end if; else rx_packet_length_noc <= (others => '0'); local_noc_tx <= (others => '0'); local_vc_write_tx_noc <= '0'; ---local_incr_tx_vec_noc <= '0'; receive_valid_to_dma <= '0'; sent_ack_to_dma <= (others => '0'); data_bus_noc_out <= (others => '0'); count <= (others => '0'); sent_packet <= (others => '0'); end if; end if; end process; end architecture;