DMA_for_RoCC/NoC_INTERFACE.vhd

129 lines
6.9 KiB
VHDL
Raw Permalink Normal View History

-- 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---------------------------
2024-12-16 23:26:48 +01:00
entity noc_interface is
generic (
2024-12-16 23:26:48 +01:00
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
2024-12-09 21:09:33 +01:00
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;
2024-12-16 23:26:48 +01:00
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
2024-12-09 21:09:33 +01:00
local_noc_rx : in std_logic_vector(REG_SIZE downto 0);--- --From Noc
2024-12-16 23:26:48 +01:00
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
2024-12-09 21:09:33 +01:00
local_noc_tx : out std_logic_vector(REG_SIZE downto 0);--- --To NoC
2024-12-16 23:26:48 +01:00
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------------------------
2024-12-16 23:26:48 +01:00
architecture noc_interface_arch of noc_interface is
2024-12-09 21:09:33 +01:00
Signal packet_id : std_logic_vector(PACKET downto 0);
signal count : std_logic_vector(LENGTH downto 0);
2024-12-16 23:26:48 +01:00
signal sent_packet : std_logic_vector(LENGTH downto 0);
2024-12-09 21:09:33 +01:00
signal packet_len : std_logic_vector(LENGTH downto 0);
begin
rxprocess : process(clk, rst)
begin
if rst = '0' then
rx_packet_length_noc <= (others => '0');
local_noc_tx <= (others => '0');
2024-12-16 23:26:48 +01:00
local_vc_write_tx_noc <= '0';
2024-12-23 14:03:57 +01:00
local_incr_tx_vec_noc <= '0';-----
2024-12-16 23:26:48 +01:00
receive_valid_to_dma <= '0';
sent_ack_to_dma <= (others => '0');
data_bus_noc_out <= (others => '0');
count <= (others => '0');
2024-12-16 23:26:48 +01:00
sent_packet <= (others => '0');
packet_id <= (others => '0');
2024-12-09 21:09:33 +01:00
packet_len <= (others => '0');
elsif rising_edge(clk) then
--------------------Reading from NoC--------------------------------
2024-12-16 23:26:48 +01:00
if (local_vc_write_rx_noc = '1') then
2024-12-09 21:09:33 +01:00
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
2024-12-16 23:26:48 +01:00
receive_valid_to_dma <= '1';
2024-12-23 14:03:57 +01:00
local_incr_tx_vec_noc <= '1';-------
2024-12-09 21:09:33 +01:00
elsif(unsigned(count) <= unsigned(packet_len) and unsigned(packet_len) > 0) then
2024-12-16 23:26:48 +01:00
report "receive_valid_to_dma is 1 from Line 80";
2024-12-09 21:09:33 +01:00
2024-12-16 23:26:48 +01:00
receive_valid_to_dma <= '1'; --valid to DMA
2024-12-09 21:09:33 +01:00
count <= std_logic_vector(unsigned(count) + 1); --counter update
2024-12-16 23:26:48 +01:00
data_bus_noc_out <= local_noc_rx(DATA_SIZE downto 0 ); --NoC is given to RAM
2024-12-23 14:03:57 +01:00
local_incr_tx_vec_noc <= '1';-------
else
2024-12-16 23:26:48 +01:00
report "receive_valid_to_dma is 0 from Line 86";
2024-12-09 21:09:33 +01:00
packet_len <= (others=>'0');
2024-12-16 23:26:48 +01:00
receive_valid_to_dma <= '0';
data_bus_noc_out <= (others=>'0');
count <= (others=>'0');
2024-12-23 14:03:57 +01:00
local_incr_tx_vec_noc <= '0';-------
end if;
--------------------Writing to NoC----------------------------------
2024-12-16 23:26:48 +01:00
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_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;
2024-12-16 23:26:48 +01:00
local_vc_write_tx_noc <= '1';
else
2024-12-16 23:26:48 +01:00
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');
2024-12-16 23:26:48 +01:00
local_vc_write_tx_noc <= '0';
2024-12-23 14:03:57 +01:00
local_incr_tx_vec_noc <= '0';---
2024-12-16 23:26:48 +01:00
receive_valid_to_dma <= '0';
sent_ack_to_dma <= (others => '0');
data_bus_noc_out <= (others => '0');
count <= (others => '0');
2024-12-16 23:26:48 +01:00
sent_packet <= (others => '0');
end if;
end if;
end process;
end architecture;